首页 > 代码库 > 转载自(http://snailz.diandian.com/post/2012-10-24/40041265730)

转载自(http://snailz.diandian.com/post/2012-10-24/40041265730)

PHP 5.4.8 添加系统服务命令

之前没注意,PHP 5.4.8 的安装包有自带的系统服务注册文件的

 

打开编译安装包,换成你自己的路径

cd /mydata/soft/php-5.4.8/

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

chmod +x /etc/init.d/php-fpm

chkconfig --add php-fpm

chkconfig --level 2345 php-fpm on

 

------------------------------------下面也是可以用的----------------------------------------

PHP5.4.8 注册系统服务操作,把之前 nginx 版本的改了下,亲自测试过应该没什么问题滴

 

要注意 - 短横杠这个符号看看复制进去后有没有乱码,我之前就遇到这个问题,郁闷了好久才发现

提示:顶部的注释不要去除否则无法注册为系统服务,

关于:chkconfig: 2345 66 38

网上搜索总结了下意思是:

2345 为启动该服务的系统环境,66 为加载的优先级别,38 为关闭的优先级别

66,38这两个位置的数值不能相同,也不能和其它服务的数值冲突,这个我也没遇到过此类问题,如果有发现问题请对应自己的配置修改下好了

 

新建文件:

# vi /etc/init.d/nginx

 

代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/sh
# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 66 38
# description: A php-fpm daemon.
                                            
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="php-fpm daemon"
NAME=php-fpm
DAEMON=/usr/local/php/sbin/$NAME
SCRIPTNAME=/etc/init.d/$NAME
                                            
# If the daemon file is not found, terminate the script.
test -x $DAEMON || exit 0
                                            
d_test() {
    $DAEMON -t
}
d_start() {
    $DAEMON || echo -n " already running"
}
d_stop() {
    kill -INT `cat /usr/local/php/var/run/php-fpm.pid`
}
d_reload() {
    kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`
}
                                            
case "$1" in
    test)
      d_test
      echo "."
      ;;
    start)
      echo -n "Starting $DESC: $NAME"
      d_start
      echo "."
      ;;
    stop)
      echo -n "Stopping $DESC: $NAME"
      d_stop
      echo "."
      ;;
    reload)
      echo -n "Reloading $DESC configuration..."
      d_reload
      echo "reloaded."
      ;;
    restart)
      echo -n "Restarting $DESC: $NAME"
      d_stop
      # Sleep for two seconds before starting again, this should give the
      # php-fpm daemon some time to perform a graceful stop.
      sleep 2
      d_start
      echo "."
      ;;
    *)
      echo "Usage: $SCRIPTNAME {test|start|stop|restart|reload}" >&2
      exit 3
      ;;
esac
                                            
exit $?

 

注册 php-fpm 服务

chmod +x /etc/init.d/php-fpm

chkconfig --add php-fpm

chkconfig --level 2345 php-fpm on

chkconfig --list php-fpm

 

相关 php-fpm 命令

检测 php-fpm 配置

# service php-fpm test

启动

# service php-fpm start

关闭

# service php-fpm stop

重启

# service php-fpm restart

重载配置

# service php-fpm reload

转载自(http://snailz.diandian.com/post/2012-10-24/40041265730)