Ported to golang, only ticktick remaining
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
[program:home_automation_backend]
|
||||
environment=PYTHONUNBUFFERED=1
|
||||
command=
|
||||
directory=
|
||||
user=
|
||||
group=
|
||||
environment=
|
||||
autostart=true
|
||||
autorestart=true
|
||||
startsecs=1
|
||||
startsecs=15
|
||||
startretries=100
|
||||
stopwaitsecs=30
|
||||
redirect_stderr=true
|
||||
|
||||
@@ -37,33 +37,28 @@ esac
|
||||
|
||||
TARGET_DIR="$HOME/.local/home-automation-backend"
|
||||
SUPERVISOR_CFG_NAME="home_automation_backend"
|
||||
APP_NAME="home-automation-backend"
|
||||
SUPERVISOR_CFG="$SUPERVISOR_CFG_NAME.conf"
|
||||
BASEDIR=$(dirname "$0")
|
||||
BASEDIR=$(dirname "$(realpath "$0")")
|
||||
|
||||
# Install or uninstall based on arguments
|
||||
install_backend() {
|
||||
# Installation code here
|
||||
echo "Installing..."
|
||||
|
||||
sudo apt update
|
||||
sudo apt install python3 python3-venv supervisor
|
||||
|
||||
sudo supervisorctl stop $SUPERVISOR_CFG_NAME
|
||||
|
||||
mkdir -p $TARGET_DIR
|
||||
cd $BASEDIR"/../src/" && go build -o $TARGET_DIR/$APP_NAME
|
||||
|
||||
rm -rf `find $BASEDIR/../src -type d -name __pycache__`
|
||||
cp -r $BASEDIR/../src $BASEDIR/../requirements.txt $TARGET_DIR
|
||||
python3 -m venv "$TARGET_DIR/venv"
|
||||
|
||||
$TARGET_DIR/venv/bin/pip install -r $TARGET_DIR/requirements.txt
|
||||
|
||||
cp $BASEDIR/"$SUPERVISOR_CFG_NAME"_template.conf $BASEDIR/$SUPERVISOR_CFG
|
||||
|
||||
sed -i "s+command=+command=$TARGET_DIR/venv/bin/fastapi run $TARGET_DIR/src/main.py --port 8881+g" $BASEDIR/$SUPERVISOR_CFG
|
||||
sed -i "s+command=+command=$TARGET_DIR/$APP_NAME serve+g" $BASEDIR/$SUPERVISOR_CFG
|
||||
sed -i "s+directory=+directory=$TARGET_DIR+g" $BASEDIR/$SUPERVISOR_CFG
|
||||
sed -i "s+user=+user=$USER+g" $BASEDIR/$SUPERVISOR_CFG
|
||||
sed -i "s+group=+group=$USER+g" $BASEDIR/$SUPERVISOR_CFG
|
||||
sed -i "s+environment=+environment=HOME=\"$HOME\"+g" $BASEDIR/$SUPERVISOR_CFG
|
||||
|
||||
sudo mv $BASEDIR/$SUPERVISOR_CFG /etc/supervisor/conf.d/$SUPERVISOR_CFG
|
||||
|
||||
@@ -83,9 +78,10 @@ uninstall_backend() {
|
||||
|
||||
sudo rm /etc/supervisor/conf.d/$SUPERVISOR_CFG
|
||||
|
||||
rm -rf $TARGET_DIR/src $TARGET_DIR/requirements.txt $TARGET_DIR/venv
|
||||
rm -rf $TARGET_DIR/
|
||||
|
||||
echo "Uninstallation complete."
|
||||
echo "Config files and db is stored in $HOME/.config/home-automation"
|
||||
}
|
||||
update_backend() {
|
||||
uninstall_backend
|
||||
|
||||
Reference in New Issue
Block a user