Sign up for a system service to boot from.
1 Script Authoring
#vim test.sh
Copy Code code as follows:
#!/bin/bash
#description: hello.sh
#chkconfig: 2345 20 81
exec_path=/usr/local/
exec=hello.sh
daemon=/usr/local/hello.sh
Pid_file=/var/run/hello.sh.pid
. /etc/rc.d/init.d/functions
if [!-X $EXEC _path/$EXEC]; Then
echo "ERROR: $DAEMON not Found"
Exit 1
Fi
Stop ()
{
echo "stoping $EXEC ..."
PS aux | grep "$DAEMON" | Kill-9 ' awk ' {print $} ' >/dev/null 2>&1
Rm-f $PID _file
Usleep 100
echo "Shutting down $EXEC: [OK]"
}
Start ()
{
echo "Starting $EXEC ..."
$DAEMON >/dev/null &
Pidof $EXEC > $PID _file
Usleep 100
echo "Starting $EXEC: [OK]"
}
Restart ()
{
Stop
Start
}
Case "$" in
Start
Start
;;
Stop
Stop
;;
Restart)
Restart
;;
Status
Status-p $PID _file $DAEMON
;;
*)
echo "Usage:service $EXEC {start|stop|restart|status}"
Exit 1
Esac
Exit $?
2 Registration Service
Copy Code code as follows:
# chmod test.sh
# CP Test.sh/etc/init.d/
# chkconfig--add test.sh
# chkconfig--list
3. Delete Service
Copy Code code as follows: