linux服務腳本因linux的發行版不同,因而具有不同的書寫規則,redhat系列的在7系列之後,將服務進行了簡化,而ubuntu則還是原來的服務書寫方式,下面來介紹ubuntu的服務書寫。
centos7.5的書寫參考下面文章,書寫的很詳細:
參考:https://blog.csdn.net/fu_wayne/article/details/38018825
https://blog.csdn.net/hellocooper/article/details/53771125
ubuntu的服務腳本書寫 :
服務腳本的書寫是有固定格式的,以case來判定輸入,對應執行相應的函數
case "$1" in
start)
start
exit 0
;;
stop)
sstop
exit 0
;;
force-stop)
sstop
start
exit 0
;;
restart|force-reload)
sstop
start
exit 0
;;
status)
status
;;
# MongoDB can't reload its configuration.
reload)
sstop
start
exit 0
;;
*)
echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2
exit 1
;;
esac
exit 0