In my previous post, Using Void Linux As My Daily Driver, I wrote that I used vpm as a wrapper for the xbps-* commands to manage packages on Void Linux. I like how convenient the tool is and how it works (it knows it's a wrapper command and it doesn't try to hide that fact). It also makes the output very colorful, which I do like a lot. I know that's a bit of a simple reason, but I personally just like very colorful output (with the option to disable it of course).

Managing services on Void Linux is already fairly easy using the sv command; however, I felt a couple of things could be made simpler and that the output could be more obvious at a quick glance.

With that, vsv was born.

vsv is a bash script wrapper for the sv command that can be used to query and manage services via runit. It was made specifically for Void Linux but should theoretically work on any system using runit to manage services.

vsv was inspired by vpm. vsv is to sv what vpm is to the xbps-* commands. vsv is available under the MIT License on GitHub:

https://github.com/bahamas10/vsv

vsv can be called without any arguments to get process status (as seen in the screenshot above). This is equivalent to running vsv status.

Note: sudo or escalated privileges are required to determine service state because of the strict permissions on each service's supervise directory.

vsv scans the /var/service directory by default, which can be overridden by setting the $SVDIR environmental variable or passing in a -d <dir> argument. Any service that has been in a state for less than 5 seconds will be marked in red, making new or failing services easy to spot:

Services in a state for more than 5 seconds but less than 30 seconds will be marked in yellow:

A string can be passed as the first argument after status to filter for services that contain that string in their name. Also, -t can be supplied to status to print the process tree of the pid for that process:

Any command other than status will be passed directly to the sv command. Restarting a service is as easy as vsv restart <svc>:

To stop a service, vsv down <svc> can be used:

A full service tree can be generated with vsv -t. This command is equivalent to running vsv status -t:

vsv also first-classes the notion of "user services". I wrote about this in my blog post for Using Linux As My Daily Driver. Basically, I have a separate instance of runsvdir running as my user out of ~/runit/sv, and the vsv script is set up to look in that location when invoked with -u.

Note that -u is just a shortcut for -d ~/runit/sv - technically, any directory can be specified with that option:

All of the commands and options are supported when -u or -d <dir> is specified.

Installation

vsv is a standalone bash script that can be dumped anywhere in your $PATH to be used.

I personally install it with git (with ~/bin in my $PATH):

mkdir -p ~/bin ~/dev
cd ~/dev
git clone git://github.com/bahamas10/vsv.git
ln -s ~/dev/vsv/vsv ~/bin

Otherwise, you can use curl or wget to pull the script directly from GitHub:

mkdir -p ~/bin
cd ~/bin
wget https://raw.githubusercontent.com/bahamas10/vsv/master/vsv
# or
curl -O https://raw.githubusercontent.com/bahamas10/vsv/master/vsv

And then:

chmod +x ~/bin/vsv

Usage

Quick Examples:

  • vsv - show all services
  • vsv status - same as above
  • vsv stop <svc> - stop a service
  • vsv start <svc> - start a service
  • vsv restart <svc> - restart a service
  • vsv hup <svc> - refresh a service (SIGHUP)

Command Usage:

$ vsv -h
 __   _______   __
 \ \ / / __\ \ / /   Void Service Manager
  \ V /\__ \\ V /    Source: https://github.com/bahamas10/vsv
   \_/ |___/ \_/     MIT License

[vsv]    Manage and view runit services
[vsv]    Made specifically for Void Linux but should work anywhere
[vsv]    Author: Dave Eddy <dave@daveeddy.com> (bahamas10)

USAGE:
vsv [OPTIONS] [SUBCOMMAND] [<ARGS>]
vsv [-u] [-d <dir>] [-h] [-t] [SUBCOMMAND] [...]

OPTIONS:
-c <yes|no|auto>          Enable/disable color output, defaults to auto
-d <dir>                  Directory to look into, defaults to env SVDIR or /var/service if unset
-h                        Print this message and exit
-t                        Tree view, this is a shortcut for 'status -t'
-u                        User mode, this is a shortcut for '-d ~/runit/service'
-v                        Increase verbosity

ENV:
SVDIR                     The directory to use, passed to the 'sv' command, can
                          be overridden with '-d <dir>'

SUBCOMMANDS:
status [-t] [filter]      Default subcommand, show process status
                          '-t' enables tree mode (process tree)
                          'filter' is an optional string to match service names against

Any other subcommand gets passed directly to the 'sv' command, see sv(1) for the
full list of subcommands and information about what each does specifically.
Common subcommands:

start <service>           Start the service
stop <service>            Stop the service
restart <service>         Restart the service
reload <service>          Reload the service (send SIGHUP)

EXAMPLES:
vsv                       Show service status in /var/service
vsv status                Same as above
vsv -t                    Show service status + pstree output
vsv status -t             Same as above
vsv status tty            Show service status for any service that matches *ssh*
vsv check uuidd           Check the uuidd svc, wrapper for 'sv check uuidd'
vsv restart sshd          Restart sshd, wrapper for 'sv restart sshd'
vsv -u                    Show service status in ~/runit/service
vsv -u restart ssh-agent  Restart ssh-agent in ~/runit/service/ssh-agent