diff --git a/plugins/rsyncd/index.py b/plugins/rsyncd/index.py index a54dffb2e..58f2d8d5a 100755 --- a/plugins/rsyncd/index.py +++ b/plugins/rsyncd/index.py @@ -19,6 +19,11 @@ def getPluginName(): return 'rsyncd' +def getInitDTpl(): + path = getPluginDir() + "/init.d/" + getPluginName() + ".tpl" + return path + + def getPluginDir(): return public.getPluginDir() + '/' + getPluginName() @@ -57,6 +62,12 @@ def checkArgs(data, ck=[]): return (True, public.returnJson(True, 'ok')) +def contentReplace(content): + service_path = public.getServerDir() + content = content.replace('{$SERVER_PATH}', service_path) + return content + + def status(): data = public.execShell( "ps -ef|grep rsync |grep -v grep | grep -v python | awk '{print $2}'") @@ -102,43 +113,41 @@ def initConf(): public.writeFile(confpwd_path, '') public.execShell('chmod 0600 ' + confpwd_path) + initD_path = getServerDir() + '/init.d' + if not os.path.exists(initD_path): + os.mkdir(initD_path) + file_bin = initD_path + '/' + getPluginName() -def start(): - initConf() + file_tpl = getInitDTpl() + # initd replace + if not os.path.exists(file_bin): + content = public.readFile(file_tpl) + content = contentReplace(content) + public.writeFile(file_bin, content) + public.execShell('chmod +x ' + file_bin) - if public.isAppleSystem(): - return "Apple Computer does not support" + return file_bin - # data = public.execShell('systemctl start rsyncd.service') - # if data[1] == '': - # return 'ok' - # return 'fail' - public.execShell('/usr/bin/rsync --daemon') - return 'ok' +def start(): + file = initConf() + data = public.execShell(file + ' start') + if data[1] == '': + return 'ok' + return 'fail' def stop(): - if public.isAppleSystem(): - return "Apple Computer does not support" - - # data = public.execShell('systemctl stop rsyncd.service') - # if data[1] == '': - # return 'ok' - # return 'fail' - - cmd = "ps -ef | grep rsync |grep -v grep | grep -v python |awk '{print $2}' | xargs kill" - public.execShell(cmd) - return 'ok' + file = initConf() + data = public.execShell(file + ' stop') + if data[1] == '': + return 'ok' + return 'fail' def restart(): if public.isAppleSystem(): return "Apple Computer does not support" - # data = public.execShell('systemctl restart rsyncd.service') - # if data[1] == '': - # return 'ok' - # return 'fail' stop() start() return 'ok' @@ -158,31 +167,38 @@ def reload(): def initdStatus(): - if public.isAppleSystem(): - return "Apple Computer does not support" + if not app_debug: + if public.isAppleSystem(): + return "Apple Computer does not support" - data = public.execShell('systemctl status rsyncd.service | grep enabled') - if data[0] == '': - return 'fail' - return 'ok' + initd_bin = getInitDFile() + if os.path.exists(initd_bin): + return 'ok' + return 'fail' def initdInstall(): - if public.isAppleSystem(): - return "Apple Computer does not support" - data = public.execShell('systemctl enable rsyncd.service') - if data[0] != '': - return 'fail' + import shutil + if not app_debug: + if public.isAppleSystem(): + return "Apple Computer does not support" + + mysql_bin = initDreplace() + initd_bin = getInitDFile() + shutil.copyfile(mysql_bin, initd_bin) + public.execShell('chmod +x ' + initd_bin) + public.execShell('chkconfig --add ' + getPluginName()) return 'ok' def initdUinstall(): - if public.isAppleSystem(): - return "Apple Computer does not support" - data = public.execShell('systemctl disable rsyncd.service') - if data[0] == '': - return 'ok' - return 'fail' + if not app_debug: + if public.isAppleSystem(): + return "Apple Computer does not support" + initd_bin = getInitDFile() + os.remove(initd_bin) + public.execShell('chkconfig --del ' + getPluginName()) + return 'ok' def getRecListData(): diff --git a/plugins/rsyncd/init.d/rsyncd.tpl b/plugins/rsyncd/init.d/rsyncd.tpl new file mode 100755 index 000000000..a3cb1d087 --- /dev/null +++ b/plugins/rsyncd/init.d/rsyncd.tpl @@ -0,0 +1,47 @@ +#!/bin/sh +# chkconfig: 2345 55 25 +# description: rsyncd Service + +### BEGIN INIT INFO +# Provides: rsyncd +# Required-Start: $all +# Required-Stop: $all +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: starts rsyncd +# Description: starts the MDW-Web +### END INIT INFO + +ROOT_PATH={$SERVER_PATH} + +p_start(){ + echo "Starting ..." + cd $ROOT_PATH/rsyncd/init.d + /usr/bin/rsync --daemon + echo "rsyncd started" +} + +p_stop(){ + echo "Stopping ..." + ps -ef | grep rsync | grep -v grep | grep -v python | awk '{print $2}' | xargs kill -9 + echo "rsyncd stopped" +} + + +case "$1" in + start) + p_start + ;; + stop) + p_stop + ;; + restart|reload) + p_stop + sleep 0.3 + p_start + ;; + *) + echo "Please use start or stop as first argument" + ;; +esac +