commit 818ce0fd322e5745cc1674c1acc5e0a8ea60be80 Author: Alexandre CATTEAU Date: Fri Aug 19 13:11:27 2022 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..99a3140 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +variables.conf +.disabled diff --git a/README.md b/README.md new file mode 100644 index 0000000..2384a91 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# WebSSH service unit + +This is just a Systemd service unit for [WebSSH](https://github.com/huashengdun/webssh) web app. + +### Files +* `webssh.service` is a Systemd units template for WebSSH. +#### Installation +* `install.sh` script copies the Systemd template to its destination, with the correct path (set in `variables.conf`). + +### TODO +* RAS diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..40e85d7 --- /dev/null +++ b/install.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +run_directory=$(dirname "$0") +user=$(whoami) + +source "$run_directory/variables.conf" + +if [ -f $run_directory/.disabled ]; then + echo "Installation is disabled. Exiting..." + exit 0 +fi + +echo "Copying WebSSH unit to system directory..." +if [[ $user != 'root' ]]; then + sudo cp webssh.service /etc/systemd/system/ + sudo sed -i -e "s:PH_WEBSSH_PATH:$webssh_part:g" /etc/systemd/system/webssh.service + sudo sed -i -e "s:PH_ADDR:$address:g" /etc/systemd/system/webssh.service + sudo sed -i -e "s:PH_PORT:$port:g" /etc/systemd/system/webssh.service +else + cp webssh.service /etc/systemd/system/ + sed -i -e "s:PH_WEBSSH_PATH:$webssh_part:g" /etc/systemd/system/webssh.service + sed -i -e "s:PH_ADDR:$address:g" /etc/systemd/system/webssh.service + sed -i -e "s:PH_PORT:$port:g" /etc/systemd/system/webssh.service +fi +echo "Reloading Systemd..." +if [[ $user != 'root' ]]; then + sudo systemctl daemon-reload +else + systemctl daemon-reload +fi + +echo "Finished install. Exiting..." +exit 0 diff --git a/variables.conf.template b/variables.conf.template new file mode 100644 index 0000000..7e07162 --- /dev/null +++ b/variables.conf.template @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +# Copy this file as variables.conf, with the correct values + +webssh_path= +address=127.0.0.1 +port=8000 diff --git a/webssh.service b/webssh.service new file mode 100644 index 0000000..03308d0 --- /dev/null +++ b/webssh.service @@ -0,0 +1,10 @@ +[Unit] +Description=Run Python webssh web app +After=network.target + +[Service] +User=www-data +ExecStart=/usr/bin/python3 PH_WEBSSH_PATH --address='PH_ADDR' --port=PH_PORT + +[Install] +WantedBy=default.target