centos中 nginx,php添加到Service,设置开机启动(自启动)

这篇文章主要介绍了centos7系统下nginx,php开机自启动操作方法, 具有参考借鉴价值

1. 创建nginx启动命令脚本

#   vim   /etc/init.d/nginx

插入以下内容, 注意修改PATH和NAME字段, 匹配自己的安装路径

#! /bin/bash
# chkconfig: - 85 15
PATH=/usr/local/webserver/nginx
DESC="nginx daemon"
NAME=nginx
DAEMON=$PATH/sbin/$NAME
CONFIGFILE=$PATH/conf/$NAME.conf
PIDFILE=$PATH/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
$DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}
do_stop() {
$DAEMON -s stop || echo -n "nginx not running"
}
do_reload() {
$DAEMON -s reload || echo -n "nginx can't reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
do_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
do_stop
echo "."
;;
reload|graceful)
echo -n "Reloading $DESC configuration..."
do_reload
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME"
do_stop
do_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac

exit 0

 

设置执行权限

#   chmod a+x /etc/init.d/nginx

注册成服务

#   chkconfig --add nginx

设置开机启动

#   chkconfig  nginx on

运行如图:

#   /sbin/chkconfig --list nginx

注:我这是中文版的

 

2. 创建php启动命令脚本

#   vim   /etc/init.d/php-fpm

插入以下内容, 注意修改PATH和NAME字段, 匹配自己的安装路径

!/bin/bash
# php-fpm startup script for the php-fpm
# php-fpm version:5.5.0-alpha6
# chkconfig: - 85 15
# description: php-fpm is very good
# processname: php-fpm
# pidfile: /var/run/php-fpm.pid
# config: /usr/local/webserver/php5/etc/php-fpm.conf

php_command=/usr/local/webserver/php5/sbin/php-fom
php_config=/usr/local/webserver/php5/etc/php-fpm.conf
php_pid=/usr/local/webserver/php5/var/run/php-fpm.pid
RETVAL=0
prog="php-fpm"

#start function
php_fpm_start() {
/usr/local/webserver/php5/sbin/php-fpm
}

start(){
if [ -e $php_pid ]
then
echo "php-fpm already start..."
exit 1
fi
php_fpm_start
}

stop(){
if [ -e $php_pid ]
then
parent_pid=`cat $php_pid`
all_pid=`ps -ef | grep php-fpm | awk '{if('$parent_pid' == $3){print $2}}'`
for pid in $all_pid
do
kill $pid
done
kill $parent_pid
fi
exit 1
}

restart(){
stop
start
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|status}"
exit 1
esac
exit $RETVAL

 

设置执行权限

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

注册成服务

#   chkconfig --add php-fpm

设置开机启动

#   chkconfig  php-fpm on

运行如图:

#   /sbin/chkconfig --list php-fpm

注:我这是中文版的

 

0 条评论
发表一条评论