Home/Guides/How to keep long tasks running on a remote Mac mini after you disconnect

How to keep long tasks running on a remote Mac mini after you disconnect

Updated · airankrush

What this guide covers

When you finish, your tasks will keep running after you disconnect, and when you come back you can reattach to the session and read the logs. You need: a Mac mini you can already connect to, basic terminal skills and Homebrew installed.

Steps

  1. First, understand that disconnecting does not stop the task

    Disconnecting UU or RustDesk only ends this remote-control session. The remote Mac is not turned off and apps keep running according to their own settings. What actually stops a task is usually something else: the terminal window being closed, the system going to sleep, the program exiting by itself, or the machine being restarted. The steps below address each of these.

  2. Put the command inside a tmux session

    Run brew install tmux in the terminal to install it, then tmux new -s work to create a session and start the task inside it. Press Ctrl+B and then D to detach, leaving the task in the background; next time you connect, use tmux attach -t work to get back in. This way the task does not end even if the terminal window is closed by mistake. The built-in screen does the same job.

  3. Use caffeinate to prevent sleep while the task runs

    Put caffeinate -i in front of the command, for example caffeinate -i ./build.sh. The system will not idle-sleep while that command is running and goes back to normal automatically when it ends. It only affects that one command and changes no system settings, which suits a rented machine. You can look at the system-level energy and lock-screen settings; before changing them, check with support first to avoid a conflict with the delivered configuration.

  4. Hand always-on tasks to launchd

    For a program that needs to be brought back automatically after a crash, write a property list file and put it under ~/Library/LaunchAgents in your own user directory, specifying the program path, KeepAlive and a log path, then load it with launchctl. Using this directory under your own account is enough; do not modify entries the platform has placed in system-level directories. Note that tasks of this kind only start after your account has logged in.

  5. Write all output to a log

    When nobody is watching, the log is the only record you have. Redirect both standard output and standard error to a file at launch, for example ./run.sh >> ~/logs/run.log 2>&1, and use tail -f to look at it when you come back. Have the program print a timestamped progress line at intervals, so you can tell whether it is running normally, stuck or long gone. Remember to clean out the log directory regularly so the disk does not fill up.

  6. Do not shut down; restart through the proper entry points

    Please do not shut the machine down yourself during the rental: after a shutdown it may need to be powered on in person, and the remote connection drops with it. When you really do need a restart, save your work and stop your tasks first, then click Restart under Remote actions in the machine details in the customer console, or use Restart in the Apple menu on the remote side. Do not submit through both entry points at once. After submitting, watch Task progress; it only counts as done once the machine is back, you have reconnected to the desktop and confirmed your tasks have recovered.

  7. Ask support to assess automatic recovery after a restart first

    Whether tasks recover by themselves after a restart depends on whether the current user logs in automatically and whether the software starts at login. These involve login and disk encryption settings and are tied to the machine's management policy, so send support the software names and what you need and have them check each item. Do not turn off FileVault or remove the login password yourself, and do not shut down or cut power just to test.

FAQ

I used nohup or the background ampersand. Why did the task still stop?

Look at the last few lines of the log and the exit time first. The common causes are the program exiting on its own error, or the system sleeping while idle. For the former, fix the program or let launchd bring it back; for the latter, put caffeinate in front of the command.

Can I set the system to never sleep and never lock?

For a single command, caffeinate solves it without changing global settings. To change system-level energy, lock-screen or login settings, contact Contact support first to confirm, so you do not affect the remote connection or the platform's management configuration.

After the machine restarts, are the tasks in tmux still there?

No. A restart ends every process and the tmux session disappears with them. Tasks that need to recover after a restart have to rely on launchd plus starting at login, and that in turn depends on whether automatic login applies, which support needs to assess first.

A task has bogged the machine down and I cannot connect. Can I force a shutdown?

You cannot force a shutdown yourself. Submit one restart from the customer console first and watch the task progress. If it fails or the machine does not come back for a long time, contact support with the machine name, the time of the action and the error message; do not keep submitting again and again.

Pricing and availability: see the plans page · Help center (中文) · Refund policy (中文) · Telegram Contact support

Back to home · All guides