nginx.service 文件如下:
[Unit]
Description=nginx
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/run/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=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
每次启动后过一会nginx就自动停止了,日志如下:
[root@wsxdream system]# systemctl status nginx.service
● nginx.service - nginx
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: failed (Result: timeout) since Sat 2018-11-24 15:12:16 CST; 3min 54s ago
Process: 23355 ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf (code=exited, status=0/SUCCESS)
Process: 23353 ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf (code=exited, status=0/SUCCESS)
Nov 24 15:10:46 wsxdream systemd[1]: Starting nginx...
Nov 24 15:10:46 wsxdream nginx[23353]: nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
Nov 24 15:10:46 wsxdream nginx[23353]: nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Nov 24 15:10:46 wsxdream systemd[1]: PID file /run/nginx.pid not readable (yet?) after start.
Nov 24 15:12:16 wsxdream systemd[1]: nginx.service start operation timed out. Terminating.
Nov 24 15:12:16 wsxdream systemd[1]: Failed to start nginx.
Nov 24 15:12:16 wsxdream systemd[1]: Unit nginx.service entered failed state.
Nov 24 15:12:16 wsxdream systemd[1]: nginx.service failed.
一开始没有重视
PID file /run/nginx.pid not readable (yet?) after start.
后来查了资料,修改了 nginx/conf/nginx.conf 里的 pid 指定位置和 nginx.service 里保持一致,重新启动后搞定。