Added sysvinit script that depends only on LSB-guaranteed utility functions, for distributions without Debian's start-stop-daemon utility.

This commit is contained in:
Brent
2025-08-31 19:04:30 -04:00
parent 02c2f2df0b
commit a7ea5efb75
3 changed files with 95 additions and 4 deletions
+81
View File
@@ -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 <[email protected]>
# Modified for LSB compliance 2025 by Brent Spillner <s p i l l n e r @ a c m . o r g>
# 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
+11 -1
View File
@@ -411,10 +411,20 @@ elseif (LINUX)
# Generate and import service
message(STATUS "Generating and importing ckb-next-daemon (${CKB_NEXT_INIT_SYSTEM})")
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.in"
"${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")