-
-
Save natcl/4688162920f368707613 to your computer and use it in GitHub Desktop.
<?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>org.nodered.plist</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/usr/local/bin/node</string> | |
<string>/usr/local/bin/node-red</string> | |
<string>-v</string> | |
</array> | |
<key>RunAtLoad</key> | |
<true/> | |
<key>KeepAlive</key> | |
<true/> | |
<key>StandardOutPath</key> | |
<string>/Users/YOURUSER/.node-red/node-red.log</string> | |
<key>WorkingDirectory</key> | |
<string>/Users/YOURUSER/.node-red</string> | |
</dict> | |
</plist> |
Here's an alias you can add to your .bashrc or .bash_profile file to quickly restart node-red:
alias restartnode="launchctl unload ~/Library/LaunchAgents/org.node-red.plist ; launchctl load -w ~/Library/LaunchAgents/org.node-red.plist"
Nice work. There is an inconsistency in the naming of your plist file. Either name the plist file org.node-red.plist or org.nodered.plist. The alias you provide will not work otherwise. Newcomers will likely not figure this out.
Thanks for helping out the "other" platform.
Thanks, @natcl. Very useful. Saved me time.
The first comment says the script should go into "/Users/YOURUSER/LaunchAgents" but it appears it should really go into "/Users/YOURUSER/Library/LaunchAgents" instead?
Thanks, @NatCi.
One question: When launchctl launches node-red I get the following error in the node-red.log file:
4 Feb 22:29:36 - [info] Palette editor disabled : npm command not found
When I run node-red from the command line I don't. Do I need to specify anything else in the .plist file? I installed nom using homebrew.
I figured it out minutes after posting my comment :-)
I needed to add the following to my .plist file:
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>$PATH:/usr/local/bin</string>
</dict>
Hope this helps others
Thanks @WizBangCrash,
but where (in file) did you set your instruction?
I set this in org.nodered.plist this:
<key>PATH</key> <string>$PATH:/usr/local/bin</string>
But Pallete still not working...
Here is the correct .plist script with palette working:
<?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>org.nodered.plist</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/node</string>
<string>/usr/local/bin/node-red</string>
<string>-v</string>
</array>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>$PATH:/usr/local/bin</string>
</dict>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/Users/YOURUSER/.node-red/node-red.log</string>
<key>WorkingDirectory</key>
<string>/Users/YOURUSER/.node-red</string>
</dict>
</plist>
This is a Launchd script for Node-Red so that it launches on stratup and restarts if it crashes.
This script assumes you have installed Node-Red using the command
sudo npm install -g node-red
Make sure to change
/Users/YOURUSER
to your own user's home directory path.You will need to place this script in
/Users/YOURUSER/LaunchAgents
and then runlaunchctl load -w org.nodered.plist
from that directory.To stop the daemon you can run
launchctl unload org.nodered.plist