When openwrt installs the service using cloudflared, there’s a compatibility issue. The problem lies in the service script under /etc/init.d/, which defaults to SysVinit, while cloudflared uses procd. So we need to modify the service script to the procd format.
SysVinit is the traditional init system used by many early Linux distributions. It uses a series of shell scripts to start various services in a specific order. These scripts are usually located in /etc/init.d/, with one script per service. SysVinit’s main drawback is that it starts services linearly and can’t start them in parallel, which can lead to longer boot times.
procd is the init system used by OpenWrt. Unlike SysVinit, procd can start services in parallel, speeding up system boot time. procd also provides other advanced features such as process monitoring, automatic restart, and cgroup management. procd’s service scripts are usually located in /etc/init.d/, similar to SysVinit, but their format and syntax differ.
After modifying /etc/init.d/cloudflared, just restart the service with /etc/init.d/cloudflared restart.
#!/bin/sh /etc/rc.common# Copyright (C) 2021 Tianling Shen <cnsztl@immortalwrt.org>
USE_PROCD=1START=99
CONF="cloudflared"PROG="/usr/bin/cloudflared"
start_service() { procd_open_instance procd_set_param command "$PROG" "--pidfile" "/var/run/$CONF.pid" "--logfile" "/var/log/cloudflared.log" "--protocol" "http2" "--no-autoupdate" "tunnel" "run" "--token" "xxxxxxxxxxxxxxxx" procd_set_param stdout 1 procd_set_param stderr 1 procd_set_param pidfile "/var/run/$CONF.pid" procd_close_instance}
stop_service() { procd_kill $CONF}
reload_service() { stop start}
service_triggers() { procd_add_reload_trigger "$CONF"}