diff --git a/helper/home_automation_backend_template.conf b/helper/home_automation_backend_template.conf index 30f926c..644c8a1 100644 --- a/helper/home_automation_backend_template.conf +++ b/helper/home_automation_backend_template.conf @@ -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 diff --git a/helper/install.sh b/helper/install.sh index a0595db..df0c559 100755 --- a/helper/install.sh +++ b/helper/install.sh @@ -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