Systemd service files

From artserver wiki
Revision as of 16:58, 24 March 2019 by Andre (talk | contribs)

I decided to write this quick n dirty recipe, as I always have to make a few web searches to remind myself on how to do a Linux systemd service file.

Very basically a service file is a set of instructions on how to execute a script/program. Useful parameters such as when the script should start, what do to if there are errors, etc.

Location

  • Location: service files are usually located in /etc/systemd/system/
  • extension: have the extension .service

Structure

  • [Unit] generic options, such as description, unit's behavior, and dependencies
    • Description A short description of the unit.
    • Documentation A list of URIs referencing documentation.
    • Before, After The order in which units are started.
    • Requires If this unit gets activated, the units listed here will be activated as well. If one of the other units gets deactivated or fails, this unit will be deactivated.
    • Wants Configures weaker dependencies than Requires. If any of the listed units does not start successfully, it has no impact on the unit activation. This is the recommended way to establish custom unit dependencies.
    • Conflicts If a unit has a Conflicts setting on another unit, starting the former will stop the latter and vice versa.
  • [Install]
    • Alias A space-separated list of additional names for the unit. Most systemctl commands, excluding systemctl enable, can use aliases instead of the actual unit name.
    • RequiredBy, WantedBy The current service will be started when the listed services are started. See the description of Wants and Requires in the [Unit] section for details.
    • Also Specifies a list of units to be enabled or disabled along with this unit when a user runs systemctl enable or systemctl disable.
  • [Service] .



After creating your myservice.service file:

  • enable it: sudo systemctl enable myservice.service
    • the command with create a symbolic link
  • start the service: sudo systemctl start myservice.service
  • check its status: sudo systemctl satus myservice.service

If after enabled you make changes to the service file, you will need to sudo systemctl daemon-reload to ingrate the changes.


Blog 2019

... more about "Systemd service files"
Date"Date" is a type and predefined property provided by Semantic MediaWiki to represent date values.
2019 +