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
根据正在运行的服务进行添加
#!/bin/bash #author zhouwei <http://blog.csdn.net/sunvince> #replace service path and move to /etc/init.d #need template nginxservice,php-fpmservice,apacheservice nginx=$(lsof | grep txt | grep nginx | awk '{print $NF}' | sort | uniq | grep nginx); echo $nginx if [ ! -z $nginx ] ; then #addslashes / => \/ nginx=$(echo ${nginx} | sed "s/\//\\\\\//g"); sed "s/NGINXSERVICE/${nginx}/" nginxservice > nginx chmod +x nginx mv nginx /etc/init.d/ fi phpfpm=$(lsof |grep txt | grep php-fpm | awk '{print $NF}' | sort |uniq | grep php-fpm); echo $phpfpm if [ ! -z $phpfpm ] ; then #addslashes / => \/ phpfpm=$(echo ${phpfpm} | sed "s/\//\\\\\//g"); sed "s/PHPFPMSERVICE/${phpfpm}/" php-fpmservice > php-fpm chmod +x php-fpm mv php-fpm /etc/init.d/ fi apache=$(lsof |grep txt | grep httpd | awk '{print $NF}' | sort |uniq | grep httpd); if [ ! -z $apache ] ; then apache=$(echo $apache | awk -F"/bin/httpd" '{print $1}')/bin/apachectl fi echo $apache if [ ! -z $apache ] ; then #addslashes / => \/ apache=$(echo ${apache} | sed "s/\//\\\\\//g"); sed "s/APACHESERVICE/${apache}/" apacheservice > apache chmod +x apache mv apache /etc/init.d/ fi
todo:等有时间写个基于pid 和 conf的... 这样就能支持多php-fpm 了,这玩意儿先凑合用着