swap
This commit is contained in:
parent
addd8d3e70
commit
ca74fed904
|
|
@ -17,8 +17,8 @@ pluginService('swap');
|
|||
|
||||
function readme(){
|
||||
var readme = '<ul class="help-info-text c7">';
|
||||
readme += '<li>dd if=/dev/zero of=/swapfile bs=1M count=2048</li>';
|
||||
readme += '<li>mkswap /swapfile</li>';
|
||||
readme += '<li>dd if=/dev/zero of=/www/server/swap/swapfile bs=1M count=2048</li>';
|
||||
readme += '<li>mkswap /www/server/swap/swapfile</li>';
|
||||
readme += '</ul>';
|
||||
$('.soft-man-con').html(readme);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
Loading…
Reference in New Issue