systemd: The service systemctl script of CentOS 7 is stored in: /usr/lib/systemd/, which is divided into system (system) and user (user), namely: /usr/lib/systemd/system, /usr/lib/systemd/user Each service ends with .service and is generally divided into three parts: [Unit], [Service], and [Install]. Take nginx as an example, the specific contents are as follows: Create a service: Create the nginx.service file under /usr/lib/systemd/system with the following content (it can also be created under /usr/lib/systemd/usr depending on the application requirements): [Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/run/nginx.pid ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target [Unit] After= : Dependency, start the custom service unit only after the dependent service is started [Service]
PIDFile: pid file path [Install] WantedBy: The user mode for service installation. Literally, it means who wants to use this service? The target used in the above text is: multi-user.target, which means that the directory that wants to use this service is multi-user. "The above is all my personal understanding and guesswork. If there is anything wrong, please give me your advice." Each .target is actually a collection of links to our unit files. When we execute: $ sudo systemctl enable nginx.service A new link to the /usr/lib/systemd/system/nginx.service file will be created in the /etc/systemd/system/multi-user.target.wants/ directory. Operation Service: #Start the service$ sudo systemctl start nginx.service #View the log $ sudo journalctl -f -u nginx.service -- Logs begin at Thursday 2015-06-25 17:32:20 CST. -- Jun 25 10:28:24 Leco.lan systemd[1]: Starting nginx - high performance web server... Jun 25 10:28:24 Leco.lan nginx[7976]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok Jun 25 10:28:24 Leco.lan nginx[7976]: nginx: configuration file /etc/nginx/nginx.conf test is successful Jun 25 10:28:24 Leco.lan systemd[1]: Started nginx - high performance web server. #Restart$ sudo systemctl restart nginx.service #Reload $ sudo systemctl reload nginx.service #Stop$ sudo systemctl stop nginx.service The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Solution to the initialization error when installing mysql5.7 from rpm package in centos6.5
>>: VUE implements a Flappy Bird game sample code
Table of contents 1. Database Engine 1.1 View dat...
This article example shares the specific code of ...
Table of contents Common array methods pop() unsh...
Copy code The code is as follows: <!DOCTYPE ht...
Table of contents introduce Implementation steps ...
CentOS8 was released a few days ago. Although it ...
1. After installing the Windows version of Docker...
This article shares the specific code for impleme...
After MySQL database optimization, not only can t...
Preface Today, a developer gave me feedback that ...
What is DNS The full name of DNS is Domain Name S...
Elastic stack, commonly known as ELK stack, is a ...
The default operating mode of MySQL is autocommit...
Table of contents Node connects to Mysql Install ...
FileReader is an important API for front-end file...