pull/109/head
midoks 3 years ago
parent addd8d3e70
commit ca74fed904
  1. 4
      plugins/swap/index.html
  2. 28
      plugins/swap/index.py
  3. 2
      plugins/swap/info.json
  4. 12
      plugins/swap/init.d/swap.service.tpl
  5. 14
      plugins/swap/install.sh
  6. 9
      plugins/varnish/index.py

@ -17,8 +17,8 @@ pluginService('swap');
function readme(){ function readme(){
var readme = '<ul class="help-info-text c7">'; var readme = '<ul class="help-info-text c7">';
readme += '<li>dd if=/dev/zero of=/swapfile bs=1M count=2048</li>'; readme += '<li>dd if=/dev/zero of=/www/server/swap/swapfile bs=1M count=2048</li>';
readme += '<li>mkswap /swapfile</li>'; readme += '<li>mkswap /www/server/swap/swapfile</li>';
readme += '</ul>'; readme += '</ul>';
$('.soft-man-con').html(readme); $('.soft-man-con').html(readme);
} }

@ -31,11 +31,6 @@ def getInitDFile():
return '/etc/init.d/' + getPluginName() return '/etc/init.d/' + getPluginName()
def getConf():
path = getPluginDir() + "/config/redis.conf"
return path
def getInitDTpl(): def getInitDTpl():
path = getPluginDir() + "/init.d/" + getPluginName() + ".tpl" path = getPluginDir() + "/init.d/" + getPluginName() + ".tpl"
return path return path
@ -81,10 +76,25 @@ 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}', '/swapfile') content = mw.readFile(file_tpl)
mw.writeFile(file_bin, content) content = content.replace(
mw.execShell('chmod +x ' + file_bin) '{$SERVER_PATH}', getServerDir() + '/swap/swapfile')
mw.writeFile(file_bin, content)
mw.execShell('chmod +x ' + file_bin)
# systemd
systemDir = '/lib/systemd/system'
systemService = systemDir + '/swap.service'
systemServiceTpl = getPluginDir() + '/init.d/swap.service.tpl'
if os.path.exists(systemDir) and not os.path.exists(systemService):
swapon_bin = mw.execShell('which swapon')[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('{$SWAPON_BIN}', swapon_bin)
mw.writeFile(systemService, se_content)
mw.execShell('systemctl daemon-reload')
return file_bin return file_bin

@ -4,7 +4,7 @@
"name": "swap", "name": "swap",
"title": "swap", "title": "swap",
"shell": "install.sh", "shell": "install.sh",
"versions":"1.0", "versions":"1.1",
"tip": "soft", "tip": "soft",
"checks": "server/swap", "checks": "server/swap",
"path": "server/swap", "path": "server/swap",

@ -0,0 +1,12 @@
[Unit]
Description=Swap Process Manager
After=network.target
[Service]
Type=forking
ExecStart={$SWAPON_BIN} {$SERVER_PATH}/swap/swapfile
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target

@ -22,10 +22,10 @@ Install_swap()
if [ "$sysName" == "Darwin" ];then if [ "$sysName" == "Darwin" ];then
pass pass
else else
dd if=/dev/zero of=/swapfile bs=1M count=2048 dd if=/dev/zero of=$serverPath/swap/swapfile bs=1M count=2048
chmod 600 /swapfile chmod 600 $serverPath/swap/swapfile
mkswap /swapfile mkswap $serverPath/swap/swapfile
swapon /swapfile swapon $serverPath/swap/swapfile
fi fi
echo '安装完成' > $install_tmp echo '安装完成' > $install_tmp
@ -33,7 +33,13 @@ Install_swap()
Uninstall_swap() Uninstall_swap()
{ {
swapoff $serverPath/swap/swapfile
rm -rf $serverPath/swap rm -rf $serverPath/swap
if [ -f /lib/systemd/system/swap.service ];then
rm -rf /lib/systemd/system/swap.service
fi
echo "Uninstall_swap" > $install_tmp echo "Uninstall_swap" > $install_tmp
} }

@ -36,11 +36,6 @@ def getConf():
return path return path
def getConfTpl():
path = getPluginDir() + "/config/redis.conf"
return path
def getInitDTpl(): def getInitDTpl():
path = getPluginDir() + "/init.d/" + getPluginName() + ".tpl" path = getPluginDir() + "/init.d/" + getPluginName() + ".tpl"
return path return path
@ -102,8 +97,6 @@ def stop():
def restart(): def restart():
data = mw.execShell('systemctl restart ' + getPluginName()) data = mw.execShell('systemctl restart ' + getPluginName())
log_file = getServerDir() + "/data/redis.log"
mw.execShell("echo '' > " + log_file)
if data[1] == '': if data[1] == '':
return 'ok' return 'ok'
return 'fail' return 'fail'
@ -111,7 +104,7 @@ def restart():
def reload(): def reload():
# file = initDreplace() # file = initDreplace()
data = mw.execShell('systemctl restart ' + getPluginName()) data = mw.execShell('systemctl reload ' + getPluginName())
if data[1] == '': if data[1] == '':
return 'ok' return 'ok'
return 'fail' return 'fail'

Loading…
Cancel
Save