#!/bin/bash # Configuration APP_NAME="tonav-go" APP_DIR="/root/.openclaw/workspace/ToNav-go" BINARY_NAME="tonav-go-v1" PID_FILE="$APP_DIR/tonav-go.pid" LOG_FILE="$APP_DIR/tonav.log" start() { if [ -f $PID_FILE ]; then PID=$(cat $PID_FILE) if ps -p $PID > /dev/null; then echo "$APP_NAME is already running (PID: $PID)" return fi fi echo "Starting $APP_NAME..." cd $APP_DIR nohup ./$BINARY_NAME >> $LOG_FILE 2>&1 & echo $! > $PID_FILE echo "$APP_NAME started with PID: $(cat $PID_FILE)" } stop() { if [ -f $PID_FILE ]; then PID=$(cat $PID_FILE) echo "Stopping $APP_NAME (PID: $PID)..." kill $PID rm $PID_FILE echo "$APP_NAME stopped." else echo "$APP_NAME is not running." fi } status() { if [ -f $PID_FILE ]; then PID=$(cat $PID_FILE) if ps -p $PID > /dev/null; then echo "$APP_NAME is running (PID: $PID)" else echo "$APP_NAME is not running (stale PID file)" fi else echo "$APP_NAME is not running." fi } build() { echo "Building $APP_NAME..." cd $APP_DIR go build -o $BINARY_NAME echo "Build complete." } case "$1" in start) start ;; stop) stop ;; restart) stop sleep 2 start ;; status) status ;; build) build ;; log) tail -f $LOG_FILE ;; *) echo "Usage: $0 {start|stop|restart|status|build|log}" exit 1 esac