service installation scripts

This commit is contained in:
bvn13 2024-10-10 00:22:26 +03:00
parent 1ff38457a1
commit 1b00624c8a
7 changed files with 102 additions and 3 deletions

15
git-pusher.service Normal file
View File

@ -0,0 +1,15 @@
[Unit]
Description=Logs-Preparer for <SERVICE>
After=network.target
[Service]
Type=simple
WorkingDirectory=<DIR>
ExecStart=poetry run git-pusher -w <WATCH_DIR>
CPUSchedulingPolicy=idle
IOSchedulingClass=3
Restart=always
RestartSec=3
[Install]
WantedBy=default.target

76
install.sh Executable file
View File

@ -0,0 +1,76 @@
#!/bin/bash
HELP=$(cat <<'EOF'
Missing required args:
-i - ID
-w - Watching path
EOF
)
POETRY=$(which poetry)
if [ -z $POETRY ]; then
echo "You need Poetry to be installed"
exit 1
fi
while getopts ":i:w:" opt; do
case $opt in
i) ID="$OPTARG"
;;
w) WATCH_DIR="$OPTARG"
;;
\?) echo "Invalid option -$OPTARG" >&2
exit 1
;;
esac
case $OPTARG in
-*) echo "Option $opt needs a valid argument"
exit 1
;;
esac
done
if [ -z $WATCH_DIR ]; then
echo "$HELP"
exit -1
fi
printf "WATCH_DIR = %s\n" "$WATCH_DIR"
FNAME="git-pusher-$ID.service"
SERVICEFILE="$HOME/.config/systemd/user/$FNAME"
echo "FNAME = $FNAME"
echo "SERVICEFILE = $SERVICEFILE"
if [ -f $SERVICEFILE ]; then
echo "Disabling current service..."
systemctl --user stop $FNAME
systemctl --user disable $FNAME
systemctl --user daemon-reload
sudo rm $SERVICEFILE
fi
echo "Preparing"
poetry lock
poetry install
echo "Creating service file..."
cat git-pusher.service | sed 's?<DIR>?'`pwd`'?' | sed 's?<WATCH_DIR>?'$WATCH_DIR'?' | sudo tee -a "$SERVICEFILE" > /dev/null
echo "Reloading daemons..."
systemctl --user daemon-reload
echo "Enabling daemon for user..."
systemctl --user enable $FNAME
echo "Starting daemon for user..."
systemctl --user start $FNAME

View File

@ -4,11 +4,16 @@ version = "0.1.0"
description = "" description = ""
authors = ["bvn13 <from.github@bvn13.me>"] authors = ["bvn13 <from.github@bvn13.me>"]
readme = "README.md" readme = "README.md"
packages = [
{ include = "src" }
]
[tool.poetry.dependencies] [tool.poetry.dependencies]
python = "^3.12" python = "^3.12"
scheduler = "^0.8.7" scheduler = "^0.8.7"
[tool.poetry.scripts]
git-pusher = "src.main:start"
[build-system] [build-system]
requires = ["poetry-core"] requires = ["poetry-core"]

0
src/__init__.py Normal file
View File

View File

@ -1,7 +1,7 @@
import argparse import argparse
import subprocess import subprocess
from app.logger import logger as l from src.logger import logger as l
import datetime as dt import datetime as dt
import subprocess as proc import subprocess as proc
from scheduler import Scheduler from scheduler import Scheduler
@ -12,14 +12,17 @@ delta = dt.timedelta(hours=3)
tz_msk = dt.timezone(offset=delta, name="MSK") tz_msk = dt.timezone(offset=delta, name="MSK")
logger = l.getChild(__name__) logger = l.getChild(__name__)
logger.warning("Starting") logger.info("Starting")
parser = argparse.ArgumentParser(__name__) parser = argparse.ArgumentParser(__name__)
parser.add_argument("-w", "--watch", help="Directory to watch") parser.add_argument("-w", "--watch", required=True, help="Directory to watch")
args = parser.parse_args() args = parser.parse_args()
directory = args.watch directory = args.watch
if directory is None:
exit(-1)
logger.info(f"Directory to watch: {directory}") logger.info(f"Directory to watch: {directory}")