#!/bin/bash SERVICE_USER="sql-proxy" SERVICE_GROUP="sql-proxy" SERVICE_DIR="/opt/sql-proxy" LOG_DIR="/var/log/sql-proxy" EXECUTABLE="sql-proxy" SERVICE_FILE="/etc/systemd/system/sql-proxy.service" if ! id "$SERVICE_USER" &>/dev/null; then useradd --system --no-create-home --shell /bin/false "$SERVICE_USER" echo "User $SERVICE_USER created." else echo "User $SERVICE_USER already exists." fi if systemctl is-active --quiet sql-proxy; then echo "Service is running. Stopping..." systemctl stop sql-proxy fi mkdir -p "$SERVICE_DIR" mkdir -p "$LOG_DIR" chown "$SERVICE_USER:$SERVICE_GROUP" "$SERVICE_DIR" chown "$SERVICE_USER:$SERVICE_GROUP" "$LOG_DIR" cp "./$EXECUTABLE" "$SERVICE_DIR/" chown "$SERVICE_USER:$SERVICE_GROUP" "$SERVICE_DIR/$EXECUTABLE" chmod +x "$SERVICE_DIR/$EXECUTABLE" cat > "$SERVICE_FILE" <