Hacker News new | past | comments | ask | show | jobs | submit login

/etc/systemd/system/foo.service:

  [Unit]
  Description=Foo
  
  [Service]
  ExecStart=/usr/sbin/foo-daemon
—— Start/stop:

  systemctl start foo
  systemctl stop foo
On boot:

  systemctl enable —now foo

Hopefully this helps you skip the red tape.




My foo-daemon needs some arguments and several steps to shutdown while saving its work. Like maybe kill -HUP, wait 10 seconds and then kill -9. Any suggestions that would be obvious to me without always having you for one-on-one consultation? Rare cases where saving work is not complete after 10 seconds are acceptable for my use case.


Sure, here's the doc this is taken from: https://www.freedesktop.org/software/systemd/man/systemd.ser...

You can find this doc by typing "systemd.service" into your favorite search engine.

The title I link to is the simple case example, which explains just below the content sample that it has pretty much the behavior you want:

  Since no ExecStop= was specified, systemd will send SIGTERM to all processes 
  started from this service, and after a timeout also SIGKILL. This behavior can 
  be modified, see systemd.kill(5) for details.
Per this, you can either implement SIGTERM rather than SIGHUP, or you can change the stop signal. It already has a generous shutdown timeout (on one of my systems where I have a similarly simple unit, it's defaulted to 1m30s). You can change the timeout by setting https://www.freedesktop.org/software/systemd/man/systemd.ser...

The docs are pretty good, and worth a scan.

Edit: I forgot about the arguments, you can just add them to the ExecStart= line (doc: https://www.freedesktop.org/software/systemd/man/systemd.ser...).


That's bread and butter work for systemd - exactly what it is designed to handle.


If your daemon needs kill -9 you fucked up but even then you can just set "stop timeout" and your demon will get the termination signal, and kill after that interval.

More crude option is putting all of the custom stop behaviour in ExecStop script




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: