···11+#!/bin/bash
22+33+# Check if running as root
44+if [ "$EUID" -ne 0 ]; then
55+ echo "This script must be run as root (use sudo)"
66+ exit 1
77+fi
88+99+# Define file paths
1010+SERVICE_NAME="stagehand"
1111+SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
1212+SERVICE_FILE="$SCRIPT_DIR/$SERVICE_NAME.service"
1313+SYSTEMD_DIR="/etc/systemd/system"
1414+1515+# Copy the service file
1616+echo "Copying $SERVICE_NAME.service to $SYSTEMD_DIR..."
1717+cp "$SERVICE_FILE" "$SYSTEMD_DIR/"
1818+1919+# Set proper permissions
2020+echo "Setting permissions..."
2121+chmod 644 "$SYSTEMD_DIR/$SERVICE_NAME.service"
2222+2323+# Reload systemd to recognize new service
2424+echo "Reloading systemd daemon..."
2525+systemctl daemon-reload
2626+2727+# Enable the service
2828+echo "Enabling $SERVICE_NAME service..."
2929+systemctl enable "$SERVICE_NAME"
3030+3131+echo "Service installation complete!"
3232+echo "You can start the service with: sudo systemctl start $SERVICE_NAME"
3333+echo "Check service status with: systemctl status $SERVICE_NAME"
3434+3535+# Ask if the user wants to start the service now
3636+read -p "Do you want to start the service now? (y/n): " START_NOW
3737+if [[ "$START_NOW" =~ ^[Yy]$ ]]; then
3838+ echo "Starting $SERVICE_NAME service..."
3939+ systemctl start "$SERVICE_NAME"
4040+ echo "Service started."
4141+fi
+17
stagehand.service
···11+[Unit]
22+Description=Stagehand Telegram bot service
33+After=network.target
44+55+[Service]
66+Type=simple
77+User=henrick
88+WorkingDirectory=/home/henrick/stagehand
99+ExecStart=/usr/bin/npm run start
1010+Restart=on-failure
1111+RestartSec=10
1212+StandardOutput=syslog
1313+StandardError=syslog
1414+SyslogIdentifier=stagehand
1515+1616+[Install]
1717+WantedBy=multi-user.target