diff --git a/1og/service.sh b/1og/service.sh index 0829953..dbb2c05 100644 --- a/1og/service.sh +++ b/1og/service.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash # Generate systemd service file +set -e + FILE=/etc/systemd/system/buttond.service button=$(realpath button.py) @@ -10,20 +12,33 @@ if [[ ! -f $button ]]; then fi vpython=$(realpath venv/)/bin/python -if [[ ! -e $vpython ]]; then +if [[ ! -x $vpython ]]; then echo venv not found exit 1 fi cat > "$FILE" << EOF [Unit] -Description = buttonctl +Description=Button Service 1. OG +StartLimitIntervalSec=60s +StartLimitBurst=10 [Service] -Type = simple -ExecStart = $vpython $button +Type=exec +ExecStart=$vpython -u $button +User=root +WorkingDirectory=$(dirname "$button") +Restart=on-failure +RestartSec=3s +NoNewPrivileges=yes +PrivateTmp=yes +ProtectSystem=full [Install] WantedBy=multi-user.target -Alias=buttond.service EOF + +service=$(basename "$FILE") +systemctl daemon-reload +systemctl enable --now "$service" +systemctl --no-pager status "$service" diff --git a/ug/button.py b/ug/button.py index 40d5f41..17b7c78 100644 --- a/ug/button.py +++ b/ug/button.py @@ -298,20 +298,20 @@ def main(): door_sense.switch_to_input(digitalio.Pull.UP) menu = StateMenu() - btn_locked = False + btn_locked = 0 try: while True: if not btn_oben.value: if not btn_locked: menu.button_pressed("oben") - btn_locked = True + btn_locked = 10 elif not btn_unten.value: if not btn_locked: menu.button_pressed("unten") - btn_locked = True - else: - btn_locked = False + btn_locked = 10 + elif btn_locked: + btn_locked -= 1 if door_sense.value != menu.doors["unten"].door_sense_state: menu.doors["unten"].door_sense_state = door_sense.value diff --git a/ug/service.sh b/ug/service.sh new file mode 100644 index 0000000..02b963e --- /dev/null +++ b/ug/service.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# Generate systemd service file + +set -e + +FILE=/etc/systemd/system/buttond.service + +button=$(realpath button.py) +if [[ ! -f $button ]]; then + echo button.py not found + exit 1 +fi + +vpython=$(realpath venv/)/bin/python +if [[ ! -x $vpython ]]; then + echo venv not found + exit 1 +fi + +cat > "$FILE" << EOF +[Unit] +Description=Button Service UG +StartLimitIntervalSec=60s +StartLimitBurst=10 + +[Service] +Type=exec +ExecStart=$vpython -u $button +User=root +WorkingDirectory=$(dirname "$button") +Restart=on-failure +RestartSec=3s +NoNewPrivileges=yes +PrivateTmp=yes +ProtectSystem=full + +[Install] +WantedBy=multi-user.target +EOF + +service=$(basename "$FILE") +systemctl daemon-reload +systemctl enable --now "$service" +systemctl --no-pager status "$service"