#!/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"