nginx自启动脚本
官方脚本
https://www.nginx.com/resources/wiki/start/topics/examples/redhatnginxinit/
下面的脚本是测试有用的一个 就是在自启动这块有点问题
nginx目录:/usr/etc/nginx1910
所在目录:/etc/init.d
vi nginx 粘贴下面的代码到文件 I插入模式 复制进去 ESC :wq 回车
给文件执行权限 chmod +x ./nginx
测试脚本 ./nginx stop
#! /bin/sh
# nginx Startup script for the Nginx HTTP Server
# chkconfig: 345 85 15
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/etc/nginx1910/sbin/$NAME
CONFIGFILE=/usr/etc/nginx1910/conf/$NAME.conf
PIDFILE=/usr/etc/nginx1910/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() {
kill -INT `cat $PIDFILE` || echo -n "nginx not running"
}
do_reload() {
kill -HUP `cat $PIDFILE` || 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
centos 7 systemctl自启动
查看nginx状态,systemctl status nginx

参考资料
http://www.centoscn.com/CentOS/config/2015/0507/5374.html 很重要参考
http://bbs.qcloud.com/thread-10429-1-1.html 最重要参考
http://www.csdn.net/article/2015-02-27/2824034 很重要参考
http://zhidao.baidu.com/link?url=kYYPNa6aYvE-cTLlsDvyS0oKqRIq4YbJwx5krxg534IVxY4t_WSArdki-x3VOtVIElfwV9g1e31lLpPEIqYOzisdPYPW6jnWIDTXjDbAaFq
http://www.linuxidc.com/Linux/2014-07/104487.htm
http://www.csdn.net/article/2015-02-27/2824034
[Unit]
Description=nginx1.9.10
After=network.target
[Service]
Type=forking
PIDFile=/usr/etc/nginx1910/logs/nginx.pid
ExecStart=/usr/etc/nginx1910/sbin/nginx start
ExecReload=/usr/etc/nginx1910/sbin/nginx restart
ExecStop=/usr/etc/nginx1910/sbin/nginx stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[root@localhost system]# systemctl enable nginx.service
[root@localhost system]# pkill -9 nginx
[root@localhost ~]# systemctl start nginx.service
Job for nginx.service failed. See 'systemctl status nginx.service' and 'journalctl -xn' for details. 这里测试是否正常启动nginx.service
查看服务状态
[root@localhost ~]# systemctl status nginx.service
nginx.service - nginx1.9.10
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled)
Active: failed (Result: exit-code) since 四 2016-06-02 08:03:37 CST; 3min 56s ago
Process: 760 ExecStart=/usr/etc/nginx1910/sbin/nginx start (code=exited, status=1/FAILURE)
6月 02 08:03:37 localhost.localdomain nginx[760]: nginx: invalid option: "start"
6月 02 08:03:37 localhost.localdomain systemd[1]: nginx.service: control process exited, code=exited status=1
6月 02 08:03:37 localhost.localdomain systemd[1]: Failed to start nginx1.9.10.
6月 02 08:03:37 localhost.localdomain systemd[1]: Unit nginx.service entered failed state.
解决办法:
http://www.cnblogs.com/xxx91hx/p/5848602.html

浙公网安备 33010602011771号