Systemd is the new system and service manager for Linux. It is a replacement for init system and can manage system startup and services. It starts up and supervises the entire system. In article we are using [centos 7.0 installed with systemd 216 version][1] and the latest version is [available for download from freedesktop.org][2].
With new player in town, PID 1 is occupied by “systemd” and can be seen from pstree command as well:
Lets explore what systemd is capable of and what possibilities we have with the new replacement for sysVinit.
### 1. Faster startup ###
The sysvinit starts the processes serially, one at a time. Systemd starts services in parallel and starts only those services which are actually required, reducing the boot time significantly.
You can get the boot process duration with the following command:
If you want to print a list of all running units, the blame option to systemd-analyze command can provide you with that, ordered by the time taken to initialize.
The above screen shows only a small number of processes, you can scroll through the list with arrows just like in less pager.
### 2. The systemctl command ###
The systemctl command is the most talked command that comes with systemd. You can manage a whole lot of your system with this command. Let’s explore this command before going any further:
#### 2.1 List Units ####
systemctl command without any option lists all the running units. The list-units switch also does the same.
In the sysvinit, we could use the “service” command to manage the services, but with systemd, the systemctl command is used to manage services. In ordwer to see whether a service is running or not, we can use the systemctl command like this:
To start a service, again we use the systemctl command as:
[root@linoxide ~]# systemctl start dnsmasq
As opposed to service command, this command does not give any output. But of course, we can check the status of the service once again to confirm that its started successfully:
Typically, all of the ablve systemctl commands can be used to manage a remote host with systemctl command itself. This will use ssh for communication with the remote host. All you need to do is add the user and host to systemctl command like this:
[root@linoxide ~]# systemctl status sshd -H root@1.2.3.4
If you want to see what target you are in, you need to list all the corresponding units. It might not feel at home with this new way, but its the way systemd works.
You can see “graphical.target” listed here. This is what we changed our target into. Now let’s change the runlevel again to multi-user.target and then analyze this output:
The systemctl command can be used to put the system down, or reboot or hibernate.
To poweroff, reboot, suspend and hibernate, use the following commands respectively:
[root@linoxide ~]# systemctl poweroff
[root@linoxide ~]# systemctl reboot
[root@linoxide ~]# systemctl suspend
[root@linoxide ~]# systemctl reboot
### 9. Bonus ###
The systemd brings out the whole new approach to interacting with your operating system. The systemd is so full of features. For example, you can get the hostname and other useful features about your Linux machine, you can use hostnamectl command