diff --git a/plugins/swap/index.html b/plugins/swap/index.html
index 138ba694a..89601d38f 100755
--- a/plugins/swap/index.html
+++ b/plugins/swap/index.html
@@ -17,8 +17,8 @@ pluginService('swap');
function readme(){
var readme = '
';
- readme += '- dd if=/dev/zero of=/swapfile bs=1M count=2048
';
- readme += '- mkswap /swapfile
';
+ readme += '- dd if=/dev/zero of=/www/server/swap/swapfile bs=1M count=2048
';
+ readme += '- mkswap /www/server/swap/swapfile
';
readme += '
';
$('.soft-man-con').html(readme);
}
diff --git a/plugins/swap/index.py b/plugins/swap/index.py
index a0cfc5ebf..6d26846f8 100755
--- a/plugins/swap/index.py
+++ b/plugins/swap/index.py
@@ -31,11 +31,6 @@ def getInitDFile():
return '/etc/init.d/' + getPluginName()
-def getConf():
- path = getPluginDir() + "/config/redis.conf"
- return path
-
-
def getInitDTpl():
path = getPluginDir() + "/init.d/" + getPluginName() + ".tpl"
return path
@@ -81,10 +76,25 @@ def initDreplace():
file_bin = initD_path + '/' + getPluginName()
# initd replace
- content = mw.readFile(file_tpl)
- content = content.replace('{$SERVER_PATH}', '/swapfile')
- mw.writeFile(file_bin, content)
- mw.execShell('chmod +x ' + file_bin)
+ if not os.path.exists(file_bin):
+ content = mw.readFile(file_tpl)
+ content = content.replace(
+ '{$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
diff --git a/plugins/swap/info.json b/plugins/swap/info.json
index 8511f7d01..b6e9b719a 100755
--- a/plugins/swap/info.json
+++ b/plugins/swap/info.json
@@ -4,7 +4,7 @@
"name": "swap",
"title": "swap",
"shell": "install.sh",
- "versions":"1.0",
+ "versions":"1.1",
"tip": "soft",
"checks": "server/swap",
"path": "server/swap",
diff --git a/plugins/swap/init.d/swap.service.tpl b/plugins/swap/init.d/swap.service.tpl
new file mode 100644
index 000000000..7fc37103c
--- /dev/null
+++ b/plugins/swap/init.d/swap.service.tpl
@@ -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
diff --git a/plugins/swap/install.sh b/plugins/swap/install.sh
index b3a6b1e24..0c2215818 100755
--- a/plugins/swap/install.sh
+++ b/plugins/swap/install.sh
@@ -22,10 +22,10 @@ Install_swap()
if [ "$sysName" == "Darwin" ];then
pass
else
- dd if=/dev/zero of=/swapfile bs=1M count=2048
- chmod 600 /swapfile
- mkswap /swapfile
- swapon /swapfile
+ dd if=/dev/zero of=$serverPath/swap/swapfile bs=1M count=2048
+ chmod 600 $serverPath/swap/swapfile
+ mkswap $serverPath/swap/swapfile
+ swapon $serverPath/swap/swapfile
fi
echo '安装完成' > $install_tmp
@@ -33,7 +33,13 @@ Install_swap()
Uninstall_swap()
{
+ swapoff $serverPath/swap/swapfile
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
}
diff --git a/plugins/varnish/index.py b/plugins/varnish/index.py
index 0460f8c05..21cfa828a 100755
--- a/plugins/varnish/index.py
+++ b/plugins/varnish/index.py
@@ -36,11 +36,6 @@ def getConf():
return path
-def getConfTpl():
- path = getPluginDir() + "/config/redis.conf"
- return path
-
-
def getInitDTpl():
path = getPluginDir() + "/init.d/" + getPluginName() + ".tpl"
return path
@@ -102,8 +97,6 @@ def stop():
def restart():
data = mw.execShell('systemctl restart ' + getPluginName())
- log_file = getServerDir() + "/data/redis.log"
- mw.execShell("echo '' > " + log_file)
if data[1] == '':
return 'ok'
return 'fail'
@@ -111,7 +104,7 @@ def restart():
def reload():
# file = initDreplace()
- data = mw.execShell('systemctl restart ' + getPluginName())
+ data = mw.execShell('systemctl reload ' + getPluginName())
if data[1] == '':
return 'ok'
return 'fail'