Created
June 10, 2016 05:34
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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