mdserver-web/web/admin/setup/init_cmd.py

79 lines
2.6 KiB
Python
Raw Permalink Normal View History

2024-11-03 05:14:25 -05:00
# coding:utf-8
# ---------------------------------------------------------------------------------
# MW-Linux面板
# ---------------------------------------------------------------------------------
# copyright (c) 2018-∞(https://github.com/midoks/mdserver-web) All rights reserved.
# ---------------------------------------------------------------------------------
# Author: midoks <midoks@163.com>
# ---------------------------------------------------------------------------------
import os
import shutil
import core.mw as mw
2024-12-02 04:54:09 -05:00
def cmdContent():
script = mw.getPanelDir() + '/scripts/init.d/mw.tpl'
2024-12-02 04:57:19 -05:00
content = mw.readFile(script)
2024-11-03 06:39:49 -05:00
content = content.replace("{$SERVER_PATH}", mw.getPanelDir())
2024-11-03 05:14:25 -05:00
content += "\n# make:{0}".format(mw.formatDate())
2024-12-02 04:54:09 -05:00
return content
2024-11-03 05:14:25 -05:00
def init_cmd():
2024-12-02 04:54:09 -05:00
cmd_content = cmdContent()
2024-11-03 05:14:25 -05:00
script_bin = mw.getPanelDir() + '/scripts/init.d/mw'
2024-12-02 04:54:09 -05:00
mw.writeFile(script_bin, cmd_content)
2024-11-03 05:14:25 -05:00
mw.execShell('chmod +x ' + script_bin)
# 在linux系统中,确保/etc/init.d存在
if not mw.isAppleSystem() and not os.path.exists("/etc/rc.d/init.d"):
mw.execShell('mkdir -p /etc/rc.d/init.d')
if not mw.isAppleSystem() and not os.path.exists("/etc/init.d"):
mw.execShell('mkdir -p /etc/init.d')
# initd
if os.path.exists('/etc/rc.d/init.d'):
initd_bin = '/etc/rc.d/init.d/mw'
2024-12-04 17:11:03 -05:00
if not os.path.exists(initd_bin):
mw.writeFile(initd_bin, cmd_content)
mw.execShell('chmod +x ' + initd_bin)
2024-11-03 05:14:25 -05:00
# 加入自启动
mw.execShell('which chkconfig && chkconfig --add mw')
2024-12-02 04:12:29 -05:00
2024-11-03 05:14:25 -05:00
if os.path.exists('/etc/init.d'):
initd_bin = '/etc/init.d/mw'
2024-12-04 17:11:03 -05:00
if not os.path.exists(initd_bin):
mw.writeFile(initd_bin, cmd_content)
mw.execShell('chmod +x ' + initd_bin)
2024-11-03 05:14:25 -05:00
# 加入自启动
mw.execShell('which update-rc.d && update-rc.d -f mw defaults')
2024-12-01 14:45:16 -05:00
2024-12-04 17:11:49 -05:00
# sys_name = mw.getOsName()
2024-12-02 04:12:29 -05:00
# if sys_name == 'opensuse':
2024-12-02 03:33:47 -05:00
# init_cmd_systemd()
2024-12-01 14:45:16 -05:00
return True
def init_cmd_systemd():
2024-12-02 03:24:29 -05:00
systemd_dir = mw.systemdCfgDir()
2024-12-01 14:45:16 -05:00
2024-12-02 03:24:29 -05:00
systemd_mw = systemd_dir + '/mw.service'
systemd_mw_task = systemd_dir + '/mw-task.service'
2024-12-01 14:45:16 -05:00
systemd_mw_tpl = mw.getPanelDir() + '/scripts/init.d/mw.service.tpl'
systemd_mw_task_tpl = mw.getPanelDir() + '/scripts/init.d/mw-task.service.tpl'
if os.path.exists(systemd_mw):
os.remove(systemd_mw)
if os.path.exists(systemd_mw_task):
os.remove(systemd_mw_task)
2024-12-02 03:25:55 -05:00
contentReplace(systemd_mw_tpl, systemd_mw)
contentReplace(systemd_mw_task_tpl, systemd_mw_task)
2024-12-01 14:45:16 -05:00
mw.execShell('systemctl enable mw')
mw.execShell('systemctl enable mw-task')
mw.execShell('systemctl daemon-reload')