• 请不要在回答技术问题时复制粘贴 AI 生成的内容
ttut
V2EX  ›  程序员

cloudflare tunnel 开机不自启,是哪里的问题

  •  
  •   ttut · Jun 6, 2024 · 3437 views
    This topic created in 882 days ago, the information mentioned may be changed or developed.
    openwrt 安装的 cloudflare tunnel ,openwrt 重启后 cloudflare tunnel 不自启,是 down 状态。
    只有在 ssh 手动执行以下其中一个命令
    cloudflared tunnel run [Tunnel name 或 Tunnel ID]
    nohup cloudflared tunnel run [Tunnel name 或 Tunnel ID] >/dev/null 2>&1 &
    cloudflare tunnel 就正常,才是 HEALTHY 状态。
    尝试过在 openwrt 启动项和计划任务里加入上面的命令,但是也不行。
    Supplement 1  ·  Jun 8, 2024
    感谢大佬们的回复,从 openwrt 下载原版 openwrt 安装解决了此问题。
    16 replies  •  2024-06-07 14:24:29 +08:00
    geekvcn
    geekvcn
    Jun 6, 2024
    1
    #!/bin/sh /etc/rc.common
    START=99
    start(){
    nohup cloudflared tunnel run [Tunnel name 或 Tunnel ID] >/dev/null 2>&1 &
    }

    stop(){
    kill -9 `ps |grep cloudflared|grep -v grep|awk '{print $1}'`
    }

    restart(){
    stop
    sleep 1
    start
    }

    把上面的内容写入到/etc/init.d/cloudflared
    chmod +x /etc/init.d/cloudflared
    service cloudflared enable
    ttut
    ttut
    OP
    Jun 6, 2024
    2
    @geekvcn #1 还是不行,不知道是不是这样加
    #!/bin/sh /etc/rc.common

    USE_PROCD=1
    START=99

    start(){
    nohup cloudflared tunnel run [Tunnel name 或 Tunnel ID] >/dev/null 2>&1 &
    }

    stop(){
    kill -9 `ps |grep cloudflared|grep -v grep|awk '{print $1}'`
    }

    restart(){
    stop
    sleep 1
    start
    }


    CONF="cloudflared"
    PROG="/usr/bin/cloudflared"

    append_param_arg() {
    local value
    config_get value "config" "$1" $2
    [ -n "$value" ] && procd_append_param command "--$1" "$value"
    }

    start_service() {
    config_load "$CONF"

    local enabled
    config_get_bool enabled "config" "enabled"
    [ "$enabled" -eq "1" ] || return 1

    procd_open_instance "$CONF"
    procd_set_param command "$PROG" "tunnel"
    procd_append_param command "--no-autoupdate"

    append_param_arg "config" "/etc/cloudflared/config.yml"
    append_param_arg "origincert" "/etc/cloudflared/cert.pem"
    append_param_arg "region"
    append_param_arg "loglevel"
    append_param_arg "logfile"

    procd_append_param command "run"
    append_param_arg "token"

    procd_set_param respawn
    procd_set_param stderr 1

    procd_close_instance
    }

    reload_service() {
    stop
    start
    }

    service_triggers() {
    procd_add_reload_trigger "$CONF"
    }
    flynaj
    flynaj
    Jun 7, 2024 via Android
    3
    原版你直接安装 luci-i18n-cloudflared-zh-cn ,在 Web 界面配置就行,不需要你改它的脚本,
    flynaj
    flynaj
    Jun 7, 2024 via Android
    4
    也可以直接编辑配置
    文件在 /etc/config/cloudflared
    config cloudflared 'config'
    option enabled '1'

    这样才会运行
    sky96111
    sky96111
    Jun 7, 2024
    5
    cf tunnel 生成的 rc 启动脚本在 op 里有兼容性问题,你比对一下格式就知道了。要么用 luci 那个包,要么动手改一下启动脚本
    ttut
    ttut
    OP
    Jun 7, 2024
    6
    @flynaj #3 可能我的 openwrt 版本不兼容,我试过装 packages-23.05 和 packages-22.03 里的(packages-22.03 以下就没有 cloudflared 了)
    luci-app-cloudflared_1.2_all.ipk
    packages-23.05:luci-i18n-cloudflared-zh-cn_git-24.137.59920-b342a45_all.ipk
    packages-22.03:luci-i18n-cloudflared-zh-cn_git-24.137.60246-95611b9_all.ipk
    但在 openwrt 的 web 页面不出现 cloudflared 相关配置。
    ttut
    ttut
    OP
    Jun 7, 2024
    7
    @flynaj #4 按这个修改过,也不自启
    photon006
    photon006
    Jun 7, 2024
    8
    docker 运行
    ttut
    ttut
    OP
    Jun 7, 2024
    9
    @flynaj #4
    @sky96111 #5
    @photon006 #8
    感谢各位大佬的回复,我再折腾下看,实在不行考虑换 openwrt 版本
    momo65535
    momo65535
    Jun 7, 2024
    10
    我是 docker 跑
    tsanie
    tsanie
    Jun 7, 2024
    11
    @ttut #6
    装了后不在 Servicse 里,在 VPN 里。
    ttut
    ttut
    OP
    Jun 7, 2024
    12
    @tsanie #11 我也看过,都没有。
    ttut
    ttut
    OP
    Jun 7, 2024
    13
    @tsanie #11 你这个是原版 openwrt 吗?安装的 cloudflared 、luci-app-cloudflared 、luci-i18n-cloudflared-zh-cn 又是哪个版本呢?
    我现在安装的是 2024.6.0 。但 luci-app-cloudflared 、luci-i18n-cloudflared-zh-cn 安装总是出问题
    tsanie
    tsanie
    Jun 7, 2024
    14
    @ttut #13

    是的,原版 23.05.0 。
    cloudflared - 2024.4.0-1
    luci-app-cloudflared - 1.2
    flynaj
    flynaj
    Jun 7, 2024
    15
    @ttut #6 ctrl+f5 刷新一下。23.05.3 实测可以正常使用。
    ttut
    ttut
    OP
    Jun 7, 2024
    16
    @tsanie #14
    @flynaj #15
    感谢感谢,我再试试
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   5609 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 119ms · UTC 03:33 · PVG 11:33 · LAX 19:33 · JFK 22:33
    ♥ Do have faith in what you're doing.