blob: 33a46b93c28542afc7151dcb96a347bae2209d46 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#!/bin/sh
# This file is a part of RSPlayer
# Licensed under the GPL-3.0 License
# Copyright (C) 2026 Salmonik @ salmonik@tuta.io
# https://codeberg.org/salmonik/RSPlayer
#
# FreeBSD rc.d service for RSPlayer.
#
# Add the following to /etc/rc.conf to enable the service:
#
# rsplayer_enable="YES"
# rsplayer_user="salmon" # user to run the daemon as (NOT root)
# rsplayer_group="wheel" # group of that user
#
# rsplayer_user must be a regular user: the daemon socket and PID file live
# in rsplayer_runtime_dir (default /tmp/rsplayer, matching the daemon's
# fallback when XDG_RUNTIME_DIR is unset) and the `rsp` CLI connects to that
# socket, so the daemon and the CLI must run as the same user.
#
# Optional: rsplayer_runtime_dir="/tmp/rsplayer"
# PROVIDE: rsplayer
# REQUIRE: LOGIN dbus
# KEYWORD: shutdown
. /etc/rc.subr
name="rsplayer"
rcvar=rsplayer_enable
load_rc_config $name
: ${rsplayer_user:="root"}
: ${rsplayer_group:="wheel"}
: ${rsplayer_runtime_dir:="/tmp/rsplayer"}
command="/usr/local/bin/rsp"
procname="${command}"
pidfile="${rsplayer_runtime_dir}/rsplayer.pid"
start_cmd="rsplayer_start"
stop_cmd="rsplayer_stop"
rsplayer_start()
{
if [ -s "${pidfile}" ] && kill -0 "$(cat "${pidfile}")" 2>/dev/null; then
echo "rsplayer is already running (PID $(cat "${pidfile}"))."
return 0
fi
if [ "${rsplayer_user}" = "root" ]; then
echo "WARNING: rsplayer_user is \"root\"; the rsp CLI will not be able to"
echo " connect to the daemon socket. Set rsplayer_user in rc.conf."
fi
install -d -o "${rsplayer_user}" -g "${rsplayer_group}" -m 700 "${rsplayer_runtime_dir}"
echo "Starting rsplayer as ${rsplayer_user}."
/usr/sbin/daemon -u "${rsplayer_user}" -o "${rsplayer_runtime_dir}/rsplayer.log" \
"${command}" start-daemon
}
rsplayer_stop()
{
echo "Stopping rsplayer."
if ! su -m "${rsplayer_user}" -c "${command} stop-daemon"; then
echo "rsplayer is not running; cleaning up stale files."
rm -f "${pidfile}" "${rsplayer_runtime_dir}/daemon.sock"
fi
}
run_rc_command "$1"
|