show status, enable and disable a list of services

This short snippet will create an ui_list object showing the active status of your services. Click the entry to start/stop the service.

Change the list of services at the "list"-function:

var services = ["apache2","smbd","mysql","minidlna","mosquitto","nginx"]

Only installed services will be shown.

[{"id":"55045ca0.144814","type":"exec","z":"6ac941ca.614be","command":"sudo systemctl status","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"status","x":390,"y":500,"wires":[["60cb1847.868eb8"],[],["872e1cf3.68764"]]},{"id":"872e1cf3.68764","type":"debug","z":"6ac941ca.614be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":530,"y":650,"wires":[]},{"id":"3473ce65.4bc3d2","type":"inject","z":"6ac941ca.614be","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":65,"y":500,"wires":[["6d066453.f9d03c"]],"l":false},{"id":"6d066453.f9d03c","type":"function","z":"6ac941ca.614be","name":" list","func":"var services    = [\"apache2\",\"smbd\",\"mysql\",\"minidlna\",\"mosquitto\",\"nginx\"]\n\nflow.services   = flow.services || {}\nfor (i=0; i<services.length; i++)\n    flow.services[services[i]] = {\"title\":services[i]}\n    \nmsg.payload     = services;\nreturn msg;","outputs":1,"noerr":0,"x":150,"y":500,"wires":[["41f527d7.93e908"]]},{"id":"60cb1847.868eb8","type":"function","z":"6ac941ca.614be","name":"parse","func":"flow.services               = flow.services || {}\n\nvar obj                     = {}\nvar parts                   = msg.payload.split(\"\\n\")\nobj.description             = parts[0].split(\"-\")[1]\nobj.title                   = parts[0].split(\" \")[1].split(\".\")[0]\nobj.isChecked               = (msg.rc.code === 0)\n\nflow.services[obj.title]    = obj\n\nmsg.payload                 = flow.services;\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":500,"wires":[["6f09b813.090888"]]},{"id":"6f09b813.090888","type":"ui_list","z":"6ac941ca.614be","group":"d608a2cd.4f776","name":"list","order":0,"width":"10","height":"10","lineType":"three","actionType":"switch","allowHTML":false,"x":630,"y":500,"wires":[["daa65601.89df78"]]},{"id":"41f527d7.93e908","type":"split","z":"6ac941ca.614be","name":"split","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":270,"y":500,"wires":[["55045ca0.144814"]]},{"id":"daa65601.89df78","type":"function","z":"6ac941ca.614be","name":"join","func":"msg.topic   = msg.payload.title\nmsg.payload = (msg.payload.isChecked===true ? \"start \" : \"stop \") + msg.topic\nreturn msg;","outputs":1,"noerr":0,"x":750,"y":500,"wires":[["48893cc1.530ff4"]]},{"id":"48893cc1.530ff4","type":"exec","z":"6ac941ca.614be","command":"sudo systemctl","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"set","x":870,"y":500,"wires":[["e5a7faa4.dc3c78"],[],[]]},{"id":"e5a7faa4.dc3c78","type":"function","z":"6ac941ca.614be","name":"","func":"msg.payload = [msg.topic]\nreturn msg;","outputs":1,"noerr":0,"x":990,"y":500,"wires":[["41f527d7.93e908"]]},{"id":"d608a2cd.4f776","type":"ui_group","z":"","name":"Services","tab":"6dc044a5.dba27c","disp":true,"width":"15","collapse":true},{"id":"6dc044a5.dba27c","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":true}]

Flow Info

Created 7 years, 6 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • debug (x1)
  • exec (x2)
  • function (x4)
  • inject (x1)
  • split (x1)
Other

Tags

  • services
  • dashboard
  • rpi
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option