Last active
July 19, 2020 15:55
-
-
Save yyny/c60b02dd629fc6ed9856c66595688f15 to your computer and use it in GitHub Desktop.
Managin a user-local pulseaudio daemon with runit in voidlinux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# /home/user/runit/service/pulseaudio/check | |
. $(dirname $0)/common.sh | |
exec $pulse --check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# /home/user/runit/service/pulseaudio/common.sh | |
PULSE_RUNTIME_PATH="/run/user/$(id -u)/pulse" | |
XDG_RUNTIME_DIR="/run/user/$(id -u)/" | |
# we need to specify the pulse runtime, or else pulse applications might think that pulseaudio isn't running | |
# we use a variable for this so we don't have to re-type it over and over | |
# this also allows for 'sv check' to work | |
# you can use `$pulse_env` to start other services that require pulseaudio. | |
# `XDG_RUNTIME_DIR` is required only for older versions of pulseaudio. | |
pulse_env="env PULSE_RUNTIME_PATH="$PULSE_RUNTIME_PATH" XDG_RUNTIME_DIR="$PULSE_RUNTIME_DIR | |
pulse=$pulse_env" pulseaudio" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# /home/user/runit/service/pulseaudio/finish | |
. $(dirname $0)/common.sh | |
exec $pulse --kill |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# /home/user/runit/service/pulseaudio/run | |
. $(dirname $0)/common.sh | |
# Wait for the user to log in before we try to start pulseaudio | |
while [ ! -d /run/user/$(id -u)/ ]; do | |
sleep 2 | |
done | |
$pulse -vvv --log-time=true --log-target=file:$HOME/.log/pulseaudio.log --use-pid-file=true --start | |
# or, without logs: | |
# $pulse --use-pid-file=true --start | |
exec tail --pid="$(cat $PULSE_RUNTIME_PATH/pid)" -f /dev/null # wait for pulseaudio to exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# /etc/sv/runsvdir-user/run | |
exec 2>&1 | |
exec su - user -c 'runsvdir -P /home/user/runit/service' 'log: ...........................................................................................................................................................................................................................................................................................................................................................................................................' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# 1. log in as your user | |
su - user | |
# 2. start runsvdir-user: | |
sudo sv up runsvdir-user | |
# 3. start pulseaudio: | |
SVDIR=~/runit/service sv up pulseaudio | |
# OR: | |
vsv -u up pulseaudio | |
# 4. check that pulseaudio is running: | |
SVDIR~/runit/service sv check pulseaudio && echo pulseaudio is running || echo pulseaudio not found | |
# OR: | |
vsv -u check pulseaudio && echo pulseaudio is running || echo pulseaudio not found | |
# 5. check the logs to see if everything is working correctly: | |
less ~/.log/pulseaudio.log | |
# 6. disable the logs or set up a log daemon once you're sure everything is working correctly | |
# 7. have fun! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Useful tip: You can set
SVDIR=~/runit/service
in~/.profile
to automatically control user-local services when you run thesv
command without privilege, since you can't access /var/services without root access anyway. The more user-friendlyvsv
(Void Service Manager) command also has the-u
flag that has the same effect.