脚本内容如下:
[root@7-node1 init.d]# cat php-fpmd #php-fpm start stop restart scripts #start php-fpm function start_php-fpm(){ if [ -f /application/php/var/run/php-fpm.pid ] then echo -e "php-fpm is started\n" else /application/php/sbin/php-fpm fi } function stop_php-fpm(){ if [ -f /application/php/var/run/php-fpm.pid ] then kill -INT `cat /application/php/var/run/php-fpm.pid` else echo -e "php-fpm is stopped\n" fi } function restart_php-fpm(){ if [ -f /application/php/var/run/php-fpm.pid ] then kill -USR2 `cat /application/php/var/run/php-fpm.pid` else /application/php/sbin/php-fpm fi } case "$1" in start) start_php-fpm ;; stop) stop_php-fpm ;; restart) restart_php-fpm ;; *) printf "Usage:$0 {start|stop|restart}\n" esac [root@7-node1 init.d]#
在/lib/systemd/system下面增加一个name.service就可以,或者在/usr/lib/systemd/system下面增加,一般在/lib/systemd/system下面增加了系统会自动复制一份到/usr/lib/systemd/system下面。
[root@7-node1 systemd]# cat /lib/systemd/system/php-fpmd.service [Unit] Description=php-fpmd After=network.target [Service] Type=forking ExecStart=/application/php/sbin/php-fpm ExecStop=/etc/init.d/php-fpmd stop Restart=/etc/init.d/php-fpmd restart [Install] WantedBy=multi-user.target [root@7-node1 systemd]#
增加了上面之后,然后执行:systemctl daemon-reload,然后就可以用systemctl start/stop/restart php-fpmd.service来启动关闭php。
原文链接:centos7.2上的php-fpm启动脚本,转载请注明来源!