Skip to content

Instantly share code, notes, and snippets.

@notbrain
Last active April 18, 2017 20:34
Show Gist options
  • Save notbrain/7077d2b999177047c3fa725288de3f8e to your computer and use it in GitHub Desktop.
Save notbrain/7077d2b999177047c3fa725288de3f8e to your computer and use it in GitHub Desktop.
plist file to run pm2 as pm2user on macOS with environment variables, linux systemd override.conf
[Service]
Environment="MYSQL_CONN=-h mydb.domain.com -u dbadmin -pnotastrongpassword database_name"
Environment="SLACK_TOKEN=xoxb-94849484948-jfhJSdlobYIFfeFBFYHckiUUJHW19v0F"
<?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.yourdomain.uniqueid</string>
<key>UserName</key>
<string>pm2user</string>
<key>KeepAlive</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>
<string>-c</string>
<string>/usr/local/lib/node_modules/pm2/bin/pm2 resurrect</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>OnDemand</key>
<false/>
<key>LaunchOnlyOnce</key>
<true/>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/local/Cellar/node@6/6.10.0_1/bin</string>
<key>PM2_HOME</key>
<string>/Users/notbrain/.pm2</string>
<key>MYSQL_CONN</key>
<string>-h mydb.domain.com -u dbadmin -pnotastrongpassword database_name</string>
<key>SLACK_TOKEN</key>
<string>xoxb-94849484948-jfhJSdlobYIFfeFBFYHckiUUJHW19v0F</string>
</dict>
<key>StandardErrorPath</key>
<string>/tmp/com.PM2.err</string>
<key>StandardOutPath</key>
<string>/tmp/com.PM2.out</string>
</dict>
</plist>
@notbrain
Copy link
Author

  • macOS .plist goes in ~/Library/LaunchAgents/com.domain.pm2user.plist
  • linux systemd .conf file goes in /etc/systemd/system/pm2-pm2user.service.d/override.conf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment