MycroftOS: Add node-red launcher scripts and service file.

This commit is contained in:
j1nx 2020-09-15 09:37:39 +02:00
parent 68a91d97bc
commit baa7435c33
7 changed files with 166 additions and 0 deletions

View File

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

View File

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

View File

@ -0,0 +1,2 @@
#!/bin/bash
sudo node-red-stop && sudo node-red-start

View File

@ -0,0 +1,3 @@
#!/bin/bash
sudo systemctl restart nodered
echo -e "\033[1mRestarted \033[38;5;88mNode-RED\033[0m"

View File

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

View File

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

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" height="480" width="480" version="1.1" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" viewBox="0 0 480.00002 479.99999">
<title>Node-RED Icon</title>
<metadata>
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
<dc:title>Node-RED Icon</dc:title>
<cc:license rdf:resource="http://creativecommons.org/licenses/by/3.0/"/>
<dc:creator>
<cc:Agent>
<dc:title>Nick O&apos;Leary</dc:title>
</cc:Agent>
</dc:creator>
</cc:Work>
<cc:License rdf:about="http://creativecommons.org/licenses/by/3.0/">
<cc:permits rdf:resource="http://creativecommons.org/ns#Reproduction"/>
<cc:permits rdf:resource="http://creativecommons.org/ns#Distribution"/>
<cc:requires rdf:resource="http://creativecommons.org/ns#Notice"/>
<cc:requires rdf:resource="http://creativecommons.org/ns#Attribution"/>
<cc:permits rdf:resource="http://creativecommons.org/ns#DerivativeWorks"/>
</cc:License>
</rdf:RDF>
</metadata>
<g transform="translate(0 -572.36)">
<rect style="color-rendering:auto;color:#000000;isolation:auto;mix-blend-mode:normal;shape-rendering:auto;solid-color:#000000;image-rendering:auto" ry="56" height="448" width="448" y="588.36" x="16" fill="#8f0000"/>
<g transform="matrix(8.545 0 0 8.545 -786.19 -1949.8)">
<path style="color-rendering:auto;text-decoration-color:#000000;color:#000000;isolation:auto;mix-blend-mode:normal;shape-rendering:auto;solid-color:#000000;block-progression:tb;text-decoration-line:none;text-decoration-style:solid;image-rendering:auto;white-space:normal;text-indent:0;text-transform:none" d="m104.41 321.21c0.0138-2.3846-1.905-4.2806-4.2896-4.2806h-6.243v2.9257h6.243c0.80513 0 1.4808 0.58383 1.4808 1.389v4.2422c0 0.80513-0.67566 1.5075-1.4808 1.5075h-6.243v2.8086h6.243c2.3846 0 4.2895-1.9315 4.2895-4.3162l-0.00005-1.9812c9.8659 0.14125 12.737 2.7065 15.877 5.4519 3.0241 2.6446 6.4153 5.4869 15.252 5.557l0.00046 0.97238c0.001 2.3846 1.9543 4.3803 4.3389 4.3803h6.4273v-3.0427h-6.4273c-0.80514 0-1.4135-0.53255-1.4135-1.3377v-4.2422c0-0.80513 0.60835-1.4418 1.4135-1.4418h6.4273v-2.8086h-6.4273c-2.3846 0-4.3379 1.8658-4.3389 4.2504l-0.00045 1.005c-8.351-0.0276-10.723-2.3434-13.76-4.9992-2.5914-2.2662-5.6368-4.7578-12.346-5.6642 0.0583-0.0501 0.11211-0.0987 0.16838-0.15027 1.2918-1.1846 1.9884-2.6158 2.6699-3.8516 0.68148-1.2357 1.3227-2.267 2.373-2.9879 0.85207-0.58483 2.0639-1.0208 3.926-1.1017l0.00018 0.99192c0.00043 2.3846 1.9236 4.4325 4.3083 4.4325h17.242c2.3846 0 4.3127-2.0479 4.3127-4.4325v-4.2422c0-2.3846-1.9281-4.3153-4.3127-4.3153h-17.242c-2.3846 0-4.3095 1.9306-4.3083 4.3153l0.00051 0.98395c-2.2474 0.0903-3.9508 0.6357-5.2079 1.4985-1.5245 1.0464-2.3662 2.4764-3.0762 3.7637-0.70992 1.2873-1.3108 2.4408-2.2188 3.2734-0.79034 0.72475-1.8834 1.2844-3.658 1.493zm18.468-12.356h17.242c0.80514 0 1.387 0.58455 1.387 1.3897v4.2422c0 0.80514-0.5819 1.3898-1.387 1.3898h-17.242c-0.80514 0-1.4994-0.58462-1.4994-1.3898v-4.2422c0-0.80513 0.69431-1.3897 1.4994-1.3897z" fill="#fff"/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.3 KiB