systemd service unit notes

In this tutorial, The describe systemd service unit notes.

  • systemd is a system and service manager for Linux.
  • init is no longer an old Linux.
  • Only the systemctl command can be used for starting and stopping.

systemd service unit file

  • It is arranged under “/etc/systemd/system” with “unitname.service
  • Others include directories like “/usr/lib/systemd” and “/lib/systemd“, but rather for systems.

Service section

Describe the operation parameters of the unit.


The relationship between the execution command and the main process is represented by Type.

  • simple: ExecStart command remains as it is main process
  • forking: Child process of ExecStart is main process
  • oneshot: Even if ExecStart ends, the main process will remain.


Restart conditions can be specified with parameters equivalent to respawn in the old inittab.

  • always: always rerun
  • on-abort: re-execute when terminating with a signal that can not be caught
  • on-watchdog: Rerun with monitor timeout
  • on-abnormal: Re-execution when terminating with a signal other than SIGHUP, SIGINT, SIGTERM or SIGPIPE
  • on-failure: re-execution when the main process ends with a code other than the normal termination code
  • on-success: Rerun when the main process ends with a normal exit code

Install section

Specify which target (old runlevel) should be executed when the unit is activated (sytemctl enable).

For example, when enabling in multi-user mode (old run level 3), a symbolic link to a unit file is established under “/etc/systemd/system/“.

After=Execute after starting the specified unit list
Before=Execute before the specified unit list
Requires=Execute after the specified unit list has been successfully started
Wants=Even if the specified unit list fails to start up

Environment=environment variable list
EnvironmentFile=environment variable file
ExecStart=start command
ExecStop=stop command
ExecReload=reload command
PIDFile=PID file path of main process
User=ExecXX execution user
SuccessExitStatus=(other than 0) EXIT code list to be regarded as a normal completion of the main process

Alias=service alias list
WantedBy=target list
Also=unit list installed together

used commands

Unit file installation (loading)

$ sudo systemctl daemon-reload


$ systemctl enable|disable unitname

Dependency display

$ systemctl list-dependencies unitname

For example, List Dependency of chronyd package.

systemd service unit notes

Confirm startup sequence

Summary of time spent on startup (kernel, initrd, user)

$ systemd-analyze time

Time is taken to activate unit (currently active unit)

$ systemd-analyze blame

SVG output startup sequence

$ systemd-analyze plot > systemd.sequence.svg 

Confirm log

$ journalctl -xe 
$ journalctl -xe -S "2019-01-22 23:00:00"  
$ journalctl -xe -S "2019-01-22 23:00:00" -U "2019-01-22 23:10:00" 
$ journalctl -xe -u unitname
$ journalctl -f -u servicename 
$ journalctl --disk-usage

$ lsof -p $(pidof systemd-journald)

Reference information

  • man systemd.service
  • man systemd-analyze

unit file example

Apache system (fork daemon)

myhttpd.service unit file

Description=HTTP Server

ExecStart=/opt/bin/apachectl start
ExecStop=/opt/bin/apachectl graceful-stop


web.service unit file

Description=WebSphere Application Server apserver network.service

ExecStart=/opt/AppServer/profiles/AppSrv01/bin/ apserver
ExecStop=/opt/AppServer/profiles/AppSrv01/bin/ apserver
SuccessExitStatus=143 0


systemd service unit notes. Thank you for reading the DevopsRoles page!

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.