diff --git a/.gitignore b/.gitignore index a60a986..38380e2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,9 @@ /__pycache__ /cards/* /words/* +/log/* !/cards/.placeholder !/words/.placeholder !/words/words.txt.example +!/log/.placeholder config.py diff --git a/log/.placeholder b/log/.placeholder new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/log/.placeholder diff --git a/scripts/init.d/pixit b/scripts/init.d/pixit new file mode 100755 index 0000000..c372b0d --- /dev/null +++ b/scripts/init.d/pixit @@ -0,0 +1,47 @@ +#!/bin/sh +# +### BEGIN INIT INFO +# Provides: pixit +# Required-Start: +# Required-Stop: +# Should-Start: +# Should-Stop: +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Pixit +# Description: External GPU fan control +### END INIT INFO + +. /lib/lsb/init-functions + +DAEMON=/usr/bin/sudo +NAME=pixit +DESC="Pixit" +PARAMS="-u gamer -g gamer /home/gamer/pixit/server.py daemon" + +start() { + log_daemon_msg "Starting $DESC" "$NAME" + start-stop-daemon --start --quiet --background --pidfile /var/run/$NAME.pid --make-pidfile --exec $DAEMON -- $PARAMS + log_end_msg $? +} + +stop() { + log_daemon_msg "Stopping $DESC" "$NAME" + start-stop-daemon --stop --oknodo --quiet --pidfile /var/run/$NAME.pid --remove-pidfile --retry 5 + log_end_msg $? +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + stop + start + ;; +esac + +exit 0 diff --git a/server.py b/server.py index b6283c7..238a494 100755 --- a/server.py +++ b/server.py @@ -1,10 +1,17 @@ #!/usr/bin/python3 +import os +os.chdir(os.path.dirname(os.path.abspath(__file__))) +import sys +if len(sys.argv) == 2 and sys.argv[1] == "daemon": + sys.stdout = open('log/server.log', 'a') + sys.stderr = sys.stdout + + import config import game import template -import os import json import threading import http.server