Nginx实现systemctl管理
源码安装的软件默认无法使用systemd管理,如果需要使用systemd管理源码安装的软件需要手动编写服务的service文件(编写是可以参考其他服务的模板文件)。
Service文件存储路径为/usr/lib/system/system/目录。
[root@centos7 ~]# vim /usr/lib/systemd/system/nginx.service
以下是nginx服务最终编辑好的模板:
[Unit]
Description=nginx - high performance web server #描述信息
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target #指定启动nginx之前需要其他的其他服务,如network.target等
[Service]
Type=forking
PIDFile=/var/run/nginx.pid ##根据nginx.conf一致,默认:/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 #设置执行systemctl start nginx后需要启动的具体命令.
ExecReload=/usr/local/nginx/sbin/nginx -s reload #设置执行systemctl reload nginx后需要执行的具