声明:
脚本的路径
[root@server5 system]# pwd
/etc/systemd/system
脚本:
[root@server5 system]# vim nginx.service
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target 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
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
此时nginx已经可以用systemctl 命令修改查看状态了!!
[root@server5 system]# systemctl status nginx
● nginx.service - The NGINX HTTP and reverse proxy server
Loaded: loaded (/etc/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: inactive (dead)
[root@server5 system]# systemctl start nginx
[root@server5 system]# systemctl status nginx
● nginx.service - The NGINX HTTP and reverse proxy server
Loaded: loaded (/etc/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: active (running) since Sat 2019-03-30 23:26:34 CST; 13s ago
Process: 5108 ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 5107 ExecStartPre=/usr/local/nginx/sbin/nginx -t (code=exited, status=0/SUCCESS)
Main PID: 5112 (nginx)
CGroup: /system.slice/nginx.service
├─5112 nginx: master process /usr/local/nginx/sbin/nginx
└─5113 nginx: worker process
Mar 30 23:26:34 server5 systemd[1]: Starting The NGINX HTTP and reverse proxy ser.....
Mar 30 23:26:34 server5 nginx[5107]: nginx: the configuration file /usr/local/ngi...ok
Mar 30 23:26:34 server5 nginx[5107]: nginx: configuration file /usr/local/nginx/c...ul
Mar 30 23:26:34 server5 systemd[1]: Failed to read PID from file /usr/local/nginx...nt
Mar 30 23:26:34 server5 systemd[1]: Started The NGINX HTTP and reverse proxy server.
Hint: Some lines were ellipsized, use -l to show in full.