What this guide covers
When you finish, your long tasks no longer pause because of system idle sleep, and everything returns to its original state once the task ends. You need: basic terminal skills.
Steps
First tell three things apart: disconnecting, display off, and sleep
Disconnecting the remote desktop only ends the remote access session; the remote system keeps running as usual. The display turning off does not affect background computation either. What really pauses a task is system sleep. So that is the only one you need to guard against, and only while the task is running. Closing the lid of your own laptop has nothing to do with the remote machine; see whether tasks stop when the lid is closed.
Wrap the command in caffeinate
The most common form is
caffeinate -i <your command>, for examplecaffeinate -i ./train.sh. According to the system manual,-icreates an assertion that prevents system idle sleep. The assertion is valid while that command runs and is released automatically as soon as the command ends. It writes nothing to system settings, so it does not conflict with the power configuration the platform delivered, and it needs no administrator password.Choose flags as needed
The options in the manual:
-iprevents system idle sleep.-sprevents system sleep and is valid only on AC power; a Mac mini is always on mains power, so it can be used.-dprevents display sleep, and should be added only when the task really needs the screen to stay on.-mprevents the disk from idle sleeping. They can be combined, for examplecaffeinate -is. For unattended computation,-iis generally enough.Add it to a process that is already running
If the task has already started and you forgot to add it, there is no need to start over. Find the process ID with
pgrep -f <keyword>, then runcaffeinate -i -w <PID>: it waits until that process exits and then ends by itself. Put this command in another tmux window so it does not die with the terminal window.With no specific command, hold for a set time
caffeinate -i -t <seconds>keeps the machine awake for the given number of seconds and ends automatically when time is up. It suits waiting for a process you did not start yourself, such as an export in a graphical app. Note what the manual says:-thas no effect when a command follows it, in which case the command's running time applies. Runningcaffeinatewith no arguments at all holds until you press Ctrl+C.Confirm it is working, read-only
pmset -g assertionslists every current sleep-prevention assertion and who created it. If you can see your caffeinate process, it is working.pmset -gshows the current power settings. Both commands only display information. Changing power settings falls within the platform's delivered configuration: contact support first if something needs adjusting, do not follow online tutorials to change them, and do not install always-on utilities that rewrite system power settings.What it cannot help with
caffeinate only prevents sleep. It cannot stop the program crashing by itself, the terminal window being closed, or the machine being restarted for a system update or maintenance. Those are handled by logs, tmux and start-at-login jobs respectively. Also, do not shut the machine down yourself: after a shutdown someone may have to power it on in person, and the remote connection drops with it. See whether you can shut down or sleep the machine.
FAQ
Can I just set the system to never sleep?
Do not change it yourself. Power-related settings are part of the delivered configuration, and whether the machine currently sleeps at all is determined by the state it was delivered in. Look with pmset -g first, and check with support if you need an adjustment.
Are tasks still running after the screen locks?
A locked screen only means the password has to be entered again to use the desktop. Background processes keep running. When you come back, unlock it by entering the Mac account password through the remote desktop.
Should scheduled jobs use caffeinate too?
For long-running ones, we suggest it: put caffeinate -i in front of the job's command. The system manual says a launchd calendar job missed during sleep runs on wake, but a job already running that gets interrupted by sleep can only be protected this way.
Related
- Can I shut down a rented Mac mini or put it to sleep?
- How to keep long tasks running on a remote Mac mini after you disconnect
- My agent stops when I close my laptop lid. What can I do?
- How to manage several long-running tmux sessions on a remote Mac mini
- How to schedule and auto-start jobs with user-level LaunchAgents on a remote Mac mini
Pricing and availability: see the plans page · Help center (中文) · Refund policy (中文) · Telegram Contact support