Cloudflared tunnel service run failing [Setup, Ubuntu]

Hi. I am trying to run cloudflared tunnel service in ubuntu but service run fails saying credentials file not found. If I manually start by giving tunnel name (for e.g. sudo cloudflared tunnel run mywebtunnelname ) , then tunnel works as intended.

(all screenshot compiled in 1 as my account is new so respecting rules)
My ubuntu release : ( lsb_release -a )
Commands output :

  • sudo systemctl status cloudflared
  • manual firing the commands showing error in status
  • ls command for the actual file showing at the location
  • start service manually ( sudo systemctl start cloudflared )
  • journal ctl log ( journalctl -xeu cloudflared.service )
Feb 11 15:41:22 server systemd[1]: Failed to start cloudflared.
β–‘β–‘ Subject: A start job for unit cloudflared.service has failed
β–‘β–‘ Defined-By: systemd
β–‘β–‘ Support: http://www.ubuntu.com/support
β–‘β–‘ 
β–‘β–‘ A start job for unit cloudflared.service has finished with a failure.
β–‘β–‘ 
β–‘β–‘ The job identifier is 1020462 and the job result is failed.
Feb 11 15:41:27 server systemd[1]: cloudflared.service: Scheduled restart job, restart counter is at 10419.
β–‘β–‘ Subject: Automatic restarting of a unit has been scheduled
β–‘β–‘ Defined-By: systemd
β–‘β–‘ Support: http://www.ubuntu.com/support
β–‘β–‘ 
β–‘β–‘ Automatic restarting of the unit cloudflared.service has been scheduled, as the result for
β–‘β–‘ the configured Restart= setting for the unit.
Feb 11 15:41:27 server systemd[1]: Stopped cloudflared.
β–‘β–‘ Subject: A stop job for unit cloudflared.service has finished
β–‘β–‘ Defined-By: systemd
β–‘β–‘ Support: http://www.ubuntu.com/support
β–‘β–‘ 
β–‘β–‘ A stop job for unit cloudflared.service has finished.
β–‘β–‘ 
β–‘β–‘ The job identifier is 1020555 and the job result is done.
Feb 11 15:41:27 server systemd[1]: Starting cloudflared...
β–‘β–‘ Subject: A start job for unit cloudflared.service has begun execution
β–‘β–‘ Defined-By: systemd
β–‘β–‘ Support: http://www.ubuntu.com/support
β–‘β–‘ 
β–‘β–‘ A start job for unit cloudflared.service has begun execution.
β–‘β–‘ 
β–‘β–‘ The job identifier is 1020555.
Feb 11 15:41:27 server cloudflared[134518]: Tunnel credentials file 'd2dxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx22a.json' doesn't exist or is not a file
Feb 11 15:41:27 server systemd[1]: cloudflared.service: Main process exited, code=exited, status=1/FAILURE
β–‘β–‘ Subject: Unit process exited
β–‘β–‘ Defined-By: systemd
β–‘β–‘ Support: http://www.ubuntu.com/support
β–‘β–‘ 
β–‘β–‘ An ExecStart= process belonging to unit cloudflared.service has exited.
β–‘β–‘ 
β–‘β–‘ The process' exit code is 'exited' and its exit status is 1.
Feb 11 15:41:27 server systemd[1]: cloudflared.service: Failed with result 'exit-code'.
β–‘β–‘ Subject: Unit failed
β–‘β–‘ Defined-By: systemd
β–‘β–‘ Support: http://www.ubuntu.com/support
β–‘β–‘ 
β–‘β–‘ The unit cloudflared.service has entered the 'failed' state with result 'exit-code'.
Feb 11 15:41:27 server systemd[1]: Failed to start cloudflared.
β–‘β–‘ Subject: A start job for unit cloudflared.service has failed
β–‘β–‘ Defined-By: systemd
β–‘β–‘ Support: http://www.ubuntu.com/support
β–‘β–‘ 
β–‘β–‘ A start job for unit cloudflared.service has finished with a failure.
β–‘β–‘ 
β–‘β–‘ The job identifier is 1020555 and the job result is failed.

I am not able to be able to diagnose what is going wrong, if it is related to system or something else I am doing wrong. I followed the official guide and setup works on manual commands on starting selected tunnel by name. So I am doubting that this might be something related to system but not sure hence asking here.
Any help appreciated, thanks in advance.

1 Like

You need to check to make sure that the credential file that is listed in the config file /etc/cloudflared/config.yml exists at the path it says it should.

I have shared the screenshot with the files showing in the location , sorry for them not in order as my account is new so had to compile all ss(screenshot) in one upload. So the ls at /etc/cloudflared/ shows the file exists. Also if I run β€œsudo cloudflared tunnel run mytunnelname” then the service runs as normal. So config files are working for sure just not as a service. Hope that clears about files being available in more details. Still thanks for your time and attention. If you spot something else please let me know. Have a good one ahead.

What does the config file at /etc/cloudflared/config.yml look like?

Running a tunnel from the command line is different than running it as a service because the files that it checks are in different locations.

Oh, okay. Here is how /etc/cloudflared/config.yml looks like.
image
Hope this helps.

Have you given the full path to where your credential file is.located as per the documents?

url: http://localhost:8000
tunnel:
credentials-file: /root/.cloudflared/.json

Your service needs to know where that file is located and if you created it with a user the service cannot access it will fail with what I think I can see in the screen shots.

2 Likes

Yeah, as @nirving said you need to change the path of the credentials-file. It should be /etc/cloudflare/<d2d tunnel json>.

1 Like

oh okay, understood. So I need to give absolute path (full path) . And that works well. Thank you @nirving and @Cyb3r-Jak3 . Please also tell me which one should I mark as solution for this one , I mean @nirving 's response or @Cyb3r-Jak3 's response since both of you gave same solution.

Give it to @Cyb3r-Jak3 he did the groundwork with you.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.