Skip to content

Instantly share code, notes, and snippets.

@SanariSan
Last active February 27, 2022 17:21
Show Gist options
  • Save SanariSan/8b15dbd2f0e7f570b6e2975a683b3710 to your computer and use it in GitHub Desktop.
Save SanariSan/8b15dbd2f0e7f570b6e2975a683b3710 to your computer and use it in GitHub Desktop.

Some info https://blog.thewatertower.org/2019/04/24/modifying-systemd-unit-files/

systemctl start mydaemon.service 
systemctl stop mydaemon.service 
systemctl enable mydaemon.service 
systemctl disable mydaemon.service 

sudo touch /etc/systemd/system/mydaemon.service
sudo nano /etc/systemd/system/mydaemon.service

Bare minimum


[Unit]
Description=My daemon

[Service]
ExecStart=/usr/bin/mydaemon
Restart=on-failure

[Install]
WantedBy=multi-user.target 

Detailed


[Unit]
Description=ServiceName
After=syslog.target
After=network.target
After=nginx.service
After=mysql.service
Requires=mysql.service
Wants=redis.service

[Service]
Type=forking # OR simple(default)
PIDFile=/work/www/myunit/shared/tmp/pids/service.pid
WorkingDirectory=/work/www/myunit/current

User=name
Group=name

Environment=RACK_ENV=production

#don't stop service when ran out of memory
OOMScoreAdjust=-1000

ExecStart=/usr/local/bin/bundle exec service -C /work/www/myunit/shared/config/service.rb --daemon
ExecStop=/usr/local/bin/bundle exec service -S /work/www/myunit/shared/tmp/pids/service.state stop
ExecReload=/usr/local/bin/bundle exec service -S /work/www/myunit/shared/tmp/pids/service.state restart
TimeoutSec=300
Restart=on-failure

[Install]
WantedBy=multi-user.target 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment