Skip to content

Instantly share code, notes, and snippets.

@ankon
Created June 10, 2016 05:34
Show Gist options
  • Save ankon/06c12bf6de01deb008f8453eade88dfe to your computer and use it in GitHub Desktop.
Save ankon/06c12bf6de01deb008f8453eade88dfe to your computer and use it in GitHub Desktop.
No-frills init/rc replacement for running SysV services in a docker container
#!/bin/sh
# This is a wrapper script around a regular SysV service
_services=
while [ $# -gt 0 ]; do
if [ -x "$1" ]; then
_service=$1
shift
else
echo "ERROR: Cannot find $1 in the image" >&2
exit 1
fi
_services="${_services} ${_service}"
done
shutdown() {
_reverse_services=`echo ${_services} | tr ' ' '\n' | awk '{a[i++]=$0} END {for (j=i-1; j>=0;) print a[j--] }'`
for _service in ${_reverse_services}; do
"${_service}" stop
done
}
trap shutdown EXIT
# Execute the commands given
for _service in ${_services}; do
"${_service}" start
done
# And wait ...
while sleep 1000; do :; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment