#!/sbin/openrc-run

# 服务名称
name="bird-lgproxy"
description="Bird Looking Glass Proxy (Go)"

# 程序路径和参数
command="/etc/birdlg/bird-lgproxy-go"
command_args="-config /etc/birdlg/config.yml"

pidfile="/run/${RC_SVCNAME}.pid"
command_background="yes"

# 自动重启配置（如果程序崩溃）
respawn_delay=5
respawn_max=10

depend() {
    # 确保在网络和 bird 启动后再启动
    need net
    after bird
}

start_pre() {
    # 启动前的检查：确保配置文件存在
    if [ ! -f "/etc/bird-lg/bird-lgproxy.yaml" ]; then
        eerror "Configuration file /etc/bird-lg/bird-lgproxy.yaml not found!"
        return 1
    fi
}