#!/bin/sh handle_signal (){ echo "received signal, passing SIGTERM" kill -s SIGTERM `ps -o pid | tail -n + 2 | xargs` } trap "handle_signal" SIGINT SIGTERM SIGHUP if [[ "$1" == "service" ]] ; then # do your stuff echo "Starting $1" else # Run custom command echo "Running $@" exec "$@" fi