How to run script from node-red?

I have a simple script that restarts the zigbee2mqtt.service
The script is located on "Orange pi zero" where is installed the "Node -red".
code of script

#!/usr/bin/env bash

systemctl restart zigbee2mqtt

But I can't run the script.
my flow

[{"id":"2f448a0f.d879a6","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"4cc56c86.93ae84","type":"exec","z":"2f448a0f.d879a6","command":"systemctl restart zigbee2mqtt","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Restart zigbee2mqtt","x":570,"y":200,"wires":[["a023a041.f66a3"],["a023a041.f66a3"],["a023a041.f66a3"]]},{"id":"9877c52a.07c6e8","type":"inject","z":"2f448a0f.d879a6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":310,"y":200,"wires":[["4cc56c86.93ae84"]]},{"id":"a023a041.f66a3","type":"debug","z":"2f448a0f.d879a6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":850,"y":200,"wires":[]}]

Also I tried like that

[{"id":"2f448a0f.d879a6","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"4cc56c86.93ae84","type":"exec","z":"2f448a0f.d879a6","command":"/home/zerg/.scrtipts/restart_zigbee2mqtt.sh","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Restart zigbee2mqtt","x":570,"y":200,"wires":[["a023a041.f66a3"],["a023a041.f66a3"],["a023a041.f66a3"]]},{"id":"9877c52a.07c6e8","type":"inject","z":"2f448a0f.d879a6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":310,"y":200,"wires":[["4cc56c86.93ae84"]]},{"id":"a023a041.f66a3","type":"debug","z":"2f448a0f.d879a6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":850,"y":200,"wires":[]}]

What am I doing wrong?

I think that would need to run as root as it is a system type command.

I tried with sudo in node of "exec" and also in script, doesn't help! Probably i do something wrong.

No. If Node-RED is running as a normal user it can’t just call sudo as that is a privilege escalation security issue. There are lots of threads in this forum on how to allow this to happen safely.

I would be grateful if you will help me or hint how to find a solution!

In fairness, this is more an OS question than node red and has been covered here a lot - search this forum.

Perhaps, better still, search Google for "systemctl restart without sudo" first 2 or 3 results have some really good info.

1 Like

Also search the forum for visudo which can enable you to use sudo with a command without having to enter a password, so it can be run from an exec node.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.