cloudflared icon indicating copy to clipboard operation
cloudflared copied to clipboard

🐛 post-removal script is not cleaning everything

Open eximius313 opened this issue 3 years ago • 9 comments

Describe the bug Installation is successful, but the purging (dpkg --purge cloudflared) does not clean the service

$ ls /etc/systemd/system/cloudflared*
cloudflared.service 
cloudflared-update.service  
cloudflared-update.timer

nor config files:

$ ls /etc/cloudflared/
config.yml

therefore purge shows following errors:

dpkg: error processing package cloudflared (--purge):
 installed cloudflared package post-removal script subprocess returned error exit status 1

and after reinstall (apt-get install --reinstall cloudflared) when one tries to install new service, they get:

cloudflared service is already installed at /etc/systemd/system/cloudflared.service; if you are running a cloudflared tunnel, you can point it to multiple origins, avoiding the need to run more than one cloudflared service in the same machine; otherwise if you are really sure, you can do `cloudflared service uninstall` to clean up the existing service and then try again this command

Moreover - I was getting weird errors while trying to systemctl disable cloudflared:

Unit /etc/systemd/system/cloudflared.service is masked, ignoring.

To Reproduce Steps to reproduce the behavior:

  1. dpkg --purge cloudflared

Expected behavior post-removal script should clean everything.

Environment and versions

  • OS: Linux
  • Architecture: Arm64
  • Version: 2022.6.3

eximius313 avatar Jul 05 '22 20:07 eximius313

Had this same issue, this solution worked for me:

sudo dpkg --remove --force-remove-reinstreq cloudflared
sudo apt-get remove cloudflared
sudo apt-get autoremove && sudo apt-get autoclean

Soulsender avatar Apr 22 '23 21:04 Soulsender

+1, still an issue

fabiannagel avatar Aug 08 '23 10:08 fabiannagel

Same here, mine kind of crashed, then after doing the official step to uninstall left garbage that dint allow to uninstall and now its even worse as states the follow doing the cleanups:

E: The package cloudflared needs to be reinstalled, but I can't find an archive for it.

For the dpkg:

sudo dpkg --remove --force-remove-reinstreq cloudflared dpkg: warning: overriding problem because --force enabled: dpkg: warning: package is in a very bad inconsistent state; you should reinstall it before attempting a removal (Reading database ... 222495 files and directories currently installed.) Removing cloudflared (2023.7.3) ... rm: cannot remove '/usr/local/bin/cloudflared': No such file or directory dpkg: error processing package cloudflared (--remove): installed cloudflared package post-removal script subprocess returned error exit status 1 Errors were encountered while processing: cloudflared

rubenz91 avatar Aug 15 '23 04:08 rubenz91

Same here, mine kind of crashed, then after doing the official step to uninstall left garbage that dint allow to uninstall and now its even worse as states the follow doing the cleanups:

E: The package cloudflared needs to be reinstalled, but I can't find an archive for it.

For the dpkg:

sudo dpkg --remove --force-remove-reinstreq cloudflared dpkg: warning: overriding problem because --force enabled: dpkg: warning: package is in a very bad inconsistent state; you should reinstall it before attempting a removal (Reading database ... 222495 files and directories currently installed.) Removing cloudflared (2023.7.3) ... rm: cannot remove '/usr/local/bin/cloudflared': No such file or directory dpkg: error processing package cloudflared (--remove): installed cloudflared package post-removal script subprocess returned error exit status 1 Errors were encountered while processing: cloudflared

At the end I found this post and seems the section that worked was the located and delete everything there: locate cloudflare sudo rm -rf [put each of the file paths in here one by one unless you can shorted them with a *]

Also I removed certbot that I had thats the only steps I did and it allow me to reinstall it.

rubenz91 avatar Aug 15 '23 05:08 rubenz91

Also getting this issue with cloudflare on Raspberry Pi

BastianZim avatar Oct 12 '23 17:10 BastianZim

The service still doesn't get removed when uninstalling cloudflared (I used sudo apt remove cloudflared), which causes a lot of errors - just discovered this looping over and over again on one of my systems...

Jan 22 16:41:35 lobster systemd[1]: Starting cloudflared...
Jan 22 16:41:35 lobster systemd[55475]: cloudflared.service: Failed to locate executable /usr/bin/cloudflared: No such file or directory
Jan 22 16:41:35 lobster systemd[55475]: cloudflared.service: Failed at step EXEC spawning /usr/bin/cloudflared: No such file or directory
Jan 22 16:41:35 lobster systemd[1]: cloudflared.service: Main process exited, code=exited, status=203/EXEC
Jan 22 16:41:35 lobster systemd[1]: cloudflared.service: Failed with result 'exit-code'.
Jan 22 16:41:35 lobster systemd[1]: Failed to start cloudflared.
Jan 22 16:41:40 lobster systemd[1]: cloudflared.service: Scheduled restart job, restart counter is at 36562.
Jan 22 16:41:40 lobster systemd[1]: Stopped cloudflared.
Jan 22 16:41:40 lobster systemd[1]: Starting cloudflared...
Jan 22 16:41:40 lobster systemd[55483]: cloudflared.service: Failed to locate executable /usr/bin/cloudflared: No such file or directory
Jan 22 16:41:40 lobster systemd[55483]: cloudflared.service: Failed at step EXEC spawning /usr/bin/cloudflared: No such file or directory
Jan 22 16:41:40 lobster systemd[1]: cloudflared.service: Main process exited, code=exited, status=203/EXEC
Jan 22 16:41:40 lobster systemd[1]: cloudflared.service: Failed with result 'exit-code'.
Jan 22 16:41:40 lobster systemd[1]: Failed to start cloudflared.
Jan 22 16:41:45 lobster systemd[1]: cloudflared.service: Scheduled restart job, restart counter is at 36563.
Jan 22 16:41:45 lobster systemd[1]: Stopped cloudflared.

Running sudo apt purge cloudflared then causes errors:

Purging configuration files for cloudflared (2024.1.4) ...
rm: cannot remove '/usr/local/bin/cloudflared': No such file or directory
dpkg: error processing package cloudflared (--purge):
 installed cloudflared package post-removal script subprocess returned error exit status 1
Errors were encountered while processing:
 cloudflared
E: Sub-process /usr/bin/dpkg returned an error code (1)

Installing it and attempting removal again with sudo apt purge cloudflared leads to:

(Reading database ... 77149 files and directories currently installed.)
Removing cloudflared (2024.1.4) ...
Processing triggers for man-db (2.10.2-1) ...
(Reading database ... 77145 files and directories currently installed.)
Purging configuration files for cloudflared (2024.1.4) ...
rm: cannot remove '/usr/local/bin/cloudflared': No such file or directory
dpkg: error processing package cloudflared (--purge):
 installed cloudflared package post-removal script subprocess returned error exit status 1
Errors were encountered while processing:
 cloudflared
E: Sub-process /usr/bin/dpkg returned an error code (1)

Pretty terrible problem :(

b4shful avatar Jan 22 '24 17:01 b4shful

Yeah is there any chance we can get the priority escalated? This is pretty major.

BastianZim avatar Jan 22 '24 17:01 BastianZim

@chungthuang apologies for the ping, but the user assigned to this (sudarshan-reddy) has "previously helped build cloudflare tunnels" in their bio and hasn't committed anything since October. So they may be no longer working on this...

I found your username by looking through recent commits.

Could you take a look and/or assign someone?

b4shful avatar Jan 22 '24 17:01 b4shful

At the end I found this post and seems the section that worked was the located and delete everything there: locate cloudflare sudo rm -rf [put each of the file paths in here one by one unless you can shorted them with a *]

as rubenz said this is the fix! sudo rm -rf $(locate cloudflared) please note the command above can be dangerous, to do it safely run only locate cloudflared and then remove those files after reviewing

NanashiTheNameless avatar Jan 23 '24 18:01 NanashiTheNameless

This exact thing is happening in my reinstallation -- 04/13/2024. Why, in any semblance of sanity, is this still happening since before 2022?

joej avatar Apr 13 '24 20:04 joej

@joej I can't reproduce this on Ubuntu 22.04, to test I just installed, configured, then removed and reinstalled on my side and it worked fine. Do make sure you follow the instructions here if on Linux to add cloudflare's apt repository to your system, so that you get the latest version (this fix was only deployed in versions 2024.3.0 and above - cloudflared --version can confirm this but of course that may not work if you are having reinstallation issues).

Feel free to post some more information about your setup, what steps you took to uninstall/reinstall, and whether you are sure you are using an updated version of cloudflared that has this fix (#1166) applied.

b4shful avatar Apr 13 '24 22:04 b4shful