如何在centos 6上創建服務殺死服務并運行腳本
例如 :
如果我運行這個命令 service test start
它應該使以下
pkill test
nohup ./opt/test/test/bin/standalone.sh -c standalone-full.xml
另外,如果我運行此命令 service test stop
它應該使以下
pkill test
uj5u.com熱心網友回復:
創建一個類似 /etc/init.d/test 的檔案
#!/bin/bash
start() {
/usr/bin/kill -9 $(cat /tmp/test_nohup_pid.txt)
nohup ./opt/test/test/bin/standalone.sh -c standalone-full.xml 2>&1 &
echo $! > /tmp/test_nohup_pid.txt
}
stop() {
/usr/bin/kill -9 $(cat /tmp/test_nohup_pid.txt)
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/436285.html
