AppDeveloper
AppDeveloper

Reputation: 2210

Graceful degradation in a docker container

Consider the following cases when nodejs runtime crashes or is forcefully taken down, I want to do some cleanup, for instance unregistering with consul which is a service registry and discovery utility.

["exit", "SIGINT", "SIGHUP", "SIGTERM", "SIGQUIT", "SIGUSR1", "SIGUSR2", "uncaughtException"].forEach(function(value){
    process.on(value, function(){
        consul.agent.check.deregister(env.CONSUL_ID, function(error) {
            if (error) throw error;
            console.log("DeRegistered Consul.");
            process.exit(1);
        });
    })
});
  1. The signals are not firing when I take down the container (docker-compose down), however, they do fire when I run the nodejs instance in a terminal and I press Ctrl-C to force exit.

  2. Please also check on the signal cases, for instance I might not need an uncaught exception, de-registration should only happen when the whole nodejs instance goes down. Any other unnecessary signals in here or signals that I might be missing?

Edit

How do I start the container. (using docker-compose)

  dept:
    image: node:10
    container_name: dept
    working_dir: /service
    command: bash -c "npm install && npm install nodemon -g && nodemon --exec npm start"
    ports:
      - 3003:3000
      - 9232:9229
    volumes:
      - "./dept:/dept"

Upvotes: 0

Views: 283

Answers (0)

Related Questions