2

I’m using Deployer to SSH onto a server and run some scripts for deployment. I don’t know the very internal details about how Deployer is executing ssh.

The problem is it only has a fragment of $PATH which means the binary required for deployment cannot be found. I tried adding a new test variable $FOO into all the files I can think of to see which one gets loaded:

  • ~/.bash_profile
  • ~/.bashrc
  • ~/.profile
  • /etc/profile
  • /etc/bash.bashrc

with:

...


export FOO="etcprofile"

but none of them works since the value of $FOO is empty when running Deployer.

I also checked the flags and the command in Deployer and there doesn't seem to be anything out of the ordinary:

deploy.php

task('debug:print', function () use($stage) {
    run('echo $PATH');
    run('echo $SHELL');
    run('export');
    dump($stage->getShellCommand());
    dump($stage->getSshArguments());
    exit("DONE");
});

output

falnyr@local:/Projects/deployer-app $ dep deploy stage-server -vvv
➤ Executing task debug:print
[stage-server] > echo $PATH
[stage-server] < ssh multiplexing initialization
[stage-server] < Linux stage-server xxx x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

[stage-server] < /usr/local/bin:/usr/bin:/bin:/usr/games
[stage-server] > echo $SHELL
[stage-server] < /bin/bash
[stage-server] > export
[stage-server] < declare -x HOME="/home/admin"
[stage-server] < declare -x LANG="en_US.UTF-8"
[stage-server] < declare -x LC_CTYPE="en_NZ.UTF-8"
[stage-server] < declare -x LOGNAME="admin"
[stage-server] < declare -x MAIL="/var/mail/admin"
[stage-server] < declare -x OLDPWD
[stage-server] < declare -x PATH="/usr/local/bin:/usr/bin:/bin:/usr/games"
[stage-server] < declare -x PWD="/home/admin"
[stage-server] < declare -x SHELL="/bin/bash"
[stage-server] < declare -x SHLVL="2"
[stage-server] < declare -x SSH_CLIENT="xxx.xxx.xxx.xxx 62738 22"
[stage-server] < declare -x SSH_CONNECTION="xxx.xxx.xxx.xxx 62738 xxx.xxx.xxx.xxx 22"
[stage-server] < declare -x USER="admin"
[stage-server] < declare -x XDG_RUNTIME_DIR="/run/user/1000"
[stage-server] < declare -x XDG_SESSION_ID="xxxxxx"
[stage-server] < declare -x _="/bin/bash"
"bash -s"
Deployer\Ssh\Arguments {#166
  -flags: []
  -options: []
}
DONE

I also have another server with a similar configuration which seems to be working well. I'm not sure what to look for to identify the difference in the configuration.

Jan Richter
  • 1,976
  • 4
  • 29
  • 49

1 Answers1

0

Scripts don't source your profile unless their shebang is like #!/bin/bash -i or they include a line like . $HOME/.profile above the lines that would use your variables.

Don't expect aliases to work, though. Functions are better.

A final thought: running shell scripts from a web server is rather risky. It's the same a making system calls; there's a risk somebody can manipulate it to get a shell and then wreck havoc on your system.

Adam Katz
  • 14,455
  • 5
  • 68
  • 83
  • The problem was with the usage of `bash -s` which accepts the commands from stdin and also maybe multiplexing. This is not a shell but a PHP script. I get the general concern with deployments this way - it's something I cannot change as easily at this very moment though. I am going to wait if somebody posts an answer that explains why the profile is not getting loaded or where is the `$PATH` actually coming from for bash. – Jan Richter Apr 06 '20 at 20:11