2

I'm using AWS CodeDeploy in which server running on pm2 dose not work due to explanation given here in troubleShoot documentation.

I followed the documentation and in AfterInstall script used node . > /dev/null 2> /dev/null < /dev/null & to run the node server in the background.

I've tried following ways to kill the server

  • fuser -k 3000/tcp

  • lsof -P | grep ':3000' | awk '{print $2}' | xargs kill -9

  • kill -9 $(lsof -t -i:3000)

but each time a new process respwans with a different PID.

How can I kill this background process and add it to the ApplicationStop script for CodeDeploy?

Ninz
  • 349
  • 5
  • 13
  • You need to add an applicationstop hook with your killing srcript. It'll be called when stopping the CodeDeploy service. See http://stackoverflow.com/questions/27923991/amazon-web-service-codedeploy-appspec-yml-problems – xvan Mar 08 '16 at 12:03
  • @xvan: I have added ApplicationStop script in which I was trying the above commands. – Ninz Mar 14 '16 at 14:23

2 Answers2

3

One of the problems with finding a pid with grep is that the grep pid will also show up as a result and can kill itself before the target, so try;

ps ax | grep node | grep -v grep

if it looks reasonable, review this;

ps ax | grep node | grep -v grep | awk '{print $1}'

then run the kill;

ps ax | grep node | grep -v grep | awk '{print $1}' | xargs kill -9

pkill is a less flexible option (no regex filtering) but if you use that be sure to use the -I flag so you don't kill anything you did not intend to.

user1133275
  • 2,642
  • 27
  • 31
1

I was able to kill using pkill node command.

Ninz
  • 349
  • 5
  • 13