Feature request: Automatic start on login
People are used to Docker Desktop coming up at login. Can we add the same option with Colima?
I experimented a bit with adding a service using homebrew, but wasn't successful. I think it's probably because colima is already setting up its own launchctl. Not sure what the options might be but letting brew services manage the launchctl might be a more integrated solution. My (failed) experiment is at https://github.com/rfay/homebrew-core/blob/601260825034aefbecb50f0a3202f7f0e4f7b197/Formula/colima.rb#L46-L55
@abiosoft I have a Homebrew service that works on my machine,
https://github.com/Homebrew/homebrew-core/pull/94189
give it a try! Leave a thumbs up on the PR if it works, or a comment if it doesn't please!
EDIT: it was merged, hopefully it works for everyone. It should, but I guess we can close this issue.
I wanted to do more testing, prior to having the PR merged. This is where I'm lacking in understanding when it comes to Colima.
The service starts in Homebrew and runs effectively, but after some time it restart loops on my machine. I sadly, didn't test for this as I expected once it's up it'll run and do its daemon thing. Looking through logs,
Brew Logs: located at /usr/local/var/log/colima.log
time="2022-02-01T09:38:44-06:00" level=info msg="[hostagent] The final requirement 1 of 1 is satisfied"
time="2022-02-01T09:38:44-06:00" level=info msg="READY. Run `limactl shell colima` to open the shell."
time="2022-02-01T09:38:44-06:00" level=info msg="provisioning ..." context=docker
colima
Current context is now "colima"
time="2022-02-01T09:38:45-06:00" level=info msg="starting ..." context=docker
* /var/log/docker.log: creating file
* /var/log/docker.log: correcting owner
* Starting Docker Daemon ... [ ok ]
Above shows that Colima has started successfully, I never see any sort of error case happening in these logs.
Initial Thoughts
The issue may be that the livecheck doesn't check the health of the application, so the keep alive from Brew is just restarting it constantly.
livecheck do
url :stable
regex(/^v?(\d+(?:\.\d+)+)$/i)
end
Removing the keep-alive from the brew config doesn't resolve the issue. I don't believe this is the issue, not sure what else could be causing it.
@abiosoft any ideas here? Can you reproduce (if you have a mac)
That log outputs indicates successful startup.
How does the keep_alive work in brew, what command is it running to verify, or is it basically monitoring the process?
I would say that keep_alive should be set to false. Colima does not stay in foreground and it can be checked with colima status.
This is most likely the cause of https://github.com/abiosoft/colima/issues/156https://github.com/abiosoft/colima/issues/156.
Will revert in Homebrew, removing keep_alive is still hitting the same situation, the logs say it's starting, but
docker ps
fails, will open another draft and keep that open to ensure it works later tonight. Will reach out then to get approval from others of it working.
EDIT: revert PR https://github.com/Homebrew/homebrew-core/pull/94264
Thanks for your efforts @NickHackman
@rfay's original attempt looks promising. It might just be missing setting PATH and HOME from @NickHackman's version.
Ah, no, I think we need a way to specify LaunchOnlyOnce in the service block:
LaunchOnlyOnce <boolean>
This optional key specifies whether the job can only be run once and only once. In other words, if the job cannot be safely
respawned without a full machine reboot, then set this key to be true.
See also https://www.karltarvas.com/2020/09/11/macos-run-script-on-startup.html.
I don't think this is supported in Homebrew yet, but PRs to implement this in https://github.com/Homebrew/brew/blob/423f34dee16e036f685b992a3ba3db29261c8f70/Library/Homebrew/service.rb are welcome.
@abiosoft Correct my understanding here, but running colima start forks and starts the daemon for the corresponding container runtime? Reading the launchd man pages on MacOS:
Daemons or agents managed by launchd are expected to behave certain ways.
A daemon or agent launched by launchd MUST NOT do the following in the process directly launched by launchd:
- Call daemon(3).
- Do the moral equivalent of daemon(3) by calling fork(2) and have the parent process exit(3) or _exit(2).
Looking at the logs of colima start
> msg="[hostagent] The final requirement 1 of 1 is satisfied"
> msg="READY. Run `limactl shell colima` to open the shell."
INFO[0020] provisioning ... context=docker
> colima
> Current context is now "colima"
INFO[0020] starting ... context=docker
> * /var/log/docker.log: creating file
> * /var/log/docker.log: correcting owner
> * Starting Docker Daemon ... [ ok ]
INFO[0025] waiting for startup to complete ... context=docker
INFO[0026] done
From my understanding Colima breaks the above requirements of launchd where it creates a daemon and then colima start exits.
@carlocab do you have experience with other applications that behave this way working with launchd in one way or another?
Not really, but my understanding is that this is why we want LaunchOnlyOnce: we don't really want launchd to manage the colima daemon (because it's complicated -- my impression is that there actually isn't a colima or even a lima daemon, just a background qemu process/daemon that is queried whenever you invoke colima/lima/limactl). We just want launchctl to call it at startup.
This does mean that we don't have the benefit of launchd restarting it when needed (e.g. in event of a crash), but that probably requires some changes in colima or lima to work properly.
I've been testing Colima with the LaunchOnlyOnce flag in brew (was going to open a PR until I found the above requirements by launchd)
plist_options manual: "colima"
service do
run [opt_bin/"colima", "start"]
run_type :immediate
keep_alive false
launch_only_once true
environment_variables HOME: ENV["HOME"], PATH: std_service_path_env
error_log_path var/"log/colima.log"
log_path var/"log/colima.log"
working_dir ENV["HOME"]
end
It's still following similar behavior where it'll start where colima status returns that it's running and then after starting a second or two will pass and then it'll die according to colima status and trying to interact with the docker daemon
Doesn't say anything after it dies in the logs located at /usr/local/var/log/colima.log nor anything new at ~/.lima/colima/serial.log maybe there's something I'm missing when it comes to debugging?
I'd like to get colima running as a service is there anything I can do to assist?
I'm using Automator as a workaround for now. https://chrisfromredfin.dev/posts/colima-autostart/
@abiosoft I have a Homebrew service that works on my machine,
give it a try! Leave a thumbs up on the PR if it works, or a comment if it doesn't please!
EDIT: it was merged, hopefully it works for everyone. It should, but I guess we can close this issue.
Hi, @NickHackman need help. I use brew but it says colima not implemented #plist, #service or installed a locatable service file, how can i solve this problem
brew services start colima
Error: Formula `colima` has not implemented #plist, #service or installed a locatable service file
I'm using Automator as a workaround for now. https://chrisfromredfin.dev/posts/colima-autostart/
Hi - I just tried this and found that Colina was in
usr/local/bin not /opt/homebrew/bin/
Also, I got the error "zsh:2: permission denied: /usr/local/bin/” even though colima stat works just fine in terminal.
Any ideas?
(Sidenote: @JCHH2 on arm64 (M1) computers, homebrew puts things in /opt/homebrew, on macOS amd64 it puts them in /usr/local/Homebrew.)
If you wanted to enable this for yourself trivially you could add a shell script like the following colima-launcher, alongside .../bin/colima:
#!/usr/bin/env bash
colima start
/opt/homebrew/gnubin/sleep infinity
And modify the plist file to point at the new script.
It comes with the caveat of having no relationship to the forked processes colima creates and therefore not responding to the failure of the colima, lima or qemu processes at all. It's only suitable for a run once invokation but could be cycled with brew services restart colima if failed.
It seems like it could be useful to add a configuration flag to colima to create subprocesses as children instead as it would allow the desired behaviour when being run as a service/agent.
I am currently starting Colima on macOS with a little wrapper script: https://gist.github.com/fardjad/a83c30b9b744b9612d793666f28361a5#file-how-to-start-colima-automatically-on-macos-md
The script does the following:
- Starts Colima and keeps retrying until it succeeds.
- It waits until it receives a shutdown signal from
launchdand then tries to stop Colima gracefully.
This is less prone to restart loop issues compared to the previous attempts and supports the use-case where the user wants to manually stop colima with colima stop.
@abiosoft It would make things much easier if Colima supported a foreground mode so we could leave it to launchd to manage the process.
@abiosoft It would make things much easier if Colima supported a foreground mode so we could leave it to launchd to manage the process.
Oh, I never thought of this. Yeah, foreground mode is doable.
I am currently starting Colima on macOS with a little wrapper script: https://gist.github.com/fardjad/a83c30b9b744b9612d793666f28361a5#file-how-to-start-colima-automatically-on-macos-md
@fardjad Your script is great. I just need to change it to work for me. Colima installed with brew.sh
- export PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
+ export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
@abiosoft I have a Homebrew service that works on my machine, Homebrew/homebrew-core#94189 give it a try! Leave a thumbs up on the PR if it works, or a comment if it doesn't please! EDIT: it was merged, hopefully it works for everyone. It should, but I guess we can close this issue.
Hi, @NickHackman need help. I use brew but it says colima not implemented #plist, #service or installed a locatable service file, how can i solve this problem
brew services start colima Error: Formula `colima` has not implemented #plist, #service or installed a locatable service file
Looks like the change was reverted: https://github.com/Homebrew/homebrew-core/pull/94264
This is the sole reason preventing me from switching from Docker Desktop to colima 😊 Seems like this is tantalizingly close? 😄
Would be cool to have this, not a big deal running it manually but would be very nice to have autostart.
Would be cool to have this, not a big deal running it manually but would be very nice to have autostart.
It is a big deal if you're serving actual websites to live traffic from Docker 😇 Power interruptions and/or kernel panics should then cause everything to automatically restart. (I've had both happen already.)
(I serve https://wimleers.com like this: browser → Fastly → port forwarding on my ISP's modem since it blocks ports 80 and 443 → Mac Mini → ddev instance in Docker.)
Would be cool to have this, not a big deal running it manually but would be very nice to have autostart.
It is a big deal if you're serving actual websites to live traffic from Docker 😇 Power interruptions and/or kernel panics should then cause everything to automatically restart. (I've had both happen already.)
(I serve
https://wimleers.comlike this: browser → Fastly → port forwarding on my ISP's modem since it blocks ports 80 and 443 → Mac Mini →ddevinstance in Docker.)
Well, you can easily add a script to start colima on boot as other have suggested. Of course an official solution would be nicer
I'd love to see this too, but it's definitely not a deal-breaker.
In the short term, I've been using this ansible-role to manage the launch agent on OSX. (I use Ansible to end-to-end provision my macs...)
I've implemented the foreground mode. It works with already created service in brew (and then reverted) https://github.com/abiosoft/colima/pull/789
Hi, the FAQ mentions that "since 0.5.6" Colima autostart is easy with brew services start colima.
At the same time, the last released version is 0.5.5. Any idea when 0.5.6 is going to be released?
I just upgraded to 0.5.6 but brew services start colima gives me the error:
Error: Formula
colimahas not implemented #plist, #service or installed a locatable service file
https://github.com/Homebrew/homebrew-core/pull/149670
The commit has been merged. Please verify if it works for you guys.