Linux/etc/init. d/service script example, etcinit. d
1. Write the script and put it in the/etc/init. d/directory, and set the executable permission chmod + x scriptnamed.
2. The script contains several methods: start, stop, restart, and status,
The/opt/myservice. sh script can add the operations you want to perform.
Example:
#! /Bin/bash
# Chkconfig: 1234 90 60
# Default-Start: 2 3 4 5
# Default-Stop: S 0 1 6
# Description: Saves and restores system entropy pool \
# Higher quality random number generation
Servername = myservice
Serverdir =/opt/myservice
Binpath =/opt/myservice. sh
Prog = $ (basename $ binpath)
./Etc/init. d/functions
Restart (){
Stop
Start
}
Reload (){
Stop
Start
}
Start (){
Echo-n $ "Starting $ daemon :"
Daemon $ binpath start
Retval = $
Echo
[$ Retval-eq 0]
}
Stop (){
Echo-n $ "Stopping $ daemon :"
Daemon $ binpath stop
Retval = $
Echo
[$ Retval-eq 0]
}
Ha_status (){
# Status $ prog
Status $ prog
Ps-ef | grep $ prog & exit 0
}
Case "$1" in
Start)
$1
;;
Stop)
$1
;;
Reload)
$1
;;
Restart)
$1
;;
Status)
Ha_status
;;
*)
Echo "Usage: $0 {start | stop | reload | restart | status }"
Exit 1
Esac
3. Set chkconfig -- level 2345 scriptname on for startup.