#!/bin/bash # Define the service name/path for easy updates BINARY_NAME="gophergate" SOURCE_PATH="./cmd/gophergate/main.go" echo "Stopping existing $BINARY_NAME processes..." # Using pkill; || true ensures the script continues even if no process was found pkill -9 "$BINARY_NAME" || echo "No running process found." echo "Pulling latest changes from git..." git pull echo "Building the application..." if go build -o "$BINARY_NAME" "$SOURCE_PATH"; then echo "Build successful. Starting $BINARY_NAME in the background..." # Launch with nohup and redirect output to a log file nohup "./$BINARY_NAME" > gophergate.log 2>&1 & echo "Service started. PID: $!" else echo "Build failed! Keeping the previous state." exit 1 fi