Centos System Services Script directory:
- /usr/lib/systemd/
System and users (user),
If you need to boot the program can be run without logging in, there is system services (systems), that is:
- /lib/systemd/system/
Conversely, the user login to run the program, the presence of users (user)
1 /lib/systemd/system equals/usr/lib/systemd/system2 /lib/systemd/user equals/usr/lib/systemd/user
The service ends with a. Service.
This is an example of an nginx boot operation.
1. Create a service file
1 cd/lib/systemd/system/2 cp-p tuned.service httpd. Service 3 Vim Httpd.service
1 [Unit]2description=Apache Httpd Serveice3After=httpdlog.Target4 5 [Service]6Type=forking7execstart=/usr/local/apache2/bin/apachectl Start8execreload=/usr/local/apache2/bin/apachectl Restart9execstop=/usr/local/apache2/bin/Apachectl StopTenprivatetmp=true One A [Install] -Wantedby=multi-user.Target -~
[Unit]: Description of the service
Description: Description Service
After: Describe the service category
settings for the [service] service run parameter
Type=forking is the form of a background run
Execstart specific run commands for the service
Execreload Reset Command
Execstop for Stop command
Privatetmp=true represents a separate temporary space allocated to the service
Note: The start, restart, and stop commands for [Service] all require absolute paths
Settings for the [Install] service installation, which can be set to multi-user
2. Save the Directory
Save in Directory with 754 permissions:
- /lib/systemd/system
3. Set up boot from boot
- Systemctl Enable Nginx.service
4. Other commands
Tasks |
old directives |
new directives |
enable a service to start automatically |
chkconfi G--level 3 httpd on |
systemctl enable Httpd.service |
cause a service not to start automatically |
chkconfig--level 3 httpd off |
systemctl disable Httpd.service |
Check service status |
services httpd status |
systemctl status httpd.service (service details) Sys Temctl is-active Httpd.service (show only active) |
Show All services started |
chkconfig--list |
sy Stemctl list-units--type=service |
start a service |
service httpd start |
systemctl start Httpd.service |
Stop a service |
service httpd stop |
systemctl stop Httpd.service |
Restart a service |
service httpd restart |
systemctl restart Httpd.service |
Start Nginx Service
Systemctl Start Nginx.service
Set up boot from
Systemctl Enable Nginx.service
Stop Boot from booting
Systemctl Disable Nginx.service
View the current status of the service
Systemctl Status Nginx.service
Restart Service
Systemctl Restart Nginx.service
View all services that have been started
Systemctl list-units--type=service
CentOS 7.x Setup Custom boot, add custom system service