RUNIT - created first service directory, "sv start testrun" does not work

I'm pretty new to runit. I installed it on a Ubuntu host.

What I did:

1) created a dir testrun in /etc/sv

2) created a script run in /etc/sv/testrun/run, the script content:

#! /bin/bash
exec /root/FP/annotate-output python /root/FP/test.py | logger -t svtest

3) If I call directly /etc/sv/testrun/run it executes successfully

4) I run sv start testrun (or sv run testrun, sv restart testrun), all of them end up with the same error msg:

fail: sv: unable to change to service directory: file does not exist

Any ideas what am I doing wrong? I'm new to runit and base all my actions on the information found here: http://smarden.org/runit/


Solution 1:

Your service isn't set up correctly. The reason it worked is that you invoked it directly from the service definition and not from the actual service control.

When runit's service management starts, it expects a /service directory to exist, although some installs (like Debian Jessie) currently have it at /etc/service for reasons unknown. The error message comes from this missing directory, which it is trying to change to, hence the unable to change service directory message. Do the following as root:

mkdir -p /etc/service
cd /
ln -s /etc/service
cd /service
ln -s /etc/sv/testrun

This will:

  • create the service directory if it doesn't exist
  • place a symlink in the root so that runsvdir will be able to change to /service as its working directory
  • creates a link to your testrun service, assuming you have it defined at /etc/sv/testrun

runsvdir will then be able to change its directory into /service, find your symlink for testrun, and then launch it. You can verify this by using ps fax or pstree -A to see the process tree; there should be a runsv with your command attached to it. Note: sometimes it may take a second or two for the runsvdir process to get its head oriented, so if you look right away and don't see it in the process tree, wait 2-3 seconds and try again, and it should show up. This appears to only happen when it starts up.