Node-red command in linux shell doesn't work in script

Hello,

I installed Node-RED on CenOS 7 web server.
Node-RED works fine, but I happen to reload the Apache server and then Node-RED.

I want to write a script to reload Apache and Node-RED :

# !/bin/bash
systemctl restart httpd
node-red&
PID=$!
sleep 5
kill $PID
disown -h

The problem is the Linux console warns the node-red command is unknown.

What am I doing wrong?

Thanks!

I use RaspberryPiOS not CenOS so this may not be available to you, but the NR installation script creates and enables a systemd script.

So I can restart Node-red with systemctl restart nodered

ps Does your #! /bin/bash line work with a space between the hash and the bang?

Hello,

Thanks for your reply!

Apparently, the Node-RED restart works with this command, but with "node-red" instead of "nodered"!

#!/bin/bash        #Yes, there was a space in my last post, but it wasn't in my script!

systemctl restart httpd
systemctl restart node-red
PID=$!
sleep 2
kill $PID
disown -h

I have another problem by the way: in this script, I want to kill de $PID because I have to press CTRL+C after the Node-RED restart. The GNU/Linux console replies:

kill : man kill page
line 8 : disown : current : unknown task (not sure about the translation from French)

Any tip?

I had to look up the meaning of $! - it's the PID of the last background process created.
As far as I can see, your script doesn't create any background processes, though your original version with node-red& did.
This might explain the problem with disown -h too.

So I suggest you get rid of

PID=$!
sleep 2
kill $PID
disown -h

If after doing that you still "have to press CTRL+C after the Node-RED restart", there is something wrong with your systemd script.

Your installation is not standard. Did the "official" installation instructions for CentOS https://github.com/node-red/linux-installers not work for you?
Did you follow some online tutorial? Why and which one?

Hello,

Thanks for you reply!

Thinking about the information you provided, I modified the script:

#!/bin/bash
systemctl restart httpd
systemctl restart node-red

I loaded the script and, apparently, it worked, with no error message.

Good news :grinning:

I still think you are storing up trouble for the future by not using the standard installation script.