From da4147a8ca2ed92556eb56061a63e0cccb1984ce Mon Sep 17 00:00:00 2001 From: salmon Date: Sun, 9 Aug 2026 23:28:12 +0200 Subject: Add FreeBSD rc.d service, install completions only for installed shells --- rsplayer.rc | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 rsplayer.rc (limited to 'rsplayer.rc') diff --git a/rsplayer.rc b/rsplayer.rc new file mode 100755 index 0000000..33a46b9 --- /dev/null +++ b/rsplayer.rc @@ -0,0 +1,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" -- cgit v1.2.3