Process Analysis of Nginx Server Adding Systemd Custom Service
- 2021-09-12 02:41:40
- OfStack
1. Take nginx as an example
nginx installed using the yum command
The Systemd service file ends with. service. For example, if you want to set up nginx for startup, if you install it with yum install command, yum command will automatically create nginx. service file, and directly use the command:
systemcel enable nginx. service//Startup
Compiled and installed using source code
1. Manually create the nginx. service service file. And place it in the/lib/systemd/system folder.
nginx. service reads as follows:
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/data/nginx/sbin/nginx
ExecReload=/data/nginx/sbin/nginx -s reload
ExecStop=/data/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
PS: Note that the above ExecStart/ExecReload/ExecStop must be based on its own
Corresponding key description
Description: Describe a service
After: Describe service categories
[Service] Service Running Parameter Settings
Type=forking is the form of running in the background
ExecStart is the specific running command of the service
ExecReload is the restart command
ExecStop is the stop command
PrivateTmp = True denotes allocating independent temporary space to services
Note: [Service] start, restart, stop commands all require absolute paths
[Install] Settings related to service installation at the run level can be set to multi-user, i.e. the system run level is 3
Save exit.
2. Set the startup
systemctl enable nginx.service
Other service orders
systemctl start nginx. service (Start nginx Service)
systemctl stop nginx. service (Stop nginx service)
systemctl enable nginx. service
systemctl disable nginx. service
systemctl status nginx. service (View current service status)
systemctl restart nginx. service (Restart Service)
systemctl list-units-type=service (View all started services)