List all running services
sv status /var/service/*
Basic usage
sv up <services>
sv down <services>
sv restart <services>
sv status <services>
Enable
ln -s /etc/sv/<service> /var/service/
Disable
rm -rf /var/service/<service>
User service
https://github.com/Duncaen/dotfiles
On void the best way to create a per user service is to create a system-level service that runs runsvdir as your user, in order to start and monitor the services in a personal services directory.
Create a local service directory: ~/.service
Create a service called: /etc/sv/runsvdir-<username> with:
#!/bin/sh
export USER="<username>"
export HOME="/home/<username>"
groups="$(id -Gn "$USER" | tr ' ' ':')"
svdir="$HOME/.service"
exec chpst -u "$USER:$groups" runsvdir "$svdir"
Running some user services:
$ sv status ~/.service/*
run: /home/kota/.service/gpg-agent: (pid 901) 33102s
run: /home/kota/.service/ssh-agent: (pid 900) 33102s
$ SVDIR=~/.service sv restart gpg-agent
ok: run: gpg-agent: (pid 19818) 0s
XDG_RUNTIME_DIR
One of the tricky bits about these user services is that they run at the system
level. For many user services we want them to start after you've logged into
your window manaver. The way around this is to touch down inside any of these
such services causing them to be in the down state by default. Then, once
sway or i3 has started you can start up your services. However, they
will not have the same environment variables as your window manager, particuarly
they will not have XDG_RUNTIME_DIR.
Fortunately you don't need to write it to a file or anthing silly. If you're using elogind you can just fetch the variable like so:
export XDG_RUNTIME_DIR=$(loginctl --value --property=RuntimePath show-user $USER)
Logs
You can add logging to your user services in one of two ways. The easiest is to
just add it at the "global level" by creating a sub-directory:
/etc/sv/runsvdir-<username>/log and then creating a run file in it like so:
#!/bin/sh
exec vlogger
The other way would be doing the same thing, but instead of putting that log subdir in your runsvdir service you would put it in each of your user services that need logging.