From 6f6350b1a23343f23ca5fad23d6b2a75f70cb9d6 Mon Sep 17 00:00:00 2001 From: midoks Date: Sun, 19 Jun 2022 10:20:52 +0800 Subject: [PATCH] rsyncd tp systemd --- plugins/rsyncd/index.py | 83 ++++++++++++------------ plugins/rsyncd/init.d/rsyncd.service.tpl | 9 +++ plugins/supervisor/index.py | 9 ++- 3 files changed, 55 insertions(+), 46 deletions(-) create mode 100644 plugins/rsyncd/init.d/rsyncd.service.tpl diff --git a/plugins/rsyncd/index.py b/plugins/rsyncd/index.py index 78a8f9461..27cbd7423 100755 --- a/plugins/rsyncd/index.py +++ b/plugins/rsyncd/index.py @@ -126,8 +126,18 @@ def initDreplace(): mw.writeFile(file_bin, content) mw.execShell('chmod +x ' + file_bin) - # if os.path.exists('/usr/lib/systemd/system/rsyncd.service'): - # mw.execShell('rm -rf /usr/lib/systemd/system/rsyncd*') + # systemd + systemDir = '/lib/systemd/system' + systemService = systemDir + '/rsyncd.service' + systemServiceTpl = getPluginDir() + '/init.d/rsyncd.service.tpl' + if os.path.exists(systemDir) and not os.path.exists(systemService): + rsync_bin = mw.execShell('which rsync')[0].strip() + service_path = mw.getServerDir() + se_content = mw.readFile(systemServiceTpl) + se_content = se_content.replace('{$SERVER_PATH}', service_path) + se_content = se_content.replace('{$RSYNC_BIN}', rsync_bin) + mw.writeFile(systemService, se_content) + mw.execShell('systemctl daemon-reload') rlog = getLog() if os.path.exists(rlog): @@ -135,65 +145,53 @@ def initDreplace(): return file_bin -def start(): +def rsyncOp(method) + file = initDreplace() - data = mw.execShell(file + ' start') + if not mw.isAppleSystem(): + data = mw.execShell('systemctl ' + method + ' rsyncd') + if data[1] == '': + return 'ok' + return 'fail' + + data = mw.execShell(file + ' ' + method) if data[1] == '': return 'ok' return 'fail' +def start(): + return rsyncOp('start') + + def stop(): - file = initDreplace() - data = mw.execShell(file + ' stop') - if data[1] == '': - return 'ok' - return 'fail' + return rsyncOp('stop') def restart(): - if mw.isAppleSystem(): - return "Apple Computer does not support" - stop() - start() - return 'ok' + return rsyncOp('restart') def reload(): - if mw.isAppleSystem(): - return "Apple Computer does not support" - - # data = mw.execShell('systemctl reload rsyncd.service') - # if data[1] == '': - # return 'ok' - # return 'fail' - stop() - start() - return 'ok' + return rsyncOp('reload') def initdStatus(): - if not app_debug: - if mw.isAppleSystem(): - return "Apple Computer does not support" + if mw.isAppleSystem(): + return "Apple Computer does not support" - initd_bin = getInitDFile() - if os.path.exists(initd_bin): - return 'ok' - return 'fail' + shell_cmd = 'systemctl status rsyncd | grep loaded | grep "enabled;"' + data = mw.execShell(shell_cmd) + if data[0] == '': + return 'fail' + return 'ok' def initdInstall(): - import shutil - if not app_debug: - if mw.isAppleSystem(): - return "Apple Computer does not support" + if mw.isAppleSystem(): + return "Apple Computer does not support" - p_bin = initDreplace() - initd_bin = getInitDFile() - shutil.copyfile(p_bin, initd_bin) - mw.execShell('chmod +x ' + initd_bin) - mw.execShell('chkconfig --add ' + getPluginName()) + mw.execShell('systemctl enable rsyncd') return 'ok' @@ -201,9 +199,8 @@ def initdUinstall(): if not app_debug: if mw.isAppleSystem(): return "Apple Computer does not support" - initd_bin = getInitDFile() - os.remove(initd_bin) - mw.execShell('chkconfig --del ' + getPluginName()) + + mw.execShell('systemctl diable rsyncd') return 'ok' diff --git a/plugins/rsyncd/init.d/rsyncd.service.tpl b/plugins/rsyncd/init.d/rsyncd.service.tpl new file mode 100644 index 000000000..66e68ea3f --- /dev/null +++ b/plugins/rsyncd/init.d/rsyncd.service.tpl @@ -0,0 +1,9 @@ +[Unit] +Description=fast remote file copy program daemon +ConditionPathExists={$SERVER_PATH}/rsyncd/rsyncd.conf + +[Service] +ExecStart={$RSYNC_BIN} --daemon --no-detach + +[Install] +WantedBy=multi-user.target diff --git a/plugins/supervisor/index.py b/plugins/supervisor/index.py index 5185dfe4b..cad9ca9dc 100755 --- a/plugins/supervisor/index.py +++ b/plugins/supervisor/index.py @@ -113,6 +113,10 @@ def initDreplace(): return True +def supOp(method): + pass + + def start(): initDreplace() @@ -181,9 +185,8 @@ def reload(): def initdStatus(): - if not app_debug: - if mw.isAppleSystem(): - return "Apple Computer does not support" + if mw.isAppleSystem(): + return "Apple Computer does not support" shell_cmd = 'systemctl status supervisor | grep loaded | grep "enabled;"' data = mw.execShell(shell_cmd)