CentOS7 custom boot item
Centos System Service Script directory:
/Usr/lib/systemd/
There are systems and users,
If you need to start a program that can run without logging on to the system, it exists in the system service, namely:
/Lib/systemd/system/
Otherwise, the program that can run only after the user logs on exists in the user
The service ends with. service.
The following uses nginx as an example.
1. Create a service file
Vim/lib/systemd/system/nginx. service
[Unit]
Description = nginx
Afterdomainnetwork.tar get
[Service]
Type = forking
ExecStart =/www/lanmps/init. d/nginxstart
ExecReload =/www/lanmps/init. d/nginxrestart
ExecStop =/www/lanmps/init. d/nginx stop
PrivateTmp = true
[Install]
Wantedbypolicmulti-user.tar get
[Unit]: Service Description
Description: describes the service.
After: Describes the service category.
[Service] Service running parameter settings
Type = forking is the form of background running
ExecStart is the specific running command of the service.
ExecReload is the restart command
ExecStop is the Stop command
PrivateTmp = True indicates that an independent temporary space is allocated to the service.
Note: the absolute path is required for the [Service] startup, restart, and stop commands.
[Install] service installation settings, which can be set to multiple users
2. Save the Directory
Save as 754 permissions in the directory:
/Lib/systemd/system
3. Set auto-start upon startup
Systemctl enable nginx. service
4. Other commands
New commands of old task commands
Enable a service to automatically start chkconfig -- level 3 httpd on systemctl enable httpd. service
Make a service not automatically start chkconfig -- level3 httpd off systemctldisable httpd. service
Check service status servicehttpd status systemctlstatus httpd. service (service details)
Systemctlis-active httpd. service (only show whether it is Active)
Show all started services chkconfig -- list systemctllist-units -- type = service
Start a service servicehttpd start systemctlstart httpd. service
Stop a service servicehttpd stop systemctlstop httpd. service
Restart a service servicehttpd restart systemctlrestart httpd. service
Start the nginx Service
Systemctl start nginx. service
Set auto-start
Systemctl enable nginx. service
Stop Auto-start
Systemctl disable nginx. service
View Current Service Status
Systemctl status nginx. service
Restart the service
Systemctl restart nginx. service
View all started services
Systemctl list-units -- type = service