Added stop/restart/enter commands.

This commit is contained in:
Shuai Lin 2016-11-21 12:56:33 +08:00
parent 3a61ff2eb4
commit 4a04b0cb5d
3 changed files with 92 additions and 6 deletions

View file

@ -11,5 +11,5 @@ install:
script: script:
- cd image && make base && make && cd .. - cd image && make base && make && cd ..
- cp samples/server.conf bootstrap/bootstrap.conf - cp samples/server.conf bootstrap/bootstrap.conf
- ./launcher bootstrap - sudo ./launcher bootstrap
- ./launcher start - sudo ./launcher start

View file

@ -1,5 +1,25 @@
#!/bin/bash #!/bin/bash
usage () {
echo "Usage: launcher COMMAND CONFIG [--skip-prereqs] [--docker-args STRING]"
echo "Commands:"
echo " start: Start/initialize a container"
echo " stop: Stop a running container"
echo " restart: Restart a container"
echo " destroy: Stop and remove a container"
echo " enter: Open a shell to run commands inside the container"
echo " logs: View the Docker logs for a container"
echo " bootstrap: Bootstrap a container for the config based on a template"
echo " rebuild: Rebuild a container (destroy old, bootstrap, start new)"
echo " cleanup: Remove all containers that have stopped for > 24 hours"
echo
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
}
set -e set -e
set -o pipefail set -o pipefail
@ -19,6 +39,12 @@ dbg() {
fi fi
} }
install_docker() {
echo "Docker is not installed, you will need to install Docker in order to run Launcher"
echo "See https://docs.docker.com/installation/"
exit 1
}
err_and_quit () { err_and_quit () {
printf "\n\n\033[33mError: %s\033[m\n\n" "$1" printf "\n\n\033[33mError: %s\033[m\n\n" "$1"
exit 1 exit 1
@ -83,6 +109,10 @@ set_volumes() {
done done
} }
set_existing_container() {
existing=$(docker ps -a | awk '{ print $1, $(NF) }' | grep " seafile$" | awk '{ print $1 }' || true)
}
bootstrap() { bootstrap() {
if [[ ! -e $bootstrap_conf ]]; then if [[ ! -e $bootstrap_conf ]]; then
err_and_quit "The file $bootstrap_conf doesn't exist. Have you run seafile-server-setup?" err_and_quit "The file $bootstrap_conf doesn't exist. Have you run seafile-server-setup?"
@ -106,13 +136,66 @@ oldstart() {
} }
start() { start() {
existing=$(docker ps | awk '{ print $1, $(NF) }' | grep " seafile$" | awk '{ print $1 }' || true)
if [[ $existing != "" ]]; then
echo "Nothing to do, your container has already started!"
exit 0
fi
set_existing_container
if [[ $existing != "" ]]; then
echo "starting up existing container"
(
set -x
docker start seafile
)
exit 0
fi
set_volumes set_volumes
set_ports set_ports
docker run --rm -it --name seafile $volumes $ports $local_image
(
set -x
docker run -d -it --name seafile $volumes $ports $local_image
)
}
stop() {
set_existing_container
if [[ $existing != "" ]]; then
(
set -x
docker stop -t 10 seafile
)
else
echo "seafile was not started !"
exit 1
fi
} }
enter() { enter() {
err_and_quit "Not implemented yet" set_existing_container
if [[ $existing != "" ]]; then
(
set -x
docker exec -it seafile /bin/bash
)
else
echo "seafile was not started !"
exit 1
fi
}
restart() {
stop
start
}
check_prereqs() {
if ! which docker >/dev/null; then
install_docker
fi
} }
main() { main() {
@ -120,13 +203,15 @@ main() {
while [[ $# -gt 0 ]] while [[ $# -gt 0 ]]
do do
case "$1" in case "$1" in
bootstrap|oldstart|start|enter) action=$1 ; shift 1 ;; bootstrap|oldstart|start|stop|restart|enter)
action=$1 ; shift 1 ;;
--debug) debug=true ; shift 1 ;; --debug) debug=true ; shift 1 ;;
--dummy) dummy=$2 ; shift 2 ;; # --dummy) dummy=$2 ; shift 2 ;;
*) err_and_quit "Argument error. Please see help." ;; *) err_and_quit "Argument error. Please see help." ;;
esac esac
done done
"$action" "$action"
} }
check_prereqs
main "$@" main "$@"

View file

@ -4,6 +4,7 @@ FROM seafileorg/server:{{ seafile_version }}
CMD ["/sbin/my_init", "--", "/scripts/start.py"] CMD ["/sbin/my_init", "--", "/scripts/start.py"]
# shared/ are ignored in .dockerignore
ADD . /app ADD . /app
RUN cp -rp /app/scripts /scripts && \ RUN cp -rp /app/scripts /scripts && \