Systemd is a system and service manager for Linux. It can run tasks in parallel (unlike SysVinit) which helps reducing boot time with tasks executed simultaneously. These tasks are called units and their configs are stored in files in the format
unit_name.type_extension in the
type_extention identifies the unit type, which may be a service, a mount, etc.
A unit service has a further
type definition that configures the unit startup functionality. The “types” are listed as follows:
- simple: It’s the default value if no
typeis defined. The process started with
ExecStartis the main process of the service. This is the preferred type for a service that remains attached to the shell after execution.
- forking: The process started with
ExecStartspawns a child process that becomes the main process of the service. The parent process exits when the startup is complete. This is the preferred type for services that would run in background.
- oneshot: This type is similar to
simple, but the process exits before starting consequent units. It’s useful for running commands sequentially.
- dbus: This type is similar to
simple, but consequent units are started only after the main process gains a D-Bus name.
- notify: This type is similar to
simple, but consequent units are started only after a notification message is sent via the
- idle: similar to
simple, but the actual execution of the service binary is delayed until all jobs are finished, which avoids mixing the status output with shell output of services.
[Unit] Description=My Program 123 After=syslog.target network.target [Service] Type=forking WorkingDirectory=/opt/my_progam User=user123 ExecStart=/opt/my_program/program123 PIDFile=/var/run/program123.pid TimeoutStartSec=3600 [Install] WantedBy=multi-user.target
In the above example, I defined the
type as forking, therefore the program will run detached from the main execution process.
After directive indicates that syslog and network services should have been started prior to starting “My Program 123”.
More information about systemd configuration can be found in the RHEL 7 System Administrator’s Guide.