Skip to content

Instantly share code, notes, and snippets.

@natcl
Last active January 23, 2024 22:50
Show Gist options
  • Save natcl/4688162920f368707613 to your computer and use it in GitHub Desktop.
Save natcl/4688162920f368707613 to your computer and use it in GitHub Desktop.
Node-Red launchd script
<?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>
@natcl
Copy link
Author

natcl commented Feb 28, 2015

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 run launchctl load -w org.nodered.plist from that directory.

To stop the daemon you can run launchctl unload org.nodered.plist

@natcl
Copy link
Author

natcl commented Mar 1, 2015

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"

@akobelan
Copy link

akobelan commented Sep 7, 2015

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.

@bkeating
Copy link

bkeating commented Sep 8, 2015

Thanks, @natcl. Very useful. Saved me time.

@cyberreefguru
Copy link

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?

@WizBangCrash
Copy link

WizBangCrash commented Feb 4, 2018

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

@JJiri
Copy link

JJiri commented Jun 14, 2018

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...

@SchneHa
Copy link

SchneHa commented Feb 1, 2021

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>

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