teambition / gulp-ssh

SSH and SFTP tasks for gulp
184 stars 38 forks source link

Executing remote `bash` scrip #52

Closed ktamiola closed 8 years ago

ktamiola commented 8 years ago

Hello there!

I am having an issue with executing a remote bash script. The script itself (attached below) works like a charm on the server.

#!/bin/bash

 #
 #   build cipchduyg0000x6royxfkchrn @ Sun Jun 12 2016 13:01:46 GMT+0200 (CEST)
 #

 DIR = /var/www/meteor/pepkalc/
 tar xvfz /var/www/meteor/pepkalc/pepkalc.tar.gz
 if [ -d $DIR ]; then
    cd /var/www/meteor/pepkalc/bundle/programs/server
    rm -rf node_modules
    npm install --silent
    # rm -rf /var/www/meteor/pepkalc/pepkalc.tar.gz
    chown -R meteor:meteor /var/www/meteor/pepkalc/
    chmod -R 755 /var/www/meteor/pepkalc/
    restart pepkalc || start pepkalc
    exit 0
 fi
 exit 0

I have tried both exec and shell with gulp-ssh in the following gulp task,

gulp.task('deploy:install', function() {
    return ssh.shell(
            ['bash -f ' + sandboxDir + 'install.com'], {
                filePath: buildVersion + '.log'
            })
        .pipe(gulp.dest('logs'));
});

however, gulp-ssh shell simply hangs upon the execution:

kamil@Kamils-iMac:~/Development/meteor/pepkalc/.install$ gulp deploy:install
[13:07:15] Using gulpfile ~/Development/meteor/pepkalc/.install/gulpfile.js
[13:07:15] Starting 'deploy:install'...
[13:07:16] gulp-ssh :: shell :: bash -f /var/www/meteor/pepkalc/install.com

whereas gulp-ssh exec reports an error,

kamil@Kamils-iMac:~/Development/meteor/pepkalc/.install$ gulp deploy:install
[13:08:32] Using gulpfile ~/Development/meteor/pepkalc/.install/gulpfile.js
[13:08:32] Starting 'deploy:install'...
[13:08:33] gulp-ssh :: Executing :: bash -f /var/www/meteor/pepkalc/install.com

events.js:141
      throw er; // Unhandled 'error' event
      ^
Error: /var/www/meteor/pepkalc/install.com: line 9: DIR: command not found

Question is, what's wrong with my scripting?

zensh commented 8 years ago

I have tested a simple bash script with shell, it worked.

The script:

echo 'hello'
ktamiola commented 8 years ago

Problem solved. It was an issue at my end. Thanks for the feedback @zensh Apparently, the npm install part of my bash script sends non-zero exit code when it stumbles upon warnings during the installation of auxiliary packages. This was causing the script to hang.