From a7ea5efb75bd21fa1e7c22c841f6eb13baf41b5e Mon Sep 17 00:00:00 2001 From: Brent Date: Sun, 31 Aug 2025 19:04:30 -0400 Subject: [PATCH] Added sysvinit script that depends only on LSB-guaranteed utility functions, for distributions without Debian's start-stop-daemon utility. --- ...-next-daemon.in => ckb-next-daemon-deb.in} | 0 linux/sysvinit/ckb-next-daemon-lsb.in | 81 +++++++++++++++++++ src/daemon/CMakeLists.txt | 18 ++++- 3 files changed, 95 insertions(+), 4 deletions(-) rename linux/sysvinit/{ckb-next-daemon.in => ckb-next-daemon-deb.in} (100%) create mode 100755 linux/sysvinit/ckb-next-daemon-lsb.in diff --git a/linux/sysvinit/ckb-next-daemon.in b/linux/sysvinit/ckb-next-daemon-deb.in similarity index 100% rename from linux/sysvinit/ckb-next-daemon.in rename to linux/sysvinit/ckb-next-daemon-deb.in diff --git a/linux/sysvinit/ckb-next-daemon-lsb.in b/linux/sysvinit/ckb-next-daemon-lsb.in new file mode 100755 index 00000000..8786c345 --- /dev/null +++ b/linux/sysvinit/ckb-next-daemon-lsb.in @@ -0,0 +1,81 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: ckb-next +# Required-Start: $local_fs $remote_fs +# Required-Stop: $local_fs $remote_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Start and stop the corsair keyboards and mice daemon +### END INIT INFO +# +# Original copyright 2017-2018 ckb-next Development Team +# Modified for LSB compliance 2025 by Brent Spillner +# Distributed under the terms of the GNU General Public License v2 + +NAME="ckb-next-daemon" +DESC="Corsair keyboards and mice" +PIDFILE="/dev/input/ckb0/pid" # DO NOT CHANGE +DAEMON="@CMAKE_INSTALL_PREFIX@/bin/ckb-next-daemon" + +# Exit if daemon not installed +[ -x "$DAEMON" ] || exit 0 + +if [ -f /lib/lsb/init-functions ]; then + . /lib/lsb/init-functions +elif [ -f /etc/init.d/functions ]; then + # Alternate path used on some non-fully-LSB-compliant distributions + . /etc/init.d/functions +else + echo "WARNING: path to LSB-style daemon control functions could not be determined; $NAME probably won't start as expected" +fi + +do_start () { + if start_daemon -p $PIDFILE $DAEMON ; then + log_success_msg "Started $DESC $NAME" + else + log_failure_msg "Could not start $DESC $NAME" + fi +} + +do_stop () { + for signal in -QUIT -TERM -KILL ; do + if killproc -p $PIDFILE $DAEMON $signal ; then + log_success_msg "Stopped $DESC $NAME with signal $signal" + return 0 + else + log_warning_msg "$DESC $NAME did not respond to signal $signal" + sleep 1 + fi + done + log_failure_msg "Unable to stop $DESC $NAME; are you running as root?" +} + +case "$1" in + start) + do_start + ;; + stop) + do_stop + ;; + restart) + log_success_msg "Restarting $DESC" "$NAME" + do_stop + do_start + ;; + reload) + if killproc -p $PIDFILE $DAEMON -USR1 ; then + log_success_msg "Reloaded $DESC $NAME" + else + log_failure_msg "Unable to reload $DESC $NAME" + fi + ;; + status) + pidofproc -p $PIDFILE $DAEMON > /dev/null + echo "$DAEMON is" $(test $? = 0 && echo "" || echo "not") running + ;; + *) + echo "Usage: $0 {start|stop|restart|reload|status}" >&2 + exit 1 +esac + +exit 0 diff --git a/src/daemon/CMakeLists.txt b/src/daemon/CMakeLists.txt index 92f5de9d..5696bb73 100644 --- a/src/daemon/CMakeLists.txt +++ b/src/daemon/CMakeLists.txt @@ -411,10 +411,20 @@ elseif (LINUX) # Generate and import service message(STATUS "Generating and importing ckb-next-daemon (${CKB_NEXT_INIT_SYSTEM})") - configure_file( - "${ckb-next_SOURCE_DIR}/linux/sysvinit/ckb-next-daemon.in" - "${CMAKE_CURRENT_BINARY_DIR}/service/ckb-next-daemon.sh" - @ONLY) + if (EXISTS "/sbin/start-stop-daemon" OR EXISTS "/usr/sbin/start-stop-daemon" OR EXISTS "/usr/local/sbin/start-stop-daemon" OR + EXISTS "/bin/start-stop-daemon" OR EXISTS "/usr/bin/start-stop-daemon" OR EXISTS "/usr/local/bin/start-stop-daemon") + # Use the Debian-style daemon management utilities + configure_file( + "${ckb-next_SOURCE_DIR}/linux/sysvinit/ckb-next-daemon-deb.in" + "${CMAKE_CURRENT_BINARY_DIR}/service/ckb-next-daemon.sh" + @ONLY) + else () + # Use LSB-compliant daemon management utilities + configure_file( + "${ckb-next_SOURCE_DIR}/linux/sysvinit/ckb-next-daemon-lsb.in" + "${CMAKE_CURRENT_BINARY_DIR}/service/ckb-next-daemon.sh" + @ONLY) + endif () if (SAFE_INSTALL) if (EXISTS "/dev/input/ckb0/pid")