Last active
March 14, 2022 16:55
-
-
Save mrballcb/9996e94b7bf357dc8e70d1692d57da29 to your computer and use it in GitHub Desktop.
Restart Rancher Desktop from the CLI on Mac
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rancher Desktop is what I've switched to in place of Docker Desktop. It has some differences that | |
need to be worked around (see previous gist for setting the network subnet a container uses). | |
One other issue is that after about 24 hours, the docker socket just stops listening. It is currently | |
on Rancher's radar, but in the meantime, the only real solution is to stop and start the entire | |
Rancher Desktop app. The below script does exactly that. | |
A second issue is that a running k3s cluster consumes enough CPU/power that it raises the temperature | |
of the Mac when it's idle and significantly cuts down on battery life. The second script will stop | |
the k3s subsystem and kill all running containers, bringing the CPU usage down to a very low level. | |
Regular docker commands still work and DNS resolution inside of a running container works properly, | |
all while bringing the CPU level back down such that the battery life of the Mac is back to normal. | |
The Rancher team is actively working on making this a feature controllable from the UI: | |
https://github.com/rancher-sandbox/rancher-desktop/issues/1562 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat /usr/local/bin/rancher_k3s_stop.sh | |
#!/usr/bin/env bash | |
echo "Stopping k3s in the VM" | |
LIMA_HOME="${HOME}/Library/Application Support/rancher-desktop/lima" limactl shell 0 sudo /etc/init.d/k3s stop | |
echo "Stopping all running docker images" | |
docker rm -f $(docker ps -aq) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat /usr/local/bin/restart_rancher_desktop.sh | |
#!/usr/bin/env bash | |
osascript -e 'tell application "Rancher Desktop" to quit' | |
while osascript -e 'if application "Rancher Desktop" is not running then error 1' 2>/dev/null; do sleep 2; done | |
# Passing "stop" on the cli will skip the start-up of Rancher Desktop app | |
if [[ $1 = "stop" ]]; then | |
echo "Skipping start up" | |
else | |
open -a "Rancher Desktop" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment