aboutsummaryrefslogtreecommitdiffstats
path: root/rsplayer.rc
diff options
context:
space:
mode:
authorsalmon <salmonik@tuta.io>2026-08-09 23:53:47 +0200
committersalmon <salmonik@tuta.io>2026-08-09 23:53:47 +0200
commitce1b4011d409997b10ca205f459cedcb6b292bd7 (patch)
treebbfd1572f0d6d3a30478bbfb613a09df0022940b /rsplayer.rc
parentMake install.sh POSIX sh so it runs without bash (diff)
downloadrsplayer-ce1b4011d409997b10ca205f459cedcb6b292bd7.tar.gz
rsplayer-ce1b4011d409997b10ca205f459cedcb6b292bd7.zip
Make daemon socket/PID paths environment-independent; fix rc service HOME
Diffstat (limited to 'rsplayer.rc')
-rwxr-xr-xrsplayer.rc39
1 files changed, 26 insertions, 13 deletions
diff --git a/rsplayer.rc b/rsplayer.rc
index 33a46b9..706387b 100755
--- a/rsplayer.rc
+++ b/rsplayer.rc
@@ -14,11 +14,10 @@
14# rsplayer_group="wheel" # group of that user 14# rsplayer_group="wheel" # group of that user
15# 15#
16# rsplayer_user must be a regular user: the daemon socket and PID file live 16# rsplayer_user must be a regular user: the daemon socket and PID file live
17# in rsplayer_runtime_dir (default /tmp/rsplayer, matching the daemon's 17# in that user's XDG state directory (~/.local/state/rsplayer) and the `rsp`
18# fallback when XDG_RUNTIME_DIR is unset) and the `rsp` CLI connects to that 18# CLI connects to that socket, so the daemon and the CLI must run as the
19# socket, so the daemon and the CLI must run as the same user. 19# same user. This also means the socket path no longer depends on the
20# 20# environment (XDG_RUNTIME_DIR), so the service and manual runs agree.
21# Optional: rsplayer_runtime_dir="/tmp/rsplayer"
22 21
23# PROVIDE: rsplayer 22# PROVIDE: rsplayer
24# REQUIRE: LOGIN dbus 23# REQUIRE: LOGIN dbus
@@ -33,11 +32,21 @@ load_rc_config $name
33 32
34: ${rsplayer_user:="root"} 33: ${rsplayer_user:="root"}
35: ${rsplayer_group:="wheel"} 34: ${rsplayer_group:="wheel"}
36: ${rsplayer_runtime_dir:="/tmp/rsplayer"} 35
36# daemon(8) does not set HOME when dropping privileges, and rsp derives its
37# config and runtime paths from it, so resolve the user's home explicitly.
38rsplayer_home=$(pw usershow "${rsplayer_user}" 2>/dev/null | awk -F: '{print $9}')
39if [ -z "${rsplayer_home}" ]; then
40 echo "Cannot determine home directory for user '${rsplayer_user}'."
41 echo "Set rsplayer_user in /etc/rc.conf."
42 exit 1
43fi
37 44
38command="/usr/local/bin/rsp" 45command="/usr/local/bin/rsp"
39procname="${command}" 46procname="${command}"
40pidfile="${rsplayer_runtime_dir}/rsplayer.pid" 47state_dir="${rsplayer_home}/.local/state/rsplayer"
48pidfile="${state_dir}/rsplayer.pid"
49socket="${state_dir}/daemon.sock"
41 50
42start_cmd="rsplayer_start" 51start_cmd="rsplayer_start"
43stop_cmd="rsplayer_stop" 52stop_cmd="rsplayer_stop"
@@ -54,19 +63,23 @@ rsplayer_start()
54 echo " connect to the daemon socket. Set rsplayer_user in rc.conf." 63 echo " connect to the daemon socket. Set rsplayer_user in rc.conf."
55 fi 64 fi
56 65
57 install -d -o "${rsplayer_user}" -g "${rsplayer_group}" -m 700 "${rsplayer_runtime_dir}" 66 echo "Starting rsplayer as ${rsplayer_user} (HOME=${rsplayer_home})."
58 echo "Starting rsplayer as ${rsplayer_user}." 67 /usr/bin/env HOME="${rsplayer_home}" \
59 /usr/sbin/daemon -u "${rsplayer_user}" -o "${rsplayer_runtime_dir}/rsplayer.log" \ 68 /usr/sbin/daemon -u "${rsplayer_user}" -o "${state_dir}/rsplayer.log" \
60 "${command}" start-daemon 69 "${command}" start-daemon
61} 70}
62 71
63rsplayer_stop() 72rsplayer_stop()
64{ 73{
65 echo "Stopping rsplayer." 74 echo "Stopping rsplayer."
66 if ! su -m "${rsplayer_user}" -c "${command} stop-daemon"; then 75 if ! su -m "${rsplayer_user}" -c "env HOME='${rsplayer_home}' ${command} stop-daemon"; then
67 echo "rsplayer is not running; cleaning up stale files." 76 # stop-daemon could not reach the daemon (stale/missing PID file or
68 rm -f "${pidfile}" "${rsplayer_runtime_dir}/daemon.sock" 77 # socket, e.g. a daemon started under an older runtime dir): kill any
78 # leftover rsp start-daemon processes for this user.
79 echo "Graceful stop failed; killing leftover daemons."
80 pkill -u "${rsplayer_user}" -f "${command} start-daemon" 2>/dev/null || true
69 fi 81 fi
82 rm -f "${pidfile}" "${socket}"
70} 83}
71 84
72run_rc_command "$1" 85run_rc_command "$1"