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
In JavaScript, use the removeAttribute() method o...
GitHub has all kinds of magic tools. Today I foun...
Margin of parallel boxes (overlap of double margi...
The relationship between Javascript and DOM is ve...
Table of contents 1. What I am going to talk abou...
<br />When we design web pages, we always en...
Table of contents About Triggers Use of triggers ...
Method 1: Use cmd command First, open our DOS win...
Effect The pictures in the code can be changed by...
Overview Binlog2sql is an open source MySQL Binlo...
Business scenario: The visitor's visit status...
This status code provides information about the s...
1. View openjdk rpm -qa|grep jdk 2. Delete openjd...
1. Introduction When the amount of data in the da...
Here we introduce the centos server with docker i...