Hi,
I'm trying to run Cloudflared as a service.
Via the following command (as root), I'm able to setup an Argo Tunnel:
cloudflared tunnel run
I want to set this as a daemon, so I've created the following scripts:
/etc/rc.d/argotunnel (with chmod +x)
#!/bin/sh
. /etc/rc.subr
name="argotunnel"
rcvar="argotunnel_enable"
argotunnel_user="root"
argotunnel_command="cloudflared tunnel --config /root/.cloudflared/config.yml run"
pidfile="/var/run/${name}.pid"
command="/usr/sbin/daemon"
command_args="-P ${pidfile} -r -f ${argotunnel_command}"
load_rc_config $name
: ${argotunnel_enable:=no}
run_rc_command "$1"
I've added this to my /etc/rc.conf:
argotunnel_enable='YES'
Via the following command, I start the service:
service argotunnel start
I can validate that the service has started:
ps aux
root 45253 0.0 0.0 1066812 2508 - Ss 16:03 0:00.00 daemon: cloudflared[62627] (daemon)
But apparently, nothing happens. The tunnel is not started as if I would start the tunnel myself manually.
Any idea what's wrong?
Thanks
Cadish
Did you find a solution for this?
Hi 9axqe,
I've setup cloudflared on a Proxmox server instead, but I've written down for myself what my solution back then was. I'm sure there's a better way to do it now.
These are the steps I did back then to enable it as a service:
1. My config is in /root/.cloudflared/config.yml
2. Create this file: /etc/rc.d/argotunnel
#!/bin/sh
. /etc/rc.subr
name="argotunnel"
rcvar="argotunnel_enable"
argotunnel_flags="tunnel --config /root/.cloudflared/config.yml"
command_args="run"
command="/usr/local/bin/cloudflared"
load_rc_config $name
run_rc_command "$1"
3. chmod +x /etc/rc.d/argotunnel
4. Add to /etc/rc.conf:
argotunnel_enable='YES'
5. Create this script: /root/.cloudflared/automatic_restart.sh
#!/bin/bash
SERVICE="cloudflared"
if pgrep -x "$SERVICE" >/dev/null
then
echo "$SERVICE is running"
else
echo "$SERVICE stopped"
/usr/sbin/daemon /etc/rc.d/argotunnel start
fi
6. Create a cron action: /usr/local/opnsense/service/conf/actions.d/actions_argotunnel.conf
[start]
command:/bin/sh /root/.cloudflared/automatic_restart.sh
parametes:
type:script
message:starting cloudflared if necessary
description:Check and restart cloudflared
7. Restart cron services
service configd restart
8. Create a cron in the OPNsense UI with "Check and restart cloudflared" as command