redis to systemd

pull/109/head
midoks 3 years ago
parent 855c89710f
commit 3cdc9fd8db
  1. 102
      plugins/redis/index.py
  2. 11
      plugins/redis/init.d/redis.service.tpl

@ -83,51 +83,66 @@ def initDreplace():
file_bin = initD_path + '/' + getPluginName() file_bin = initD_path + '/' + getPluginName()
# initd replace # initd replace
content = mw.readFile(file_tpl) if not os.path.exists(file_bin):
content = content.replace('{$SERVER_PATH}', service_path) content = mw.readFile(file_tpl)
mw.writeFile(file_bin, content) content = content.replace('{$SERVER_PATH}', service_path)
mw.execShell('chmod +x ' + file_bin) mw.writeFile(file_bin, content)
mw.execShell('chmod +x ' + file_bin)
# config replace # config replace
conf_content = mw.readFile(getConfTpl()) dst_conf = getServerDir() + '/redis.conf'
conf_content = conf_content.replace('{$SERVER_PATH}', service_path) if not os.path.exists(dst_conf):
mw.writeFile(getServerDir() + '/redis.conf', conf_content) conf_content = mw.readFile(getConfTpl())
conf_content = conf_content.replace('{$SERVER_PATH}', service_path)
mw.writeFile(dst_conf, conf_content)
# systemd
systemDir = '/lib/systemd/system'
systemService = systemDir + '/redis.service'
systemServiceTpl = getPluginDir() + '/init.d/redis.service.tpl'
if os.path.exists(systemDir) and not os.path.exists(systemService):
service_path = mw.getServerDir()
se_content = mw.readFile(systemServiceTpl)
se_content = se_content.replace('{$SERVER_PATH}', service_path)
mw.writeFile(systemService, se_content)
mw.execShell('systemctl daemon-reload')
return file_bin return file_bin
def start(): def redisOp(method):
file = initDreplace() file = initDreplace()
if not mw.isAppleSystem():
data = mw.execShell('systemctl ' + method + ' redis')
if data[1] == '':
return 'ok'
return 'fail'
data = mw.execShell(file + ' start') data = mw.execShell(file + ' start')
if data[1] == '': if data[1] == '':
return 'ok' return 'ok'
return 'fail' return 'fail'
def start():
return redisOp('start')
def stop(): def stop():
file = initDreplace() return redisOp('stop')
data = mw.execShell(file + ' stop')
if data[1] == '':
return 'ok'
return 'fail'
def restart(): def restart():
file = initDreplace() status = redisOp('restart')
data = mw.execShell(file + ' restart')
log_file = getServerDir() + "/data/redis.log" log_file = runLog()
mw.execShell("echo '' > " + log_file) mw.execShell("echo '' > " + log_file)
if data[1] == '': return status
return 'ok'
return 'fail'
def reload(): def reload():
file = initDreplace() return redisOp('reload')
data = mw.execShell(file + ' reload')
if data[1] == '':
return 'ok'
return 'fail'
def runInfo(): def runInfo():
@ -161,37 +176,30 @@ def runInfo():
def initdStatus(): def initdStatus():
if not app_debug: if mw.isAppleSystem():
if mw.isAppleSystem(): return "Apple Computer does not support"
return "Apple Computer does not support"
initd_bin = getInitDFile() shell_cmd = 'systemctl status redis | grep loaded | grep "enabled;"'
if os.path.exists(initd_bin): data = mw.execShell(shell_cmd)
return 'ok' if data[0] == '':
return 'fail' return 'fail'
return 'ok'
def initdInstall(): def initdInstall():
import shutil if mw.isAppleSystem():
if not app_debug: return "Apple Computer does not support"
if mw.isAppleSystem():
return "Apple Computer does not support" mw.execShell('systemctl enable redis')
source_bin = initDreplace()
initd_bin = getInitDFile()
shutil.copyfile(source_bin, initd_bin)
mw.execShell('chmod +x ' + initd_bin)
mw.execShell('chkconfig --add ' + getPluginName())
return 'ok' return 'ok'
def initdUinstall(): def initdUinstall():
if not app_debug:
if mw.isAppleSystem():
return "Apple Computer does not support"
mw.execShell('chkconfig --del ' + getPluginName()) if mw.isAppleSystem():
initd_bin = getInitDFile() return "Apple Computer does not support"
os.remove(initd_bin)
mw.execShell('systemctl disable redis')
return 'ok' return 'ok'

@ -0,0 +1,11 @@
[Unit]
Description=Redis In-Memory Data Store
After=network.target
[Service]
ExecStart={$SERVER_PATH}/redis/redis-server {$SERVER_PATH}/redis/redis.conf
ExecStop={$SERVER_PATH}/redis/redis-cli shutdown
Restart=always
[Install]
WantedBy=multi-user.target
Loading…
Cancel
Save