Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to have a custom "stop" script runit (runsv) to execute when having to stop/restart the process. Currently it simply kills the process, then runs the "finish" script. But in my case, my process spawns dynamically child processes, so instead of simple kill, I need a "killtree" to get rid of them. How do I do that?

I know it should be done through the control options of runit but from reading the docs its not really clear to me how the stop script should be named :(

share|improve this question
Your service (not the script but the program) sounds mis-behaved, it should reap/clean up after its own children. Just curious, what is it? – Avery Payne Aug 20 '14 at 19:02
up vote 10 down vote accepted

From the docs

For each control character c sent to the control pipe, runsv first checks if service/control/c exists and is executable. If so, it starts service/control/c and waits for it to terminate, before interpreting the command. If the program exits with return code 0, runsv refrains from sending the service the corresponding signal. The command o is always considered as command u. On command d first service/control/t is checked, and then service/control/d. On command x first service/control/t is checked, and then service/control/x. The control of the optional log service cannot be customized.

That means you need to create a service_name/control/X, X being an executable that will run when you send the related sv command to the service, like the d command (down). If your script exits with status 0 it will not try to down the service itself.

Basically you need an executable script on /etc/sv/<service>/control/d that will do whatever you want and kill the service, clean up pids and etc.

share|improve this answer
it's really interesting and simple the way runsv dir works. – nXqd Dec 19 '14 at 10:17

The simple answer is to name your cleanup script "service/finish". This script is executed when "service/run" exits.

There is also a "service/control/ctrl_char interface. It allows you to perform differing actions depending on which command you send to runsv.

share|improve this answer
service/finish runs after TERM CONT being send to running service. It is more like clearing service after kill. – MaximKostrikin May 8 '15 at 6:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.