Open Will-wastelander opened 2 years ago
Example service file of working service. klipper_mcu
`#!/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin DESC="klipper_mcu startup" NAME="klipper_mcu" KLIPPER_HOST_MCU=/usr/local/bin/klipper_mcu KLIPPER_HOST_ARGS="-r" PIDFILE=/var/run/klipper_mcu.pid
. /lib/lsb/init-functions
mcu_host_stop() {
# put the GPIO pins in a safe state.
if [ -c /tmp/klipper_host_mcu ]; then
log_daemon_msg "Attempting to shutdown host mcu..."
set -e
( echo "FORCE_SHUTDOWN" > /tmp/klipper_host_mcu ) 2> /dev/null || ( log_action_msg "Firmware busy! Please shutdown Klipper and then retry." && exit 1 )
sleep 1
( echo "FORCE_SHUTDOWN" > /tmp/klipper_host_mcu ) 2> /dev/null || ( log_action_msg "Firmware busy! Please shutdown Klipper and then retry." && exit 1 )
sleep 1
set +e
fi
log_daemon_msg "Stopping klipper host mcu" $NAME
killproc -p $PIDFILE $KLIPPER_HOST_MCU
}
mcu_host_start() { [ -x $KLIPPER_HOST_MCU ] || return
if [ -c /tmp/klipper_host_mcu ]; then
mcu_host_stop
fi
log_daemon_msg "Starting klipper MCU" $NAME
start-stop-daemon --start --quiet --exec $KLIPPER_HOST_MCU \
--background --pidfile $PIDFILE --make-pidfile \
-- $KLIPPER_HOST_ARGS
log_end_msg $?
}
case "$1" in start) mcu_host_start ;; stop) mcu_host_stop ;; restart) $0 stop $0 start ;; reload|force-reload) log_daemon_msg "Reloading configuration not supported" $NAME log_end_msg 1 ;; status) status_of_proc -p $PIDFILE $KLIPPER_HOST_MCU $NAME && exit 0 || exit $? ;; *) log_action_msg "Usage: /etc/init.d/klipper_mcu {start|stop|status|restart|reload|force-reload}" exit 2 ;; esac exit 0`
Sorry for the late reply. Were you able to get this working?
The only thing I can see in the log is the Exec format error
. Is everything in the ExecStart line correct?
When attempting to restart the service, I get the following errors. When I run the
klipper_ledstrip.py
command, the LED strip response as expected.`pi@sv01-mainsailos:~/Klipper-WS281x_LED_Status $ sudo /etc/init.d/ledstrip status /etc/init.d/ledstrip: 1: /etc/init.d/ledstrip: [Unit]: not found /etc/init.d/ledstrip: 2: /etc/init.d/ledstrip: Python: not found /etc/init.d/ledstrip: 5: /etc/init.d/ledstrip: [Service]: not found /etc/init.d/ledstrip: 15: /etc/init.d/ledstrip: [Install]: not found pi@sv01-mainsailos:~/Klipper-WS281x_LED_Status $ sudo service ledstrip status ● ledstrip.service Loaded: loaded (/etc/init.d/ledstrip; generated) Active: inactive (dead) Docs: man:systemd-sysv-generator(8) pi@sv01-mainsailos:~/Klipper-WS281x_LED_Status $ sudo service ledstrip stop pi@sv01-mainsailos:~/Klipper-WS281x_LED_Status $ sudo service ledstrip start Job for ledstrip.service failed because the control process exited with error code. See "systemctl status ledstrip.service" and "journalctl -xe" for details. pi@sv01-mainsailos:~/Klipper-WS281x_LED_Status $ systemctl status ledstrip.service ● ledstrip.service Loaded: loaded (/etc/init.d/ledstrip; generated) Active: failed (Result: exit-code) since Sun 2022-08-28 11:30:40 PDT; 7s ago Docs: man:systemd-sysv-generator(8) Process: 28112 ExecStart=/etc/init.d/ledstrip start (code=exited, status=203/EXEC)
Aug 28 11:30:40 sv01-mainsailos systemd[1]: Starting ledstrip.service... Aug 28 11:30:40 sv01-mainsailos systemd[28112]: ledstrip.service: Failed to execute command: Exec format error Aug 28 11:30:40 sv01-mainsailos systemd[28112]: ledstrip.service: Failed at step EXEC spawning /etc/init.d/ledstrip: Exec format error Aug 28 11:30:40 sv01-mainsailos systemd[1]: ledstrip.service: Control process exited, code=exited, status=203/EXEC Aug 28 11:30:40 sv01-mainsailos systemd[1]: ledstrip.service: Failed with result 'exit-code'. Aug 28 11:30:40 sv01-mainsailos systemd[1]: Failed to start ledstrip.service.
-- Subject: A start job for unit ledstrip.service has begun execution -- Defined-By: systemd -- Support: https://www.debian.org/support
-- A start job for unit ledstrip.service has begun execution.
-- The job identifier is 2008. Aug 28 11:30:40 sv01-mainsailos systemd[28112]: ledstrip.service: Failed to execute command: Exec format error Aug 28 11:30:40 sv01-mainsailos systemd[28112]: ledstrip.service: Failed at step EXEC spawning /etc/init.d/ledstrip: Exec format error -- Subject: Process /etc/init.d/ledstrip could not be executed -- Defined-By: systemd -- Support: https://www.debian.org/support
-- The process /etc/init.d/ledstrip could not be executed and failed.
-- The error number returned by this process is ERRNO. Aug 28 11:30:40 sv01-mainsailos systemd[1]: ledstrip.service: Control process exited, code=exited, status=203/EXEC -- Subject: Unit process exited -- Defined-By: systemd -- Support: https://www.debian.org/support
-- An ExecStart= process belonging to unit ledstrip.service has exited.
-- The process' exit code is 'exited' and its exit status is 203. Aug 28 11:30:40 sv01-mainsailos systemd[1]: ledstrip.service: Failed with result 'exit-code'. -- Subject: Unit failed -- Defined-By: systemd -- Support: https://www.debian.org/support
-- The unit ledstrip.service has entered the 'failed' state with result 'exit-code'. Aug 28 11:30:40 sv01-mainsailos systemd[1]: Failed to start ledstrip.service. -- Subject: A start job for unit ledstrip.service has failed -- Defined-By: systemd -- Support: https://www.debian.org/support
-- A start job for unit ledstrip.service has finished with a failure.
-- The job identifier is 2008 and the job result is failed. `
-- ledstrip.service -- `cat /etc/init.d/ledstrip [Unit] Description=Simplified Python Klipper LED Strip Service After=syslog.target
[Service] Type=simple User=pi Group=pi WorkingDirectory=/home/pi/Klipper-WS281x_LED_Status/ ExecStart=/home/pi/Klipper-WS281x_LED_Status/klipper_ledstrip.py StandardOutput=syslog StandardError=syslog KillSignal=SIGINT
[Install] WantedBy=multi-user.target `