Linux Environment: Ubuntu
Copy Code code as follows:
#! /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 "$" 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 is the program that we need as a system service.
After writing a script, place it in the directory/etc/init.d, or make a soft link form such as: sudo ln-s/home/huangmin/cdev/project/bash/server.sh/etc/init.d/ Servertest.sh
Finally adds it to the system service using the Chkconfig command: Chkconfig–add servertest.sh
can use the command service servertest.sh Start starts the service
immediately.