sv status exit code for service masked by its log
garthk opened this issue · 1 comments
sv(8) says:
The sv program can be sym-linked to
/etc/init.d/
to provide an LSB init script interface. The service to be controlled then is specified by the base name of the "init script".
If sv is called with a base name other than
sv
: it exits 1 on timeout or trouble sending the command; if the command is status, it exits 3 if the service is down, and 4 if the status is unknown; it exits 2 on wrong usage, and 151 on error.
This isn't entirely true. If the service has a log
, the exit code instead reflects the status of the log. In src/sv.c:154-176 you'll see rc
updated if chdir("log")
and svstatus_get()
succeed, after which the if (lsb)
branch to the switch
will call done
reflecting the log's status.
This strikes me as a bug in the code, not the man page.
I can reproduce this:
❯ fd -t f . /etc/sv/issue-20 -X head
==> /etc/sv/issue-20/run <==
#!/bin/sh
echo 'Sleeping for 60 seconds.'
exec /usr/bin/sleep 60
==> /etc/sv/issue-20/log/run <==
#!/bin/sh
exec /usr/bin/false
❯ ls -l /etc/init.d/issue-20
lrwxrwxrwx 1 root root 11 Aug 5 18:09 /etc/init.d/issue-20 -> /usr/bin/sv
❯ sudo /etc/init.d/issue-20 status
run: issue-20: (pid 8220) 44s; down: log: 1s, normally up, want up
❯ echo $? # expecting 0
3
PR up momentarily.