要注意 - 短横杠这个符号看看复制进去后有没有乱码,我之前就遇到这个问题,郁闷了好久才发现
提示:顶部的注释不要去除否则无法注册为系统服务,
关于:chkconfig: 2345 65 37
网上搜索总结了下意思是:
2345 为启动该服务的系统环境,65 为加载的优先级别,37 为关闭的优先级别
65,37这两个位置的数值不能相同,也不能和其它服务的数值冲突,这个我也没遇到过此类问题,如果有发现问题请对应自己的配置修改下好了
新建文件(最好在win下安装ssh客户端,这样可以直接copy脚本代码):
# vi /etc/init.d/nginx
代码如下:
#!/bin/sh
# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 65 37
# description: A nginx daemon.
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/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() {
$DAEMON -s quit || echo -n " not running"
}
d_reload() {
$DAEMON -s reload || echo -n " could not reload"
}
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
# Nginx 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启动脚本
#! /bin/sh
# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 65 37
#
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/sbin/$NAME
CONFIGFILE=/usr/local/etc/php-fpm.conf
PIDFILE=/usr/local/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
d_start() {
$DAEMON -y $CONFIGFILE || echo -n " already running"
}
d_stop() {
kill -QUIT `cat $PIDFILE` || echo -n " not running"
}
d_reload() {
kill -HUP `cat $PIDFILE` || echo -n " can't reload"
}
case "$1" in
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 1
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac
exit 0
(以注册nginx为系统服务为例,php-fpm注册流程类似,不再赘述)
注册 nginx 服务
chmod +x /etc/init.d/nginx
chkconfig --add nginx
chkconfig --level 2345 nginx on
chkconfig --list nginx
相关 nginx 命令
检测 nginx 配置
# service nginx test
启动
# service nginx start
关闭
# service nginx stop
重启
# service nginx restart
重载配置
# service nginx reload