system service
This commit is contained in:
41
install.sh
41
install.sh
@@ -2,7 +2,7 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Vixy Eye Service Mk2 - Installer
|
# Vixy Eye Service Mk2 - Installer
|
||||||
# Deploys to ~/eyes-mk2, creates venv, installs systemd service
|
# Deploys to ~/eyes-mk2, creates venv, installs system-level systemd service
|
||||||
#
|
#
|
||||||
# Usage:
|
# Usage:
|
||||||
# ./install.sh # install and start service
|
# ./install.sh # install and start service
|
||||||
@@ -16,9 +16,9 @@ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|||||||
echo "[install] Vixy Eye Service Mk2"
|
echo "[install] Vixy Eye Service Mk2"
|
||||||
|
|
||||||
# --- Stop existing service if running ---
|
# --- Stop existing service if running ---
|
||||||
if systemctl --user is-active "$SERVICE_NAME" &>/dev/null; then
|
if systemctl is-active "$SERVICE_NAME" &>/dev/null; then
|
||||||
echo "[install] stopping existing $SERVICE_NAME service"
|
echo "[install] stopping existing $SERVICE_NAME service"
|
||||||
systemctl --user stop "$SERVICE_NAME"
|
sudo systemctl stop "$SERVICE_NAME"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# --- Copy files ---
|
# --- Copy files ---
|
||||||
@@ -41,36 +41,37 @@ echo "[install] installing dependencies"
|
|||||||
"$VENV_DIR/bin/pip" install --quiet --upgrade pip
|
"$VENV_DIR/bin/pip" install --quiet --upgrade pip
|
||||||
"$VENV_DIR/bin/pip" install --quiet -r "$INSTALL_DIR/requirements.txt"
|
"$VENV_DIR/bin/pip" install --quiet -r "$INSTALL_DIR/requirements.txt"
|
||||||
|
|
||||||
|
# --- Ensure user is in dialout group for serial access ---
|
||||||
|
if ! groups "$USER" | grep -q dialout; then
|
||||||
|
echo "[install] adding $USER to dialout group (may need re-login)"
|
||||||
|
sudo usermod -aG dialout "$USER"
|
||||||
|
fi
|
||||||
|
|
||||||
# --- Learn USB serial numbers if requested ---
|
# --- Learn USB serial numbers if requested ---
|
||||||
if [ "$1" = "--learn" ]; then
|
if [ "$1" = "--learn" ]; then
|
||||||
echo "[install] learning eye USB serials (both eyes must be plugged in)"
|
echo "[install] learning eye USB serials (both eyes must be plugged in)"
|
||||||
"$VENV_DIR/bin/python" "$INSTALL_DIR/eye_service_mk2.py" --learn
|
"$VENV_DIR/bin/python" "$INSTALL_DIR/eye_service_mk2.py" --learn
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# --- Install systemd service ---
|
# --- Install systemd service (system-level, runs on boot without login) ---
|
||||||
echo "[install] installing systemd service"
|
echo "[install] installing systemd service"
|
||||||
mkdir -p "$HOME/.config/systemd/user"
|
sed -e "s|/home/alex/eyes-mk2|$INSTALL_DIR|g" \
|
||||||
cp "$SCRIPT_DIR/vixy-eyes-mk2.service" "$HOME/.config/systemd/user/$SERVICE_NAME.service"
|
-e "s|User=alex|User=$USER|g" \
|
||||||
|
"$SCRIPT_DIR/vixy-eyes-mk2.service" | sudo tee /etc/systemd/system/"$SERVICE_NAME".service >/dev/null
|
||||||
|
|
||||||
# Patch paths in case home dir differs from build machine
|
sudo systemctl daemon-reload
|
||||||
sed -i "s|/home/alex/eyes-mk2|$INSTALL_DIR|g" \
|
sudo systemctl enable "$SERVICE_NAME"
|
||||||
"$HOME/.config/systemd/user/$SERVICE_NAME.service"
|
sudo systemctl start "$SERVICE_NAME"
|
||||||
sed -i "s|User=alex|User=$USER|g" \
|
|
||||||
"$HOME/.config/systemd/user/$SERVICE_NAME.service"
|
|
||||||
|
|
||||||
systemctl --user daemon-reload
|
|
||||||
systemctl --user enable "$SERVICE_NAME"
|
|
||||||
systemctl --user start "$SERVICE_NAME"
|
|
||||||
|
|
||||||
echo "[install] done"
|
echo "[install] done"
|
||||||
echo ""
|
echo ""
|
||||||
echo " status: systemctl --user status $SERVICE_NAME"
|
echo " status: sudo systemctl status $SERVICE_NAME"
|
||||||
echo " logs: journalctl --user -u $SERVICE_NAME -f"
|
echo " logs: journalctl -u $SERVICE_NAME -f"
|
||||||
echo " stop: systemctl --user stop $SERVICE_NAME"
|
echo " stop: sudo systemctl stop $SERVICE_NAME"
|
||||||
echo " restart: systemctl --user restart $SERVICE_NAME"
|
echo " restart: sudo systemctl restart $SERVICE_NAME"
|
||||||
echo ""
|
echo ""
|
||||||
if [ "$1" != "--learn" ]; then
|
if [ "$1" != "--learn" ]; then
|
||||||
echo " If this is the first install, plug in both eyes and run:"
|
echo " If this is the first install, plug in both eyes and run:"
|
||||||
echo " $INSTALL_DIR/.venv/bin/python $INSTALL_DIR/eye_service_mk2.py --learn"
|
echo " $INSTALL_DIR/.venv/bin/python $INSTALL_DIR/eye_service_mk2.py --learn"
|
||||||
echo " Then: systemctl --user restart $SERVICE_NAME"
|
echo " Then: sudo systemctl restart $SERVICE_NAME"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user