From d6535affec0c94c13e59b5bcaa3e2a7533a74190 Mon Sep 17 00:00:00 2001 From: Kameron Kenny <1267885+kkenny@users.noreply.github.com> Date: Sun, 20 Oct 2024 20:58:14 -0400 Subject: [PATCH] systemd and setup scripts --- scripts/setup-client.sh | 24 ++++++++++++++++++++++++ scripts/setup-server.sh | 24 ++++++++++++++++++++++++ scripts/systemd/power-api.service | 13 +++++++++++++ scripts/systemd/power-client.service | 13 +++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 scripts/setup-client.sh create mode 100644 scripts/setup-server.sh create mode 100644 scripts/systemd/power-api.service create mode 100644 scripts/systemd/power-client.service diff --git a/scripts/setup-client.sh b/scripts/setup-client.sh new file mode 100644 index 0000000..751ce47 --- /dev/null +++ b/scripts/setup-client.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +INSTALL_DIR='/opt/power' + +[[ ! -d $INSTALL_DIR ]] && mkdir $INSTALL_DIR + +if [[ ! -d "${INSTALL_DIR}/.git" ]]; then + git clone https://git.thelinuxpro.net/Utilities/powerapi.git $INSTALL_DIR +else + cd $INSTALL_DIR && git pull +fi + +cp ${INSTALL_DIR}/scripts/systemd/power-client.service /etc/systemd/system/ + +if [[ -f '/etc/systemd/system/power-client.service' ]]; then + chmod +x /etc/systemd/system/power-client.service + systemctl daemon-reload + systemctl start power-client.service + systemctl enable power-client.service + systemctl status power-client.service +else + echo 'Service file missing. Something went wrong.' + exit 1 +fi diff --git a/scripts/setup-server.sh b/scripts/setup-server.sh new file mode 100644 index 0000000..7b2e372 --- /dev/null +++ b/scripts/setup-server.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +INSTALL_DIR='/opt/power' + +[[ ! -d $INSTALL_DIR ]] && mkdir $INSTALL_DIR + +if [[ ! -d "${INSTALL_DIR}/.git" ]]; then + git clone https://git.thelinuxpro.net/Utilities/powerapi.git $INSTALL_DIR +else + cd $INSTALL_DIR && git pull +fi + +cp ${INSTALL_DIR}/scripts/systemd/power-api.service /etc/systemd/system/ + +if [[ -f '/etc/systemd/system/power-api.service' ]]; then + chmod +x /etc/systemd/system/power-api.service + systemctl daemon-reload + systemctl start power-api.service + systemctl enable power-api.service + systemctl status power-api.service +else + echo 'Service file missing. Something went wrong.' + exit 1 +fi diff --git a/scripts/systemd/power-api.service b/scripts/systemd/power-api.service new file mode 100644 index 0000000..dca05cc --- /dev/null +++ b/scripts/systemd/power-api.service @@ -0,0 +1,13 @@ +[Unit] +Description=Power API Service +After=network.target + +[Service] +ExecStart=/usr/bin/python3 /opt/power/api.py +WorkingDirectory=/opt/power/ +StandardOutput=journal +StandardError=journal +Restart=always + +[Install] +WantedBy=multi-user.target diff --git a/scripts/systemd/power-client.service b/scripts/systemd/power-client.service new file mode 100644 index 0000000..6730ead --- /dev/null +++ b/scripts/systemd/power-client.service @@ -0,0 +1,13 @@ +[Unit] +Description=Power Client Service +After=network.target + +[Service] +ExecStart=/usr/bin/python3 /opt/power/power_client.py +WorkingDirectory=/opt/power/ +StandardOutput=journal +StandardError=journal +Restart=always + +[Install] +WantedBy=multi-user.target