CentOS 7.x custom startup settings
I. Overview
CentOS 7 inherits New Features of RHEL 7, such as powerful systemctl. The use of systemctl also makes the/etc/init of system services in the past. d/'s startup script method has changed, greatly improving the operating efficiency of system services. However, the service configuration is significantly different from the previous one.
The systemctl script of the CentOS 7 service is stored in:/usr/lib/systemd/. There are systems and users, such as programs that can be run without logon, there is still a system service, that is, under the/usr/lib/systemd/system directory, and each service uses. end of the service.
Centos System Service Script directory:
/usr/lib/systemd
If you need to start a program that can run without logging on to the system, it exists in the system service, namely:
/usr/lib/systemd/system
2. Start Configuration
2.1 environment ==>
1. Add the self-starting service uwsgi
2. Self-start script to be written
3. I put the boot script in the/etc/init. d/directory and add the execution permission.
2.2 configuration ==>
Each service ends with a. Service and is generally divided into three parts: [Unit], [service], and [Install]. The Service I wrote is used to run the uwsgi project at startup. The details are as follows:
[root@tsingserver~]#cd/usr/lib/systemd/system[root@tsingserversystem]#vimuwsgid.service[Unit]Description=uwsgidAfter=network.target[Service]Type=forkingExecStart=/etc/init.d/uwsgidstartExecReload=/etc/init.d/uwsgidrestartExecStop=/etc/init.d/uwsgidstopPrivateTmp=true[Install]WantedBy=multi-user.target
After the service script is compiled as above, it is saved to the/usr/lib/systemd/system directory with 754 permissions.
[root@tsingserversystem]#chmod754uwsgid.service
The configuration file is described as follows:
[Unit] ==> service description
Description: describes the service.
After: Describes the service category.
[Service] ==> Service running parameter settings
Type = forking: running in the background
ExecStart: The specific running command for the service
ExecReload: restart command
ExecStop: indicates 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
--------------------------------------------------------------------------------
3. Set auto-start upon startup
systemctlenableuwsgid.service
4. Other commands
The following uses the httpd service as an example.
TaskOld commandsNew commands enable a service to automatically start chkconfig -- level 3 httpd on systemctl enable httpd. service so that a service does not automatically start chkconfig -- level 3 httpd offsystemctl disable httpd. service to 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 to start a service httpd startsystemctl start httpd. service to stop a service httpd stopsystemctl stop httpd. restart a service httpd restartsystemctl restart httpd. serviceStart 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
Reference blog: http://blog.csdn.net/yuanguozhengjust/article/details/38019923
Http://www.centoscn.com/CentOS/config/2015/0507/5374.html