Created
August 24, 2015 19:18
-
-
Save Markbnj/491b45527184331d666d to your computer and use it in GitHub Desktop.
Handling command line options in bash scripts, example
This file contains 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
# Starts the elasticsearch node container, optionally setting | |
# a cluster name and host IP to expose to other nodes. Mounts | |
# the directory at /var/lib/elasticsearch to the same location | |
# on the host. | |
# | |
# exposes ports: | |
# 9200 = elasticsearch http | |
# 9300 = elasticsearch transport | |
# | |
IP="" | |
C_NAME="" | |
print_help() { | |
echo "Usage: start-container [-h 'IP_ADDRESS'] [-c CLUSTER_NAME]" | |
echo "Options:" | |
echo " -i|--hostip : host IP to expose to other es nodes" | |
echo " -c|--cluster : name of the cluster to join" | |
echo " -h|--help : print this help screen" | |
} | |
while [[ $# > 0 ]] | |
do | |
key="$1" | |
case $key in | |
-i|--hostip) | |
IP="$2" | |
shift | |
;; | |
-c|--cluster) | |
C_NAME="$2" | |
shift | |
;; | |
-h|--help) | |
print_help | |
exit 0 | |
;; | |
*) | |
echo "Unknown option $key" | |
print_help | |
exit 1 | |
;; | |
esac | |
shift | |
done | |
sudo docker run -i -t\ | |
-e "CLUSTER_NAME=$C_NAME"\ | |
-e "HOST_IP=$IP"\ | |
-v /var/lib/elasticsearch:/var/lib/elasticsearch\ | |
--name="elasticsearch" -h="es" -p 9200:9200 -p 9300:9300 feedgrub/elasticsearch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment