# Graceful process shutdown for overridden commands

**URL:** <https://community.convox.com/t/graceful-process-shutdown-for-overridden-commands/497>\
**Category:** Configuration\
**Created:** [April 22, 2019, 9:00pm UTC](https://community.convox.com/t/graceful-process-shutdown-for-overridden-commands/497 "2019-04-22T21:00:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sparky](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@sparky](https://community.convox.com/u/sparky)\
**Post date:** [April 22, 2019, 9:00pm UTC](https://community.convox.com/t/graceful-process-shutdown-for-overridden-commands/497/1 "2019-04-22T21:00:49Z")

</div>

I have a ruby app where we have several services all built off a single Docker image - my `convox.yml` has under each non-default service, such as a background worker, an entry like:

```auto
build: . 
command: bundle exec resque-pool

```

When it gets terminated (eg during a deploy), it does not seem to be gracefully shutting down (ECS/docker should be sending a SIGTERM), here’s the process tree:

```auto
  PID TTY STAT TIME COMMAND
    1 ? Ss 0:06 /dev/init -- /convox-env sh -c bundle exec resque-pool
    6 ? S 0:00 sh -c bundle exec resque-pool
   12 ? Sl 0:53 \_ resque-pool-master[app]: managing [14]
   14 ? Sl 2:34 \_ resque-1.25.2: Waiting for *

```

If a convox service does not have a command in `convox.yml`, as in something that uses the default `CMD` from the `Dockerfile`, it will set that process as PID 1, allowing it to get the signal as expected and gracefully shutdown. I’ve also tried using the [docker init process](https://docs.convox.com/application/services#init), but that didn’t change how the command was run.

Any tricks for being able to trap & handle the signal or otherwise be able for these to gracefully terminate? I suppose I could make a separate `Dockerfile` for each service, but that would be a bit of duplication.

---

<div class="post-metadata">

**Author:** ![sparky](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@sparky](https://community.convox.com/u/sparky)\
**Post date:** [April 24, 2019, 2:26am UTC](https://community.convox.com/t/graceful-process-shutdown-for-overridden-commands/497/2 "2019-04-24T02:26:33Z")

</div>

I’ve found something that can work for what I want - using the `exec` shell built in as part of the convox command override works. For example, for a service in `convox.yml`

```auto
command: exec bundle exec puma

```

Will result in a docker container like this with the command as PID 1 as I want it. This also works when using docker init.

```auto
# ps axf
  PID TTY STAT TIME COMMAND
  353 pts/0 Ss 0:00 sh -c bash
  365 pts/0 S 0:00 \_ bash
  393 pts/0 R+ 0:00 \_ ps axf
    1 ? Ssl 0:04 puma 3.12.1 (tcp://0.0.0.0:9292) [app]

```
