Wednesday, November 18, 2015

How To Use Systemctl to Manage Systemd Services in RHEL7

Useful SystemD commands (hints for systemctl or systemctl vs chkconfig and service)
List all running services

# systemctl

Start/stop or enable/disable services

Activates a service immediately:

# systemctl start foo.service

Deactivates a service immediately:

# systemctl stop foo.service

Restarts a service:

# systemctl restart foo.service

Shows status of a service including whether it is running or not:

# systemctl status foo.service

Enables a service to be started on bootup:

# systemctl enable foo.service

Disables a service to not start during bootup:

# systemctl disable foo.service

Check whether a service is already enabled or not:

# systemctl is-enabled foo.service; echo $?

0 indicates that it is enabled. 1 indicates that it is disabled

How do I change the runlevel?

systemd has the concept of targets which is a more flexible replacement for runlevels in sysvinit.

Run level 3 is emulated by Run level 5 is emulated by is a symbolic link to and is a symbolic link to

You can switch to ‘runlevel 3′ by running

# systemctl isolate (or) systemctl isolate

You can switch to ‘runlevel 5′ by running

# systemctl isolate (or) systemctl isolate

How do I change the default runlevel?

systemd does not use /etc/inittab file.
List the current run level

# systemctl list-units --type=target

[root@redhat7 ~]# systemctl list-units --type target
UNIT                LOAD   ACTIVE SUB    DESCRIPTION        loaded active active Basic System   loaded active active Encrypted Volumes        loaded active active Login Prompts    loaded active active Graphical Interface loaded active active Local File Systems (Pre)     loaded active active Local File Systems   loaded active active Multi-User System      loaded active active Network          loaded active active Network File System Server        loaded active active Paths    loaded active active Remote File Systems       loaded active active Slices      loaded active active Sockets         loaded active active Swap      loaded active active System Initialization       loaded active active Timers

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.

runlevel command still works with systemd. You can continue using that however runlevels is a legacy concept in systemd and is emulated via ‘targets’ and multiple targets can be active at the same time.

If u want to change default runlevel by using following command u can change the default runlevel in rhel7

[root@rhel7 ~]# systemctl set-default

[root@rhel7 ~]# reboot or systemctl reboot

You are server defaulty goes to cli mode.

if u want graphical mode using following you can change the cli to graphical mode

[root@rhel7 ~]# systemctl set-default

[root@rehl7 ~]# reboot or systemctl reboot or init 6

you are default server is goes to graphical mode.

Service vs. systemd

# service NetworkManager stop


# systemctl stop NetworkManager.service

Chkconfig vs. systemd

# chkconfig NetworkManager off


# systemctl disable NetworkManager.service


systemd has a built-in readahead implementation is not enabled on upgrades. It should improve bootup speed but your mileage may vary depending on your hardware. To enable it:

# systemctl enable systemd-readahead-collect.service
# systemctl enable systemd-readahead-replay.service

How to check the number of service running on the you are server in rhel7?

using following command you can check number of services running on you are server

[root@rhel7~]# systemctl list-units --type service

SystemD cheatsheet

RHEL6                          RHEL7

service foobar start     systemctl start foobar.service             Used to start a service (not reboot persistent)
service foobar stop     systemctl stop foobar.service             Used to stop a service (not reboot persistent)
service foobar restart     systemctl restart foobar.service     Used to stop and then start a service
service foobar reload     systemctl reload foobar.service     When supported, reloads the config file without interrupting pending operations.
service foobar condrestart     systemctl condrestart foobar.service     Restarts if the service is already running.
service foobar status     systemctl status foobar.service     Tells whether a service is currently running.
ls /etc/rc.d/init.d/     ls /lib/systemd/system/*.service /etc/systemd/system/*.service     Used to list the services that can be started or stopped
chkconfig foobar on     systemctl enable foobar.service     Turn the service on, for start at next boot, or other trigger.
chkconfig foobar off     systemctl disable foobar.service     Turn the service off for the next reboot, or any other trigger.
chkconfig foobar     systemctl is-enabled foobar.service     Used to check whether a service is configured to start or not in the current environment.
chkconfig foobar –list     ls /etc/systemd/system/*.wants/foobar.service     Used to list what levels this service is configured on or off
chkconfig foobar –add           Not needed, no equivalent.

No comments:

Post a Comment