CentOS 7.x Setup Custom boot, add custom system service

Source: Internet
Author: User

Centos System Services Script directory:



    1. /usr/lib/systemd/

System and users (user),

If you need to boot the program can be run without logging in, there is system services (systems), that is:


    1. /lib/systemd/system/

Conversely, the user login to run the program, the presence of users (user)

The service ends with a. Service.

This is an example of an nginx boot operation.

1. Create a service file

[HTML] view plaincopyprint?650) this.width=650; "alt=" View the code piece "Height=" "src=" https://code.csdn.net/ Assets/code_ico.png "width=" "style=" Padding:0px;margin:0px;border:none; "/>650" this.width=650; "alt=" Derive to my code slice "height=" "src=" Https://code.csdn.net/assets/ico_fork.svg "width=" "style=" padding:0px;margin:0px; Border:none; "/>

    1. Vim/lib/systemd/system/nginx.service

[Plain] view plaincopyprint?650) this.width=650; "alt=" View the code piece "height=" src= "https://code.csdn.net/" on Code Assets/code_ico.png "width=" "style=" Padding:0px;margin:0px;border:none; "/>650" this.width=650; "alt=" Derive to my code slice "height=" "src=" Https://code.csdn.net/assets/ico_fork.svg "width=" "style=" padding:0px;margin:0px; Border:none; "/>

  1. [Unit]

  2. Description=nginx

  3. After=network.target

  4. [Service]

  5. Type=forking

  6. Execstart=/www/lanmps/init.d/nginx start

  7. Execreload=/www/lanmps/init.d/nginx restart

  8. Execstop=/www/lanmps/init.d/nginx stop

  9. Privatetmp=true

  10. [Install]

  11. 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 the [Install] service installation, which can be set to multi-user

2. Save the Directory

Save in Directory with 754 permissions:

[HTML] view plaincopyprint?650) this.width=650; "alt=" View the code piece "Height=" "src=" https://code.csdn.net/ Assets/code_ico.png "width=" "style=" Padding:0px;margin:0px;border:none; "/>650" this.width=650; "alt=" Derive to my code slice "height=" "src=" Https://code.csdn.net/assets/ico_fork.svg "width=" "style=" padding:0px;margin:0px; Border:none; "/>

    1. /lib/systemd/system

3. Set up boot from boot

[HTML] view plaincopyprint?650) this.width=650; "alt=" View the code piece "Height=" "src=" https://code.csdn.net/ Assets/code_ico.png "width=" "style=" Padding:0px;margin:0px;border:none; "/>650" this.width=650; "alt=" Derive to my code slice "height=" "src=" Https://code.csdn.net/assets/ico_fork.svg "width=" "style=" padding:0px;margin:0px; Border:none; "/>

    1. Systemctl Enable Nginx.service

4. Other commands

Task Old instructions New directives
Enable a service to start automatically Chkconfig--level 3 httpd on Systemctl Enable Httpd.service
Make a service not start automatically Chkconfig--level 3 httpd off Systemctl Disable Httpd.service
Check Service status Service httpd Status Systemctl Status Httpd.service (service details)
Systemctl is-active Httpd.service (show only active)
Show all services that have been started 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 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 that have been started

Systemctl list-units--type=service


This article is from the "Dream to Reality" blog, please be sure to keep this source http://lookingdream.blog.51cto.com/5177800/1846507

CentOS 7.x Setup Custom boot, add custom system service

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.