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