run pm2 from remote shell script
I am trying to write a script which ssh into a bunch of my servers and runs some commands to start my app. One of the commands (pm2) always says pm2: command not found. This is how I'm attempting this:
ssh -o StrictHostKeyChecking=no -i /Path/to/key-pair.pem ubuntu@${ec2ips[i]} 'bash ' << 'STARTAPP'
cd ~/my-app-folder
pm2 start ./bin/www --name 'my-app'
exit
STARTAPP
when I ssh in normally, all pm2 commands run fine. If I ssh in and run a script with pm2 in it, it also works as expected. It's only when I try and run it on a remote machine from my machine.
shell-script remote
add a comment |
I am trying to write a script which ssh into a bunch of my servers and runs some commands to start my app. One of the commands (pm2) always says pm2: command not found. This is how I'm attempting this:
ssh -o StrictHostKeyChecking=no -i /Path/to/key-pair.pem ubuntu@${ec2ips[i]} 'bash ' << 'STARTAPP'
cd ~/my-app-folder
pm2 start ./bin/www --name 'my-app'
exit
STARTAPP
when I ssh in normally, all pm2 commands run fine. If I ssh in and run a script with pm2 in it, it also works as expected. It's only when I try and run it on a remote machine from my machine.
shell-script remote
add a comment |
I am trying to write a script which ssh into a bunch of my servers and runs some commands to start my app. One of the commands (pm2) always says pm2: command not found. This is how I'm attempting this:
ssh -o StrictHostKeyChecking=no -i /Path/to/key-pair.pem ubuntu@${ec2ips[i]} 'bash ' << 'STARTAPP'
cd ~/my-app-folder
pm2 start ./bin/www --name 'my-app'
exit
STARTAPP
when I ssh in normally, all pm2 commands run fine. If I ssh in and run a script with pm2 in it, it also works as expected. It's only when I try and run it on a remote machine from my machine.
shell-script remote
I am trying to write a script which ssh into a bunch of my servers and runs some commands to start my app. One of the commands (pm2) always says pm2: command not found. This is how I'm attempting this:
ssh -o StrictHostKeyChecking=no -i /Path/to/key-pair.pem ubuntu@${ec2ips[i]} 'bash ' << 'STARTAPP'
cd ~/my-app-folder
pm2 start ./bin/www --name 'my-app'
exit
STARTAPP
when I ssh in normally, all pm2 commands run fine. If I ssh in and run a script with pm2 in it, it also works as expected. It's only when I try and run it on a remote machine from my machine.
shell-script remote
shell-script remote
asked Jun 29 '16 at 2:12
user137717user137717
1062
1062
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
When you run an interactive shell it sets the PATH variable according to your "rc" files (e.g .bash_profile). When you run that "non-interactive" ssh command then many of these scripts aren't run and so PATH isn't set.
You should include the pathname to pm2
even if it is the current directory (eg ./pm2
or /path/to/pm2
) to ensure it is found, or else export PATH=....
before the call to pm2
.
i did 'which pm2' which should get me the path to the executable, correct me if i'm wrong. then i tried doing /home/ubuntu/.nvm/versions/node/v6.0.0/bin/pm2 start ./bin/www --name 'my-app' but that is still giving me command not found. did i misunderstand your solution?
– user137717
Jun 29 '16 at 4:50
The point is your execution environments are different; doespm2
use other variables to find things? Login and run theenv
command and compare that tossh server env
; there will be a LOT of differences. Do any of those variables impact the execution of the command?
– Stephen Harris
Jun 29 '16 at 12:38
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f292740%2frun-pm2-from-remote-shell-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
When you run an interactive shell it sets the PATH variable according to your "rc" files (e.g .bash_profile). When you run that "non-interactive" ssh command then many of these scripts aren't run and so PATH isn't set.
You should include the pathname to pm2
even if it is the current directory (eg ./pm2
or /path/to/pm2
) to ensure it is found, or else export PATH=....
before the call to pm2
.
i did 'which pm2' which should get me the path to the executable, correct me if i'm wrong. then i tried doing /home/ubuntu/.nvm/versions/node/v6.0.0/bin/pm2 start ./bin/www --name 'my-app' but that is still giving me command not found. did i misunderstand your solution?
– user137717
Jun 29 '16 at 4:50
The point is your execution environments are different; doespm2
use other variables to find things? Login and run theenv
command and compare that tossh server env
; there will be a LOT of differences. Do any of those variables impact the execution of the command?
– Stephen Harris
Jun 29 '16 at 12:38
add a comment |
When you run an interactive shell it sets the PATH variable according to your "rc" files (e.g .bash_profile). When you run that "non-interactive" ssh command then many of these scripts aren't run and so PATH isn't set.
You should include the pathname to pm2
even if it is the current directory (eg ./pm2
or /path/to/pm2
) to ensure it is found, or else export PATH=....
before the call to pm2
.
i did 'which pm2' which should get me the path to the executable, correct me if i'm wrong. then i tried doing /home/ubuntu/.nvm/versions/node/v6.0.0/bin/pm2 start ./bin/www --name 'my-app' but that is still giving me command not found. did i misunderstand your solution?
– user137717
Jun 29 '16 at 4:50
The point is your execution environments are different; doespm2
use other variables to find things? Login and run theenv
command and compare that tossh server env
; there will be a LOT of differences. Do any of those variables impact the execution of the command?
– Stephen Harris
Jun 29 '16 at 12:38
add a comment |
When you run an interactive shell it sets the PATH variable according to your "rc" files (e.g .bash_profile). When you run that "non-interactive" ssh command then many of these scripts aren't run and so PATH isn't set.
You should include the pathname to pm2
even if it is the current directory (eg ./pm2
or /path/to/pm2
) to ensure it is found, or else export PATH=....
before the call to pm2
.
When you run an interactive shell it sets the PATH variable according to your "rc" files (e.g .bash_profile). When you run that "non-interactive" ssh command then many of these scripts aren't run and so PATH isn't set.
You should include the pathname to pm2
even if it is the current directory (eg ./pm2
or /path/to/pm2
) to ensure it is found, or else export PATH=....
before the call to pm2
.
answered Jun 29 '16 at 2:22
Stephen HarrisStephen Harris
25.5k24477
25.5k24477
i did 'which pm2' which should get me the path to the executable, correct me if i'm wrong. then i tried doing /home/ubuntu/.nvm/versions/node/v6.0.0/bin/pm2 start ./bin/www --name 'my-app' but that is still giving me command not found. did i misunderstand your solution?
– user137717
Jun 29 '16 at 4:50
The point is your execution environments are different; doespm2
use other variables to find things? Login and run theenv
command and compare that tossh server env
; there will be a LOT of differences. Do any of those variables impact the execution of the command?
– Stephen Harris
Jun 29 '16 at 12:38
add a comment |
i did 'which pm2' which should get me the path to the executable, correct me if i'm wrong. then i tried doing /home/ubuntu/.nvm/versions/node/v6.0.0/bin/pm2 start ./bin/www --name 'my-app' but that is still giving me command not found. did i misunderstand your solution?
– user137717
Jun 29 '16 at 4:50
The point is your execution environments are different; doespm2
use other variables to find things? Login and run theenv
command and compare that tossh server env
; there will be a LOT of differences. Do any of those variables impact the execution of the command?
– Stephen Harris
Jun 29 '16 at 12:38
i did 'which pm2' which should get me the path to the executable, correct me if i'm wrong. then i tried doing /home/ubuntu/.nvm/versions/node/v6.0.0/bin/pm2 start ./bin/www --name 'my-app' but that is still giving me command not found. did i misunderstand your solution?
– user137717
Jun 29 '16 at 4:50
i did 'which pm2' which should get me the path to the executable, correct me if i'm wrong. then i tried doing /home/ubuntu/.nvm/versions/node/v6.0.0/bin/pm2 start ./bin/www --name 'my-app' but that is still giving me command not found. did i misunderstand your solution?
– user137717
Jun 29 '16 at 4:50
The point is your execution environments are different; does
pm2
use other variables to find things? Login and run the env
command and compare that to ssh server env
; there will be a LOT of differences. Do any of those variables impact the execution of the command?– Stephen Harris
Jun 29 '16 at 12:38
The point is your execution environments are different; does
pm2
use other variables to find things? Login and run the env
command and compare that to ssh server env
; there will be a LOT of differences. Do any of those variables impact the execution of the command?– Stephen Harris
Jun 29 '16 at 12:38
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f292740%2frun-pm2-from-remote-shell-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown