diff --git a/buildroot-external/board/raspberrypi/rootfs-overlay/lib/systemd/system/nodered.service b/buildroot-external/board/raspberrypi/rootfs-overlay/lib/systemd/system/nodered.service new file mode 100644 index 00000000..dcb17eeb --- /dev/null +++ b/buildroot-external/board/raspberrypi/rootfs-overlay/lib/systemd/system/nodered.service @@ -0,0 +1,32 @@ +# systemd service file to start Node-RED + +[Unit] +Description=Node-RED graphical event wiring tool +Wants=network.target +Documentation=http://nodered.org/docs/hardware/raspberrypi.html + +[Service] +Type=simple +# Run as normal pi user - change to the user name you wish to run Node-RED as +User=mycroft +Group=mycroft +WorkingDirectory=/home/mycroft + +Nice=5 +Environment="NODE_OPTIONS=--max_old_space_size=512" +# uncomment and edit next line if you need an http proxy +#Environment="HTTP_PROXY=my.httpproxy.server.address" +# uncomment the next line for a more verbose log output +#Environment="NODE_RED_OPTIONS=-v" +#ExecStart=/usr/bin/env node $NODE_OPTIONS red.js $NODE_RED_OPTIONS +ExecStart=/usr/bin/env node-red-pi $NODE_OPTIONS $NODE_RED_OPTIONS +# Use SIGINT to stop +KillSignal=SIGINT +# Auto restart on crash +Restart=on-failure +# Tag things in the log +SyslogIdentifier=Node-RED +#StandardOutput=syslog + +[Install] +WantedBy=multi-user.target diff --git a/buildroot-external/rootfs-overlay/usr/bin/node-red-log b/buildroot-external/rootfs-overlay/usr/bin/node-red-log new file mode 100755 index 00000000..b200450e --- /dev/null +++ b/buildroot-external/rootfs-overlay/usr/bin/node-red-log @@ -0,0 +1,13 @@ +#!/bin/bash +LINES=25 +while getopts ":n:" opt; do + case $opt in + n) LINES="$OPTARG" + ;; + \?) echo "Unrecognized option -$OPTARG. Usage: node-red-log [-n lines]. For example: node-red-log -n 50" >&2 && exit 1 + ;; + esac +done +echo -e '\033]2;'Node-RED log'\007' +echo " " +sudo journalctl -f -n $LINES -u nodered -o cat diff --git a/buildroot-external/rootfs-overlay/usr/bin/node-red-reload b/buildroot-external/rootfs-overlay/usr/bin/node-red-reload new file mode 100755 index 00000000..33118009 --- /dev/null +++ b/buildroot-external/rootfs-overlay/usr/bin/node-red-reload @@ -0,0 +1,2 @@ +#!/bin/bash +sudo node-red-stop && sudo node-red-start diff --git a/buildroot-external/rootfs-overlay/usr/bin/node-red-restart b/buildroot-external/rootfs-overlay/usr/bin/node-red-restart new file mode 100755 index 00000000..bffee103 --- /dev/null +++ b/buildroot-external/rootfs-overlay/usr/bin/node-red-restart @@ -0,0 +1,3 @@ +#!/bin/bash +sudo systemctl restart nodered +echo -e "\033[1mRestarted \033[38;5;88mNode-RED\033[0m" diff --git a/buildroot-external/rootfs-overlay/usr/bin/node-red-start b/buildroot-external/rootfs-overlay/usr/bin/node-red-start new file mode 100755 index 00000000..7892c168 --- /dev/null +++ b/buildroot-external/rootfs-overlay/usr/bin/node-red-start @@ -0,0 +1,75 @@ +#!/bin/bash +# +# Copyright 2016,2020 JS Foundation and other contributors, https://js.foundation/ +# Copyright 2015,2016 IBM Corp. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +echo -e '\033]2;'Node-RED console'\007' +if [[ $(which node-red-pi) ]]; then + if [[ ! $(which npm) ]]; then + echo -e "\033[0m \033[0m" + echo -e "\033[0m npm is not installed, it is recommended \033[0m" + echo -e "\033[0m to install the latest by running: \033[0m" + echo -e "\033[0m update-nodejs-and-nodered \033[0m" + echo -e "\033[0m \033[0m" + echo -e " " + fi + HOSTIP=`hostname -I | cut -d ' ' -f 1` + if [ "$HOSTIP" = "" ]; then + HOSTIP="127.0.0.1" + fi + echo -e "\033[1mStart \033[38;5;88mNode-RED\033[0m" + echo " " + echo "Once Node-RED has started, point a browser at http://$HOSTIP:1880" + echo "On Pi Node-RED works better with the Firefox or Chrome browser" + echo " " + if groups | grep -q -w sudo; then + echo -e "Use \033[0;36mnode-red-stop\033[0m to stop Node-RED" + echo -e "Use \033[0;36mnode-red-start\033[0m to start Node-RED again" + echo -e "Use \033[0;36mnode-red-log\033[0m to view the recent log output" + fi + echo -e "Use \033[0;36msudo systemctl enable nodered.service\033[0m to autostart Node-RED at every boot" + echo -e "Use \033[0;36msudo systemctl disable nodered.service\033[0m to disable autostart on boot" + echo " " + echo "To find more nodes and example flows - go to http://flows.nodered.org" + if [ "$nv" = "v0" ]; then + echo "You may also need to install and upgrade npm" + echo -e " \033[0;36msudo apt-get install npm\033[0m" + echo -e " \033[0;36msudo npm i -g npm@2.x\033[0m" + fi + if groups $USER | grep -q -w sudo; then + # Current user is member of sudo group, start node-red through systemd + sudo systemctl start nodered + echo " " + echo "Starting as a systemd service." + sudo journalctl -f -n 0 -u nodered -o cat + elif [ $EUID -eq 0 ]; then + # Current user is root, start node-red through systemd + systemctl start nodered + echo " " + echo "Starting as root systemd service." + journalctl -f -n 0 -u nodered -o cat + else + # Start node-red as unprivileged user + echo " " + echo "Starting as a normal user." + node-red-pi + fi +else + echo "Node-RED is not yet fully installed. Please re-run the install script again manually." + echo " " + echo " bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)" + echo " " + echo "then retry node-red-start" + echo " " +fi diff --git a/buildroot-external/rootfs-overlay/usr/bin/node-red-stop b/buildroot-external/rootfs-overlay/usr/bin/node-red-stop new file mode 100755 index 00000000..50de1854 --- /dev/null +++ b/buildroot-external/rootfs-overlay/usr/bin/node-red-stop @@ -0,0 +1,8 @@ +#!/bin/bash +echo -e '\033]2;'Node-RED console'\007' +echo -e "\033[1mStop \033[38;5;88mNode-RED\033[0m" +echo " " +echo -e "Use \033[0;36mnode-red-start\033[0m to start Node-RED again" +sudo systemctl stop nodered +echo " " +exit diff --git a/buildroot-external/rootfs-overlay/usr/share/icons/hicolor/scalable/apps/node-red-icon.svg b/buildroot-external/rootfs-overlay/usr/share/icons/hicolor/scalable/apps/node-red-icon.svg new file mode 100644 index 00000000..020a9037 --- /dev/null +++ b/buildroot-external/rootfs-overlay/usr/share/icons/hicolor/scalable/apps/node-red-icon.svg @@ -0,0 +1,33 @@ + + + + Node-RED Icon + + + + image/svg+xml + + Node-RED Icon + + + + Nick O'Leary + + + + + + + + + + + + + + + + + + +