CentOS 7.x allows you to set custom startup and add custom system services.
Centos System Service Script directory: [html] view plaincopyprint?
- /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:
[Html] view plaincopyprint?
- /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 [html] view plaincopyprint?
- Vim/lib/systemd/system/nginx. service
[Plain] view plaincopyprint?
- [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/nginxstop
- 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:
[Html] view plaincopyprint?
- /Lib/systemd/system
3. Set auto-start upon startup
[Html] view plaincopyprint?
- Systemctlenablengworkflow. service
4. Other commands
The new command of the old task command enables a service to automatically start chkconfig -- level 3 httpd on systemctl enable httpd. service causes a service to not automatically start chkconfig -- level 3 httpd offsystemctl disable httpd. service check service Status service httpd statussystemctl statushttpd. service (service details)
Systemctl is-active httpd. service (show Active only) display all started services chkconfig -- listsystemctl list-units -- type = service start a service httpd startsystemctl start httpd. service to stop a service httpd stopsystemctl stop httpd. restart a service httpd restartsystemctl restart httpd. service
Start the nginx Service
systemctlstartnginx.service
Set auto-start
systemctlenablenginx.service
Stop Auto-start
systemctldisablenginx.service
View Current Service Status
systemctlstatusnginx.service
Restart the service
systemctlrestartnginx.service
View all started services
systemctllist-units--type=service