Skip to content

Instantly share code, notes, and snippets.

@javajawa
Created August 5, 2019 15:18
Show Gist options
  • Save javajawa/a3a5f62115456da4429cd5e0ade3233b to your computer and use it in GitHub Desktop.
Save javajawa/a3a5f62115456da4429cd5e0ade3233b to your computer and use it in GitHub Desktop.
Service Magic

Service file: put in /etc/systemd/system/[name].service

[Unit]
Description=Run foo

# You can sepcify dependencies
#After=network.target

[Service]
# Service that is not actually a service
# Process is spawned (state=active) then exits (state=inactive)
Type=simple

# The actual program to run
ExecStart=/usr/local/bin/foo

[Install]
# You can make it so that you can run all
# processes you need with
#   systemctl start magic-process-group.target
WantedBy=magic-process-group.target

Checking script

Check if foo.service or bar.service are running, otherwise exit

systemctl is-active foo bar | grep '^active$' || systemctl poweroff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment