1

I have some NodeJS scripts, that runs 24/7 on a windows vServer. Normally I connect via RDM/VNC, open a console, navigate to the path of the script and type in "node ." to start it. Sometimes I need to check the output of that scripts and sometimes I want to restart them. Then I connect again to the server, check the shell, abort the process and restart it with "node ." again. But now I want some other people to do that too but I dont want to give them access to my server. So my plan was to do a "Managing website". But atm I have no idea how to do it. I have several problems: First, How can I start the script with "node ." in php? I tried several stuff with the exec and shell_exec command. One example:

echo shell_exec('cd C:\\Users\***\\');

echo shell_exec("node .");

But I dont even get an output back. So obviously there is something wrong. Second, every user of that website should see the same output. If someone hits the "Restart" Button (need to figure out a way how to restart it too), it should restart the same process some one else started earlier. Any idea/way to go?

Introser
  • 161
  • 1
  • 12

1 Answers1

0

Here's a possible way to handle this issue.

First, package your nodejs program as a Windows Service. Here are some suggestions about how to do that. It's not hard. How to install node.js as windows service?

Then you, or anybody else, can use these command from an elevated-priv cmd.exe or powershell, to stop and start the service.

sc.exe stop yourServiceName
sc.exe start yourServiceName

If they're on another machine and they have appropriate permissions they can do

sc.exe \\YourMachineName stop yourServiceName
sc.exe \\YourMachineName start yourServiceName

Services are also handy because you can configure them to restart if they crash. And you can configure them to start automatically when the server starts up.

O. Jones
  • 103,626
  • 17
  • 118
  • 172