Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alessionossa/78f69b9451a130240e2057acbd4eb7f8 to your computer and use it in GitHub Desktop.
Save alessionossa/78f69b9451a130240e2057acbd4eb7f8 to your computer and use it in GitHub Desktop.
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