CentOS 7 above is initialized with SYSTEMD system, SYSTEMD is the latest initialization system (INIT) in Linux system, its main design goal is to overcome the inherent shortcomings of sysvinit, and improve the system startup speed. Details about the systemd are here.
SYSTEMD Service files end with. Service, such as now to build nginx for boot, if installed with yum install command, yum command will automatically create Nginx.service file, directly with the command
Systemcel Enable Nginx.service
Set the boot up.
Here I was compiled with the source code to install, so to manually create the Nginx.service service file.
A program that can run without logging on, exists in system service, i.e.:
/lib/systemd/system/
1. Create a Nginx.service file in the System services directory
Vim/lib/systemd/system/nginx.service
The contents are as follows
[Unit] Description=nginx After=network.target [Service] type=forking Execstart=/usr/local/nginx/sbin/nginx ExecReload=/usr /local/nginx/sbin/nginx-s Reload Execstop=/usr/local/nginx/sbin/nginx-s quitprivatetmp=true [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 service installation under [Install] run level, can be set to multi-user, i.e. system run level is 3
Save exit.
2. Set Boot up
Systemctl Enable Nginx.service
3.nginx command
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 started
Systemctl list-units--type=service
Comparison of 4.Systemd command and Sysvinit command
sysvinit Command |
Systemd Command |
Notes |
Service Foo Start |
Systemctl Start Foo.service |
Used to start a service (does not restart the existing one) |
Service Foo Stop |
Systemctl Stop Foo.service |
Used to stop a service (and not restart the existing one). |
Service Foo Restart |
Systemctl Restart Foo.service |
Used to stop and start a service. |
Service Foo Reload |
Systemctl Reload Foo.service |
When supported, remount the configuration file without interrupting the wait operation. |
Service Foo Condrestart |
Systemctl Condrestart Foo.service |
If the service is running then restart it. |
Service Foo Status |
Systemctl Status Foo.service |
Reports whether the service is running. |
ls/etc/rc.d/init.d/ |
Systemctl List-unit-files--type=service |
Used to list the services that can be started or stopped. |
Chkconfig foo on |
Systemctl Enable Foo.service |
Setting the service to Enabled at the next startup or when other trigger conditions are met |
Chkconfig foo off |
Systemctl Disable Foo.service |
Setting the service to disabled at the next startup or when other trigger conditions are met |
Chkconfig Foo |
Systemctl is-enabled Foo.service |
Used to check whether a service is configured to be enabled or disabled in the current environment. |
Chkconfig–list |
Systemctl List-unit-files--type=service |
Output enabled and disabled for the service under each run level |
Chkconfig foo–list |
Ls/etc/systemd/system/*.wants/foo.service |
Use to list which run levels the service is enabled and disabled under. |
Chkconfig Foo–add |
Systemctl Daemon-reload |
Used when you create a new service file or change settings. |
Telinit 3 |
Systemctl isolate Multi-user.target (or Systemctl isolate Runlevel3.target OR telinit 3) |
Change the maximum user run level. |
5.Sysvinit run level and systemd target table
Sysvinit Run Level |
Systemd Target |
Notes |
0 |
Runlevel0.target, Poweroff.target |
Shut down the system. |
1, S, single |
Runlevel1.target, Rescue.target |
Single-user mode. |
2, 4 |
Runlevel2.target, Runlevel4.target, Multi-user.target |
User-defined/domain-specific runlevel. The default is equal to 3. |
3 |
Runlevel3.target, Multi-user.target |
Multi-user, non-graphical. Users can log on through multiple consoles or networks. |
5 |
Runlevel5.target, Graphical.target |
Multi-user, graphical. Typically, all run Level 3 services plus graphical logins. |
6 |
Runlevel6.target, Reboot.target |
Restart |
Emergency |
Emergency.target |
Emergency Shell |
Original Address http://www.dohooe.com/2016/03/03/352.html
CentOS 7.x write boot start service