From e7871f5ede7c97592de91c6feb952cfac409af4f Mon Sep 17 00:00:00 2001 From: Shuai Lin Date: Mon, 21 Nov 2016 13:07:09 +0800 Subject: [PATCH] launcher: support serveral command line flags. --- launcher | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/launcher b/launcher index 65d8ed0..cda9280 100755 --- a/launcher +++ b/launcher @@ -1,7 +1,7 @@ #!/bin/bash usage () { - echo "Usage: launcher COMMAND CONFIG [--skip-prereqs] [--docker-args STRING]" + echo "Usage: launcher COMMAND [--skip-prereqs] [--docker-args STRING]" echo "Commands:" echo " start: Start/initialize a container" echo " stop: Stop a running container" @@ -16,7 +16,6 @@ usage () { echo "Options:" echo " --skip-prereqs Don't check launcher prerequisites" echo " --docker-args Extra arguments to pass when running docker" - echo " --skip-mac-address Don't assign a mac address" exit 1 } @@ -64,7 +63,7 @@ init_shared() { } set_ports() { - ports=$(docker run --rm -it \ + ports=$(docker run $user_args --rm -it \ -v ${dockerdir}/scripts:/scripts \ -v ${dockerdir}/bootstrap:/bootstrap:ro \ $image \ @@ -122,7 +121,7 @@ bootstrap() { set_bootstrap_volumes set_ports - docker run --rm -it --name seafile-bootstrap -e SEAFILE_BOOTSRAP=1 $volumes $ports $image /sbin/my_init -- /scripts/bootstrap.py + docker run $user_args --rm -it --name seafile-bootstrap -e SEAFILE_BOOTSRAP=1 $volumes $ports $image /sbin/my_init -- /scripts/bootstrap.py docker build -f bootstrap/generated/Dockerfile -t local_seafile/server:latest . } @@ -130,7 +129,7 @@ bootstrap() { oldstart() { set_volumes set_ports - docker run --rm -it --name seafile $volumes $ports $image \ + docker run $user_args --rm -it --name seafile $volumes $ports $image \ /sbin/my_init -- bash -l # /sbin/my_init -- /scripts/start.py } @@ -155,9 +154,18 @@ start() { set_volumes set_ports + + local restart_policy attach_on_run + if [[ "${SUPERVISED}" = "true" ]]; then + restart_policy="--restart=no" + attach_on_run="-a stdout -a stderr" + else + attach_on_run="-d" + fi + ( set -x - docker run -d -it --name seafile $volumes $ports $local_image + docker run $user_args $attach_on_run $restart_policy --name seafile $volumes $ports $local_image ) } @@ -193,9 +201,27 @@ restart() { } check_prereqs() { + if [[ $skip_prereqs == "true" ]]; then + return 0 + fi + + # check docker if ! which docker >/dev/null; then install_docker fi + # TODO: check git version +} + +logs() { + err_and_quit "Not implemented yet" +} + +destroy() { + err_and_quit "Not implemented yet" +} + +rebuild() { + err_and_quit "Not implemented yet" } main() { @@ -203,10 +229,11 @@ main() { while [[ $# -gt 0 ]] do case "$1" in - bootstrap|oldstart|start|stop|restart|enter) + bootstrap|oldstart|start|stop|restart|enter|destroy|logs|rebuild) action=$1 ; shift 1 ;; --debug) debug=true ; shift 1 ;; - # --dummy) dummy=$2 ; shift 2 ;; + --skip-prereqs) skip_prereqs=true ; shift 1 ;; + --docker-args) user_args=$2 ; shift 2 ;; *) err_and_quit "Argument error. Please see help." ;; esac done