Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
macOS launchd WireGuard configurations

An example of launchd configuration files for WireGuard on macOS.

To start WireGuard at system startup, you should put com.example.wg.connectOnStartup.wg1.plist in /Library/LaunchDaemons/ folder. Note that on MacBooks, it looks like Global Daemons (aka scripts in /Library/LaunchDaemons/) are not loaded until a user login into an account.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.example.wg.connectOnStartup.wg1</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/bash</string>
<string>-c</string>
<string>date +"%D %T" >&amp;2; /usr/local/bin/wg-quick up /usr/local/etc/wireguard/wg1.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
</dict>
<key>StandardErrorPath</key>
<string>/tmp/com.example.wg.connectOnStartup.wg0.err</string>
<key>StandardOutPath</key>
<string>/tmp/com.example.wg.connectOnStartup.wg0.out</string>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.example.wg.restartWg</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/bash</string>
<string>-c</string>
<string>date +"%D %T" >&amp;2; /usr/local/bin/wg-quick down /usr/local/etc/wireguard/wg1.conf; echo "--- Restarting... ---" >&amp;2; sleep 2; /usr/local/bin/wg-quick up /usr/local/etc/wireguard/wg1.conf; echo "--- Restarted! ---" >&amp;2;</string>
</array>
<key>StartInterval</key>
<integer>500</integer>
<key>Disabled</key>
<false/>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
</dict>
<key>StandardErrorPath</key>
<string>/tmp/com.example.wg.restartWg.err</string>
<key>StandardOutPath</key>
<string>/tmp/com.example.wg.restartWg.out</string>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment