seafile-containerized/launcher
2016-11-16 09:46:08 +08:00

133 lines
3.1 KiB
Bash
Executable file

#!/bin/bash
set -e
set -o pipefail
version=6.0.5
image=seafileorg/server:$version
local_image=local_seafile/server:latest
dockerdir=$(cd "$(dirname $0)"; pwd -P)
sharedir=$dockerdir/shared
installdir=/opt/seafile/seafile-server-$version
bootstrap_conf=$dockerdir/bootstrap/bootstrap.conf
cd $dockerdir
dbg() {
if [[ $debug == "true" ]]; then
echo "dbg: $1"
fi
}
err_and_quit () {
printf "\n\n\033[33mError: %s\033[m\n\n" "$1"
exit 1
}
init_shared() {
mkdir -p $sharedir/{seafile,db}
mkdir -p $sharedir/logs/{seafile,var-log}
mkdir -p $sharedir/logs/var-log/nginx
touch $sharedir/logs/var-log/syslog
local bash_history=$sharedir/.bash_history
if [[ ! -e $bash_history ]]; then
touch $bash_history
fi
}
set_ports() {
ports=$(docker run --rm -it \
-v ${dockerdir}/scripts:/scripts \
-v ${dockerdir}/bootstrap:/bootstrap:ro \
$image \
/scripts/bootstrap.py --parse-ports)
}
set_bootstrap_volumes() {
local mounts
init_shared
mounts=(
$sharedir:/shared
$sharedir/logs/var-log:/var/log
$sharedir/db:/var/lib/mysql
$dockerdir/bootstrap:/bootstrap
$dockerdir/scripts:/scripts:ro
$dockerdir/templates:/templates:ro
$dockerdir/scripts/tmp/check_init_admin.py:$installdir/check_init_admin.py:ro
$sharedir/.bash_history:/root/.bash_history
)
volumes=""
local m
for m in ${mounts[*]}; do
volumes="$volumes -v $m"
done
}
set_volumes() {
local mounts
init_shared
mounts=(
$sharedir:/shared
$sharedir/logs/var-log:/var/log
$sharedir/db:/var/lib/mysql
$sharedir/.bash_history:/root/.bash_history
)
volumes=""
local m
for m in ${mounts[*]}; do
volumes="$volumes -v $m"
done
}
bootstrap() {
if [[ ! -e $bootstrap_conf ]]; then
err_and_quit "The file $bootstrap_conf doesn't exist. Have you run seafile-server-setup?"
fi
# First initialize seafile server and letsencrypt
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 build -f bootstrap/generated/Dockerfile -t local_seafile/server:latest .
}
oldstart() {
set_volumes
set_ports
docker run --rm -it --name seafile $volumes $ports $image \
/sbin/my_init -- bash -l
# /sbin/my_init -- /scripts/start.py
}
start() {
set_volumes
set_ports
docker run --rm -it --name seafile $volumes $ports $local_image
}
enter() {
err_and_quit "Not implemented yet"
}
main() {
local action
while [[ $# -gt 0 ]]
do
case "$1" in
bootstrap|oldstart|start|enter) action=$1 ; shift 1 ;;
--debug) debug=true ; shift 1 ;;
--dummy) dummy=$2 ; shift 2 ;;
*) err_and_quit "Argument error. Please see help." ;;
esac
done
"$action"
}
main "$@"