centos7 使用 systemd 代替之前的 systemv 的启动脚本,可以说更简单。不再需要编写一长段脚本。
复制以下内容到 / usr/lib/systemd/system/nginx.service
- [Unit]
- Description=nginx - high performance web server
- Documentation=http://nginx.org/en/docs/
- After=network.target remote-fs.target nss-lookup.target
- [Service]
- Type=forking
- PIDFile=/usr/local/nginx/logs/nginx.pid
- ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
- ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
- ExecReload=/bin/kill -s HUP $MAINPID
- ExecStop=/bin/kill -s QUIT $MAINPID
- PrivateTmp=true
- [Install]
- WantedBy=multi-user.target
即可使用 systemctl start|stop|reload|restart nginx 进行启动重启等操作。
systemctl enable nginx 即可实现开机启动。
systemctl disable nginx 取消开机启动。
来源: http://www.bubuko.com/infodetail-1947658.html