From 4e7a1178d98816e27788ff34a4b0210db4c1b53e Mon Sep 17 00:00:00 2001 From: Mike Cifelli <1836280-mike-cifelli@users.noreply.gitlab.com> Date: Wed, 16 Jun 2021 16:59:16 -0400 Subject: [PATCH] Initial commit --- README.md | 12 ++++++++++++ install | 34 ++++++++++++++++++++++++++++++++++ system-status.py | 1 + system-status.service | 13 +++++++++++++ 4 files changed, 60 insertions(+) create mode 100755 install create mode 100644 system-status.py create mode 100644 system-status.service diff --git a/README.md b/README.md index 0417d6f..7f3dac4 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,14 @@ # system-status +## Dependencies +``` +sudo raspi-config nonint do_spi 0 +sudo apt install python3-pip +sudo apt install python3-gpiozero +sudo pip3 install unicornhatmini +``` + +## Installation +``` +sudo ./install +``` diff --git a/install b/install new file mode 100755 index 0000000..85f26c9 --- /dev/null +++ b/install @@ -0,0 +1,34 @@ +#! /usr/bin/env python3 + +import os +import sys + +from string import Template +from subprocess import check_call + +EXEC = 'system-status.py' +SERVICE = 'system-status.service' +SYSTEM_DIR = '/etc/systemd/system' + +CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) +EXEC_PATH = os.path.join(CURRENT_DIR, EXEC) +SERVICE_TEMPLATE = os.path.join(CURRENT_DIR, SERVICE) +SERVICE_FILE = os.path.join(SYSTEM_DIR, SERVICE) +PYTHON = sys.executable +EXEC_START = f'{PYTHON} {EXEC}' + +with open(SERVICE_TEMPLATE) as f: + serviceTemplate = Template(f.read()) + +serviceFile = serviceTemplate.substitute( + workingDirectory=CURRENT_DIR, + execStart=EXEC_START +) + +with open(SERVICE_FILE, 'w') as f: + f.write(serviceFile) + +check_call(['systemctl', 'daemon-reload']) +check_call(['systemctl', 'enable', '--no-pager', SERVICE]) +check_call(['systemctl', 'restart', '--no-pager', SERVICE]) +check_call(['systemctl', 'status', '--no-pager', SERVICE]) diff --git a/system-status.py b/system-status.py new file mode 100644 index 0000000..50b17fa --- /dev/null +++ b/system-status.py @@ -0,0 +1 @@ +from unicornhatmini import UnicornHATMini diff --git a/system-status.service b/system-status.service new file mode 100644 index 0000000..05bf741 --- /dev/null +++ b/system-status.service @@ -0,0 +1,13 @@ +[Unit] +Description=System Status Service +After=multi.user.target + +[Service] +Type=simple +WorkingDirectory=$workingDirectory +ExecStart=$execStart +Restart=on-failure +SyslogIdentifier=system-status + +[Install] +WantedBy=multi-user.target