dasuchin / grunt-ssh-deploy

Grunt SSH Deployment
MIT License
66 stars 45 forks source link

Not executing after_deploy, nor releases_to_keep #26

Closed jsgv closed 9 years ago

jsgv commented 9 years ago

I have an after_deploy command that is not being triggered correctly. Output says it is

--------------- RUNNING PRE-DEPLOY COMMANDS

--- kill -KILL `ps o pid= -C main`

--------------- CREATING NEW RELEASE

--- cd /var/www && mkdir -p releases/20150320151525912

--------------- UPLOADING NEW BUILD

--- DONE UPLOADING

--------------- UPDATING SYM LINK

--- rm -rf /var/www/current && cd /var/www && ln -s releases/20150320151525912 current

--------------- RUNNING POST-DEPLOY COMMANDS

--- cd /var/www/current && go build main.go && nohup ./main &

But I am not getting anything on the directory.

And releases_to_keep is not removing any releases.

The Gruntfile

enviroments: {
  options: {
    privateKey: key,
    username: username,
    host: host,
    deploy_path: '/var/www',
    local_path: 'dist',
    releases_to_keep: 2
  },
  production: {
    options: {
      before_deploy: 'kill -KILL `ps o pid= -C main`',
      after_deploy: 'cd /var/www/current && go build main.go && nohup ./main &',
    }
  }
}
hurricane766 commented 9 years ago

You can see more information if you run the grunt task with the --debug option.

grunt ssh_deploy:production --debug

jsgv commented 9 years ago

Thanks @hurricane766

Output with --debug flag

Running "ssh_deploy:production" (ssh_deploy) task
[D] Task source: /path/to/node_modules/grunt-ssh-deploy/tasks/ssh_deploy.js

Connecting :: ###.###.###.##

Connected :: ###.###.###.##

--------------- RUNNING PRE-DEPLOY COMMANDS

--- kill -KILL `ps o pid= -C main`
[D] REMOTE: kill -KILL `ps o pid= -C main`

--------------- CREATING NEW RELEASE

--- cd /var/www && mkdir -p releases/20150320160417730
[D] REMOTE: cd /var/www && mkdir -p releases/20150320160417730

--------------- UPLOADING NEW BUILD
[D] SCP FROM LOCAL: dist
 TO REMOTE: /var/www/releases/20150320160417730/

--- DONE UPLOADING

--------------- UPDATING SYM LINK

--- rm -rf /var/www/current && cd /var/www && ln -s releases/20150320160417730 current
[D] REMOTE: rm -rf /var/www/current && cd /var/www && ln -s releases/20150320160417730 current

--------------- RUNNING POST-DEPLOY COMMANDS

--- cd /var/www/current && go build main.go && nohup ./main &
[D] REMOTE: cd /var/www/current && go build main.go && nohup ./main &
hurricane766 commented 9 years ago

Does the symlink get created? In other words, is /var/www/current pointing to the proper release directory?

Does the program exit after the RUNNING POST-DEPLOY COMMANDS section? Or does it just hang there?

It doesn't look like it's getting to the keep releases part at all.

What happens if after it fails, you manually ssh onto that machine and try running those post deploy commands?

athinktank commented 9 years ago

Similar issue, we are getting to the REMOVING OLD BUILDS section, but no release directories are being deleted. Tested the command from the command line under the same user as grunt is using, and the line of code performs as expected. any clues? There is no other output under the remote command when running grunt -v -d.

Thanks.

--------------- REMOVING OLD BUILDS

--- rm -rf ls -r /var/www/html/my_site/releases/ | awk 'NR>5' [D] REMOTE: rm -rf ls -r /var/www/html/mysite/releases/ | awk 'NR>5'

hurricane766 commented 9 years ago

@athinktank I've been having the same experience lately. I tried changing rm -rf to rm -rfv and got no more information, so clearly it's not running at all.

I can get the ls section to return display results but the rm will not execute.

hurricane766 commented 9 years ago

I think I've got it. The issue was the working directory is not the releases directory, so rm was just getting the name (not the full path) of the release directories but they don't exist in the current working directory so rm was doing nothing.

I can't do a pull request right now but the command in remoteCleanup should change to: var command = "cd " + options.deploy_path + "/releases/ && rm -rfvls -r " + options.deploy_path + "/releases/ | awk 'NR>" + options.releases_to_keep + "'";

I added a -v to the rm so you can see the delete happening now.

athinktank commented 9 years ago

Thanks @hurricane766 . I've tried it and it does the trick for me as well! Thanks again.