#! /bin/sh
### BEGIN INIT INFO
# Provides: noip
# Required-Start: $syslog
# Required-Stop: $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: noip server
# Description:
### END INIT INFO
 
case "$1" in
    start)
        # echo "update RTC Clock"
        # Update clock from RTC Module
        python3 /home/pi/rtc/USB-RTC-Key/UPDATE_RaspberryPi.py
    
        echo "retroprinter will be started"
        # Start Program
        /usr/bin/taskset -c 1 nice /home/pi/temp/sdl/escparser/retroprinter 4 1>>/home/pi/data/retroprinter.log 2>>/home/pi/data/retroprinter-error.log&
        /usr/bin/taskset -c 1 /home/pi/printpcl.sh
        /usr/bin/taskset -c 1 /home/pi/printprintronix.sh
        ;;
    restart)
        echo "retroprinter will be restarted"
        # Stop Program
        killall -s SIGKILL retroprinter
        killall -s SIGKILL inotifywait
        pkill -9 -f "convert-*"
        # Start Program
        /usr/bin/taskset -c 1 nice /home/pi/temp/sdl/escparser/retroprinter 4 1>>/home/pi/data/retroprinter.log 2>>/home/pi/data/retroprinter-error.log&
        /usr/bin/taskset -c 1 /home/pi/printpcl.sh
        /usr/bin/taskset -c 1 /home/pi/printprintronix.sh
        ;;        
    stop)
        echo "retroprinter will be killed"
        # End Program
        killall -s SIGKILL retroprinter
        killall -s SIGKILL inotifywait
        pkill -9 -f "convert-*"
        ;;
    *)
        echo "Usage: /etc/init.d/retroprinter {start|stop|restart}"
        exit 1
        ;;
esac
 
exit 0
