Server and Host update
Keep your server up to date
by periodically updating:
- linux host
- npm
- Node-RED
- node modules
then restarting
Environmental dependencies
- apt-get
- awk
- xargs
- npm
so, basically any Debian based linux distro.
Note
Assumes that the Node-RED working directory contains the .node-red
directory. If you've used the official Linux Installers then that should be the case.
Not super secure - it requires that sudo
can be run unattended. If this is not the case, you will need to modify the flow. For example, add a node to pull the su
password from a secure store, put it in the payload sent to the exec
node, and pipe it to sudo
using the -s
flag (totally untested, and I haven't security audited Node-RED message passing so YMMV).
Will modify and restart the host, so it may affect any other services being run on it.
[{"id":"e878e7c4.d19298","type":"inject","z":"90ea6656.b27608","name":"Update schedule","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"00 04 * * 0","once":false,"onceDelay":0.1,"x":130,"y":40,"wires":[["728f7509.785c4c"]]},{"id":"eeaf2376.6451","type":"switch","z":"90ea6656.b27608","name":"failure check","property":"payload.code","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"}],"checkall":"false","repair":false,"outputs":1,"x":150,"y":400,"wires":[["8d77bbbc.c04668"]]},{"id":"8d77bbbc.c04668","type":"exec","z":"90ea6656.b27608","command":"npm update","addpay":false,"append":"","useSpawn":"false","timer":"1600","oldrc":false,"name":"npm update","x":310,"y":400,"wires":[["9562d847.2ec7e8"],["a80ca7d3.8903a8"],["551eaab8.e31784"]]},{"id":"728f7509.785c4c","type":"exec","z":"90ea6656.b27608","command":"sudo apt-get -y -q --allow-releaseinfo-change update","addpay":false,"append":"","useSpawn":"false","timer":"1600","oldrc":false,"name":"update","x":290,"y":40,"wires":[["1a17d493.51a90b"],["4b263d7f.c375b4"],["260b44d4.8673ec"]]},{"id":"551eaab8.e31784","type":"switch","z":"90ea6656.b27608","name":"failure check","property":"payload.code","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"}],"checkall":"false","repair":false,"outputs":1,"x":150,"y":520,"wires":[["69f52c9d.5fccb4"]]},{"id":"69f52c9d.5fccb4","type":"exec","z":"90ea6656.b27608","command":"cd .node-red && npm outdated | awk 'NR>1 { print $1 }' | xargs --no-run-if-empty npm install","addpay":false,"append":"","useSpawn":"false","timer":"1600","oldrc":false,"name":"palette update","x":320,"y":520,"wires":[["6c8e972e.e81968"],["6ec666a7.e148d8"],["e899996c.104138"]],"info":"update all the nodeRed nodes and packages"},{"id":"4e8894e5.7790bc","type":"switch","z":"90ea6656.b27608","name":"failure check","property":"payload.code","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"}],"checkall":"false","repair":false,"outputs":1,"x":150,"y":760,"wires":[["391204a.d5860fc"]]},{"id":"391204a.d5860fc","type":"exec","z":"90ea6656.b27608","command":"sudo shutdown -r now \"nodeRed schedueld update and restart\"","addpay":false,"append":"","useSpawn":"false","timer":"300","oldrc":false,"name":"restart","x":290,"y":760,"wires":[["25bc46f5.44889a"],["3307dc63.6b51c4"],[]]},{"id":"260b44d4.8673ec","type":"switch","z":"90ea6656.b27608","name":"failure check","property":"payload.code","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"}],"checkall":"false","repair":false,"outputs":1,"x":130,"y":160,"wires":[["c63a3e45.741fc"]]},{"id":"c2ac25f3.68e168","type":"switch","z":"90ea6656.b27608","name":"failure check","property":"payload.code","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"}],"checkall":"false","repair":false,"outputs":1,"x":130,"y":280,"wires":[["70e746e9.71d6f8"]]},{"id":"c63a3e45.741fc","type":"exec","z":"90ea6656.b27608","command":"sudo apt-get -y -q dist-upgrade","addpay":false,"append":"","useSpawn":"false","timer":"3600","oldrc":false,"name":"upgrade","x":300,"y":160,"wires":[["876b6c58.f75ea"],["c93c8f70.512b5"],["c2ac25f3.68e168"]]},{"id":"70e746e9.71d6f8","type":"exec","z":"90ea6656.b27608","command":"sudo apt-get -y -q autoclean ","addpay":false,"append":"","useSpawn":"false","timer":"900","oldrc":false,"name":"autoclean","x":300,"y":280,"wires":[["1e0c31dd.8ef55e"],["5f983eef.03c9d"],["eeaf2376.6451"]]},{"id":"4b263d7f.c375b4","type":"debug","z":"90ea6656.b27608","name":"update std err","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"payload","targetType":"msg","x":580,"y":60,"wires":[]},{"id":"1a17d493.51a90b","type":"debug","z":"90ea6656.b27608","name":"update std out","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":580,"y":20,"wires":[]},{"id":"c93c8f70.512b5","type":"debug","z":"90ea6656.b27608","name":"upgrade std err","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"payload","targetType":"msg","x":590,"y":180,"wires":[]},{"id":"876b6c58.f75ea","type":"debug","z":"90ea6656.b27608","name":"upgrade std out","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":580,"y":140,"wires":[]},{"id":"5f983eef.03c9d","type":"debug","z":"90ea6656.b27608","name":"autoclean std err","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"payload","targetType":"msg","x":590,"y":300,"wires":[]},{"id":"1e0c31dd.8ef55e","type":"debug","z":"90ea6656.b27608","name":"autoclean std out","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":590,"y":260,"wires":[]},{"id":"a80ca7d3.8903a8","type":"debug","z":"90ea6656.b27608","name":"npm update std err","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"payload","targetType":"msg","x":600,"y":420,"wires":[]},{"id":"9562d847.2ec7e8","type":"debug","z":"90ea6656.b27608","name":"npm update std out","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":590,"y":380,"wires":[]},{"id":"6ec666a7.e148d8","type":"debug","z":"90ea6656.b27608","name":"palette update std err","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"payload","targetType":"msg","x":610,"y":540,"wires":[]},{"id":"6c8e972e.e81968","type":"debug","z":"90ea6656.b27608","name":"palette update std out","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":600,"y":500,"wires":[]},{"id":"3307dc63.6b51c4","type":"debug","z":"90ea6656.b27608","name":"restart std err","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"payload","targetType":"msg","x":580,"y":780,"wires":[]},{"id":"25bc46f5.44889a","type":"debug","z":"90ea6656.b27608","name":"restart std out","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":580,"y":740,"wires":[]},{"id":"e899996c.104138","type":"switch","z":"90ea6656.b27608","name":"failure check","property":"payload.code","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"}],"checkall":"false","repair":false,"outputs":1,"x":150,"y":640,"wires":[["b7d28e44.e79e"]]},{"id":"b7d28e44.e79e","type":"exec","z":"90ea6656.b27608","command":"cd .node-red && npm audit fix","addpay":false,"append":"","useSpawn":"false","timer":"1600","oldrc":false,"name":"npm audit","x":300,"y":640,"wires":[["ee8d4184.1e0b1"],["9b599588.8a00b8"],["4e8894e5.7790bc"]],"info":"update all the nodeRed nodes and packages"},{"id":"9b599588.8a00b8","type":"debug","z":"90ea6656.b27608","name":"npm audit std err","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"payload","targetType":"msg","x":590,"y":660,"wires":[]},{"id":"ee8d4184.1e0b1","type":"debug","z":"90ea6656.b27608","name":"npm audit std out","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":590,"y":620,"wires":[]}]