Systemd Service Management Program
Systemctl is the most important tool. It integrates the functions of service and chkconfig. You can use it to enable or disable services permanently or only in the current session.
Run the following command to list running services or other: systemctl
For more information, see man systemctl ). Systemd-cgls lists running processes in a tree. It recursively displays the content of a given control group. For more information, see systemd-cgls manual.
How do I start, disable, enable, and disable a service?
Run a service:
Systemctl start Foo. Service:
Systemctl stop Foo. Service restart a service:
Systemctl restart Foo. Service
Displays the status of a service (whether running or not): systemctl status Foo. Service
Enable a service at startup: systemctl enable Foo. Service
Disable a service at startup: systemctl disable Foo. Service
Check if the service is started: systemctl is-enabled iptables. Service; echo $?
Modify the running level:
Systemd uses a more free target concept than sysvinit.
3rd run-level replacement with multi-user.target. 5th use graphical.tar get to replace the runtime class. Runlevel3.target and runlevel5.target are symbolic links to multi user.targetand graphical.tar get respectively.
You can use the following command to switch to "RunTime Level 3 ":
Systemctl isolate multi-user.target (OR)
Systemctl isolate runlevel3.target
You can also use the following command to switch to "running level 5 ":
Systemctl isolate graphical.tar get (OR)
Systemctl isolate runlevel5.target
How can I change the default running level?
Systemd uses links to point to the default running level. Before creating a new link, you can run the following command to delete the existing link: Rm/etc/systemd/system/default.tar get
Switch to runtime Level 3 by default:
Ln-SF/lib/systemd/system/multi-user.target/etc/systemd/system/default.tar get
Switch to running level 5 by default:
Ln-SF/lib/systemd/system/graphical.tar get/etc/systemd/system/default.tar get
Systemd does not use the/etc/inittab file. How can I view the current running level?
The runlevel command can still work in systemd. You can continue to use it, although systemd uses the 'target' concept (multiple 'targets' can be activated at the same time) to replace the runlevel of the previous system.
The equivalent systemd command is
Systemctl list-units -- type = Target
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.
Each service. the end of a service is generally divided into three parts: [unit], [SERVICE], and [install]. The service I wrote is used to start a node. JS project, details:
[Plain]View plaincopy
- [Unit]
- Description = xiyoulibapi
- Afterappsnetwork.tar get remote-fs.target nss-lookup.target
- [Service]
- Type = forking
- Pidfile =/node. JS/PID
- Execstart =/usr/local/bin/forever start/node. JS/xiyoulib/bin/WWW
- Execreload =/usr/local/bin/forever restart/node. JS/xiyoulib/bin/WWW
- Execstop =/usr/local/bin/Forever stop/node. JS/xiyoulib/bin/WWW
- Privatetmp = true
- [Install]
- Wantedbypolicmulti-user.tar get
The [unit] section mainly describes the service, including description and after. description is used to describe the service, and after is used to describe the service category.
[SERVICE] is the key of the service and the setting of some specific running parameters of the service. Here, type = forking is the form of running in the background, and pidfile is the file path for storing the PID, execstart is the specific running command of the service, execreload is the restart command, execstop is the Stop command, and privatetmp = true indicates that the service is allocated an independent temporary space. Note: the absolute path is required for all the commands for starting, restarting, and stopping [SERVICE]. An error is returned if the relative path is used!
[Install] is related to the service installation settings, which can be set to multiple users.
After the service script is compiled as above, it is saved in the/usr/lib/systemd/system directory with 754 permissions. Then you can use systemctl for configuration.
First, use systemctl start [service name (also file name)] to test whether the service can run successfully. If it cannot run, use systemctl status [service name (also file name)] view the error information and other service information, and modify the information based on the error report until start is available. If you are not at ease, you can test the restart and stop commands.
Then, you only need to use systemctl enable XXXXX to add the Written service to the on-premises startup.
The Compiling Method of my script is based on the compiling method of nginx, or similar programs with other functions.
In this case, although systemctl is unfamiliar, it is actually better than init. d. That method is much simpler and easier to use. There are still many operations that can be simplified by systemctl. Now there are a lot of information. It seems that RHEL/centos is more advanced than other Linux releases, this update finally abandoned the Linux 2.6 kernel, improving both speed and stability.
Systemd in centos 7