三里屯摇滚 发表于 2011-11-16 11:20

简单的service编写 nginx php-fpm .

简单的service编写 nginx php-fpm .




几个方法

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说明


view plaincopy to clipboardprint?01.#!/bin/bash
02.#/etc/init.d/nginx
03.
04.# Source function library.
05.if [ -f /etc/init.d/functions ] ; then
06.. /etc/init.d/functions
07.elif [ -f /etc/rc.d/init.d/functions ] ; then
08.. /etc/rc.d/init.d/functions
09.else
10.exit 1
11.fi
12.
13.#config
14.service='/opt/Soft/nginx/sbin/nginx'
15.service_name='nginx'
16.
17.#functions
18.start()
19.{
20.      echo 'start service'
21.      echo "${service}"
22.      ${service}
23.      if [ "$?" -eq 0 ] ; then
24.                success
25.      else
26.                failure
27.      fi
28.}
29.stop()
30.{
31.      echo 'stop service'
32.      echo "killproc ${service_name}"
33.      killproc ${service_name}
34.}
35.reload()
36.{
37.      echo 'reload service'
38.      echo "${service} -s reload"
39.      ${service} -s reload
40.      if [ "$?" -eq 0 ] ; then
41.                success
42.      else
43.                failure
44.      fi
45.}
46.test()
47.{
48.      echo 'test service'
49.      echo "${service} -t"
50.      ${service} -t
51.}
52.
53.
54.case "$1" in
55.start)
56.    start
57.    ;;
58.stop)
59.    stop
60.    ;;
61.reload)
62.    reload
63.    ;;
64.restart)
65.    stop
66.    start
67.    ;;
68.test)
69.    test
70.    ;;
71.status)
72.    status ${service_name}
73.    ;;
74.*)
75.    echo "usage: $0 start|stop|reload|restart|test|status"
76.    exit 0;
77.esac
#!/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


view plaincopy to clipboardprint?01.#!/bin/bash
02.
03.# Source function library.
04.if [ -f /etc/init.d/functions ] ; then
05.. /etc/init.d/functions
06.elif [ -f /etc/rc.d/init.d/functions ] ; then
07.. /etc/rc.d/init.d/functions
08.else
09.exit 1
10.fi
11.
12.#config
13.service='/opt/Soft/php/sbin/php-fpm'
14.service_name='php-fpm'
15.
16.#functions
17.start()
18.{
19.      echo 'start service'
20.      echo "${service}"
21.      ${service}
22.      if [ "$?" -eq 0 ] ; then
23.                success
24.      else
25.                failure
26.      fi
27.}
28.stop()
29.{
30.      echo 'stop service'
31.      echo "killproc ${service_name}"
32.      killproc ${service_name}
33.}
34.
35.
36.case "$1" in
37.start)
38.    start
39.    ;;
40.stop)
41.    stop
42.    ;;
43.reload|restart)
44.    stop
45.    start
46.    ;;
47.status)
48.    status ${service_name}
49.    ;;
50.*)
51.    echo "usage: $0 start|stop|reload|restart|status"
52.    exit 0;
53.esac
#!/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;
esactodo:等有时间写个基于pid 和 conf的... 这样就能支持多php-fpm 了,这玩意儿先凑合用着
页: [1]
查看完整版本: 简单的service编写 nginx php-fpm .