Jump to content

Recommended Posts

Posted (edited)

Hi,

I am on Tommy server and I use npm version 23.5.0. I want to run npm script after pulling the code from github, I have entered npm run-script build in "Deploy action"

image.thumb.png.fb473dbf4c98b025b65cdd3fc1a1a81c.png

But I got the error " line 1: nodenv: command not found ". Can you tell me how to run the command "npm run-script build" right after pull?

image.thumb.png.44ab6df92e0b6ce6c646882094d3a760.png

Best regards

Edited by mbo
Forgot to mention name of the server and npm version
Posted

You can't. The system jails your commands to your home folder for security, so it can't see npm.

You can run npm commands through Plesk, but you have to do it using the node toolkit. You can't call the binaries directly, so an automation like this won't work.

Posted

Hi @wolstech

Thank you for your answer. Do you have any suggestion to solve my issue?

If I create a shell script that calls npm and I call the shell script in git deploy action, will I have same problem?

Best regards

Posted (edited)

I've asked in a staff channel for you, but I'm not sure there is a solution that will work on the Plesk boxes. Assuming that's the case, the only option that will offer the flexibility to automate this is going to be a VPS.

EDIT: The response I received suggested writing a CGI script in your language of choice that calls npm, and calling that through curl. It's a bit of a roundabout solution, but might be worth a try. You'll need to create a scheduled task in Plesk and run it once (it can be anything, even something like echo "Hello world"). After that, curl should be available to git, along with a bunch of other common linux commands. You can use curl to call the CGI script via URL, which will cause Apache to run the handler for the cgi, which will in turn run npm outside of the jail. Curl should return the output of the cgi script, so assuming its coded to echo the results of npm, it can be retrieved by curl and logged.

Edited by wolstech
Posted

Thank you for this update @wolstech for this update I think it worked. I just need to trigger Node JS app restart after the build in CGI script. If you have any suggestion to do that it will be more than welcome 😄 otherwise I will google for it.

By the way happy new year to all the team 🎉🎊

Posted

Here is the final final solution

image.png.ecfa4781aa9ab34d5a45d94eec0b694f.png

Here is the detail

1. wget --header="TOKEN:secured_token" "http://mbo.helioho.st/cgi-bin/my_script_for_build.py" : this cgi script contains the commands that run "npm install" + "npm run build"

2. touch tmp/restart.txt : after "npm run build" I need to restart the Node JS application, according to Plesk documentation it can be done by creating a file named "restart.txt" in folder "tmp"

3. wget "http://mbo.helioho.st/api/version" : when creating the file "tmp/restart.txt" the server will restart after the next request, that's why I immediately send a request to my application in order it to restart immediately after my new build

  • Like 1
Posted

Glad to hear you got it working and thanks for posting the solution! :) The information posted will be helpful to others if they ever want to do the same thing.

Please let us know if you need anything else.

  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...