linux環境:ubuntu
複製代碼 代碼如下:
#! /bin/sh
# Provides: server.sh
# Default-Start: 2 3 4 5
# Short-Description: server testing...
EXEC_PATH=/home/huangmin/cdev/project
EXEC=server
PID_FILE=/var/run/server.sh.pid
DAEMON=/home/huangmin/cdev/project/server
if ! [ -x $EXEC_PATH/$EXEC ]; then
echo "ERROR:$EXEC_PATH/$EXEC not found ..."
exit 1
fi
stop() {
echo "Stopping $EXEC ..."
killall $DAEMON >/dev/null
rm -f $PID_FILE
sleep 1
echo "Shutting down $EXEC: [OK]"
}
start() {
echo "Starting $EXEC ..."
$DAEMON >/dev/null
pidof $EXEC > $PID_FILE
sleep 1
echo "Starting $EXEC: [OK]"
}
restart() {
stop
start
}
case "$1" in
start)
start
stop)
stop
restart)
restart
status)
echo "Status Here"
*)
echo "Usage: service $EXEC {start|stop|restart|status}"
exit 1
esac
exit $?
/home/huangmin/cdev/project/server是我們需要的作為系統服務的程式。
寫好指令碼之後,將其放置到目錄/etc/init.d中,或者做成軟連結形式如:sudo ln -s /home/huangmin/cdev/project/bash/server.sh /etc/init.d/servertest.sh
最後利用chkconfig命令將其添加進系統服務: chkconfig –add servertest.sh
可以使用命令service servertest.sh start馬上啟動該服務程式