Auto-starting Instances at Login

macpine can be configured to automatically start specific virtual machines when you log in to your macOS user account by leveraging the system's launchctl service. This is useful for services you always want running in the background.

Note that enabling this feature may slightly increase your login time.

The launchctl-autostart Tag

The autostart mechanism works by identifying instances with a special tag: launchctl-autostart. The launch agent will automatically execute alpine start +launchctl-autostart upon user login.

To enable a VM for autostart, simply add this tag:

# Add the autostart tag to 'my-server-vm'
alpine tag my-server-vm launchctl-autostart

You can add this tag to as many instances as you need.

To disable autostart for an instance, remove the tag:

# Remove the tag to prevent autostarting
alpine tag -r my-server-vm launchctl-autostart

Installing the Launch Agent

There are two ways to install the macpine launch agent plist file into ~/Library/LaunchAgents.

If you installed macpine via Homebrew, this is the easiest method. brew services will create and manage the launch agent for you.

# Ensure macpine is installed
brew install macpine

# Start and enable the service
brew services start macpine

To disable it, simply run brew services stop macpine.

2. Installing from Source

If you installed macpine from source or manually, you can use the Makefile to install the agent. This requires the alpine binary to be in your system's PATH.

# Navigate to the cloned macpine repository directory
cd /path/to/macpine

# Run the agent installation target
make agent

This command compiles a plist file with the correct path to your alpine executable and places it in ~/Library/LaunchAgents/alpineDaemonLaunchAgent.plist.