#!/bin/bash
# SMS Receiver Go - 管理脚本

SERVICE_NAME="sms-receiver-go"
BINARY_PATH="/root/.openclaw/workspace/SmsReceiver-go/sms-receiver-new"
LOG_PATH="/root/.openclaw/workspace/SmsReceiver-go/sms_receiver.log"

case "$1" in
    start)
        echo "启动 SMS Receiver Go 服务..."
        systemctl start $SERVICE_NAME
        sleep 2
        systemctl status $SERVICE_NAME --no-pager
        ;;
    stop)
        echo "停止 SMS Receiver Go 服务..."
        systemctl stop $SERVICE_NAME
        ;;
    restart)
        echo "重启 SMS Receiver Go 服务..."
        systemctl restart $SERVICE_NAME
        sleep 2
        systemctl status $SERVICE_NAME --no-pager
        ;;
    status)
        echo "SMS Receiver Go 服务状态:"
        systemctl status $SERVICE_NAME --no-pager
        ;;
    log)
        echo "SMS Receiver Go 日志 (最近 50 行):"
        tail -n 50 $LOG_PATH
        ;;
    logtail)
        echo "实时监控 SMS Receiver Go 日志 (Ctrl+C 退出):"
        tail -f $LOG_PATH
        ;;
    enable)
        echo "设置 SMS Receiver Go 开机自启..."
        systemctl enable $SERVICE_NAME
        ;;
    disable)
        echo "禁用 SMS Receiver Go 开机自启..."
        systemctl disable $SERVICE_NAME
        ;;
    *)
        echo "用法: $0 {start|stop|restart|status|log|logtail|enable|disable}"
        echo ""
        echo "命令说明:"
        echo "  start    - 启动服务"
        echo "  stop     - 停止服务"
        echo "  restart  - 重启服务"
        echo "  status   - 查看状态"
        echo "  log      - 查看日志"
        echo "  logtail  - 实时监控日志"
        echo "  enable   - 设置开机自启"
        echo "  disable  - 禁用开机自启"
        exit 1
        ;;
esac

exit 0
