7

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/

1
  • Not worth an answer but I arrived here with the same error. I had changed the container image from mysql to mariadb and startup scripts were still trying to restart mysql, when the new binary was mariadb. Feb 12, 2021 at 0:48

2 Answers 2

6

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.

1
  • A side note: if you look at the stage 2 script in Debian Jessie (2014-08-20 as of this writing), you'll see that it invokes runsvdir with /service instead of /etc/service. If you don't like having the symlink for /service around in the root of the filesystem, simply change the stage 2 script to /etc/service and it will be "correct" on the next reboot. Aug 20, 2014 at 18:59
0

It seems that sv controls services that are started and monitored by runit (using runsv). As runit on my machine does not actually replace sysvinit, it does not run and does not monitor the /services/ which should contain symbolic links to /etc/sv/ directories.

Running runsv /etc/sv/testrun/ seems to do the expected runit behavior.

1
  • 3
    This is the wrong answer, but I don't downvote out of principle. Aug 20, 2014 at 18:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .