CentOS 7. X sets custom boot and adds custom system services

January 15, 2017 854 point heat 0 liked it 0 comments

CentOS system service script Directory:

It can be divided into system and user,
Programs that can be run without logging on are stored in the system, that is:

On the contrary, programs that can only be run after a user logs in exist in the user
Service ends with. Service.
Take nginx as an example
1. Establish service documents

 vim /lib/systemd/system/nginx.service
 [Unit]   Description=nginx   After=network.target     [Service]   Type=forking   ExecStart=/www/lanmps/init.d/nginx start   ExecReload=/www/lanmps/init.d/nginx restart   ExecStop=/www/lanmps/init.d/nginx  stop   PrivateTmp=true     [Install]   WantedBy=multi-user.target

[unit]: description of the service
Description: describes the service
After: describes the service category
Setting of service running parameters
Type = forking is the form of running in the background
Execstart runs the command for the service
Execreload is the restart command
Execstop is the stop command
Privatetmp = true indicates that the service is allocated independent temporary space
Note: absolute path is required for start, restart and stop commands of [service]
[install] service installation related settings, can be set to multi-user

2. Save the directory
Save in directory with 754 permissions:

3. Set the boot to start automatically

 systemctl enable nginx.service

4. Other orders

Task old instruction new instruction
Make a service automatically start chkconfig -- level 3 httpd on systemctl enable httpd.service
Make a service not automatically start chkconfig -- level 3 httpd off systemctl disable httpd.service
Check the service status service httpd status systemctl status httpd.service
Systemctl is active httpd.service
Show all started services chkconfig -- list systemctl 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 boot up

 systemctl enable nginx.service

Stop and start

 systemctl disable nginx.service

View current service status

 systemctl status nginx.service

Restart service

 systemctl restart nginx.service

View all started services

 systemctl list-units --type=service


If life is just like the first sight, what is the sad autumn wind painting fan

Article review