1. 程式人生 > >簡單的service編寫 nginx php-fpm

簡單的service編寫 nginx php-fpm

nginx

幾個方法

start 直接啟動 檢視返回值是否是0 如果0則success 非0 則failure

stop 直接呼叫killproc

reload 呼叫nginx -s reload

restart stop,start

test 呼叫nginx -t

status 直接呼叫status

幾個方法killproc, status, success, failure 來自/etc/init.d/functions 詳細方法:/etc/init.d/functions說明

#!/bin/bash #/etc/init.d/nginx # Source function library. if [ -f /etc/init.d/functions ] ; then . /etc/init.d/functions elif [ -f /etc/rc.d/init.d/functions ] ; then . /etc/rc.d/init.d/functions else exit 1 fi #config service='/opt/Soft/nginx/sbin/nginx' service_name='nginx' #functions start() { echo 'start service' echo "${service}" ${service} if [ "$?" -eq 0 ] ; then success else failure fi } stop() { echo 'stop service' echo "killproc ${service_name}" killproc ${service_name} } reload() { echo 'reload service' echo "${service} -s reload" ${service} -s reload if [ "$?" -eq 0 ] ; then success else failure fi } test() { echo 'test service' echo "${service} -t" ${service} -t } case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) stop start ;; test) test ;; status) status ${service_name} ;; *) echo "usage: $0 start|stop|reload|restart|test|status" exit 0; esac

php-fpm

start , stop ,restart|reload, status

#!/bin/bash # Source function library. if [ -f /etc/init.d/functions ] ; then . /etc/init.d/functions elif [ -f /etc/rc.d/init.d/functions ] ; then . /etc/rc.d/init.d/functions else exit 1 fi #config service='/opt/Soft/php/sbin/php-fpm' service_name='php-fpm' #functions start() { echo 'start service' echo "${service}" ${service} if [ "$?" -eq 0 ] ; then success else failure fi } stop() { echo 'stop service' echo "killproc ${service_name}" killproc ${service_name} } case "$1" in start) start ;; stop) stop ;; reload|restart) stop start ;; status) status ${service_name} ;; *) echo "usage: $0 start|stop|reload|restart|status" exit 0; esac

todo:等有時間寫個基於pid 和 conf的... 這樣就能支援多php-fpm 了,這玩意兒先湊合用著