annotate docker/libervia_cont.sh @ 109:cb16c0a1f194

docker (libervia_cont): added eprintf function to print to stderr
author Goffi <goffi@goffi.org>
date Mon, 29 Feb 2016 21:50:53 +0100
parents a7b8bb39736b
children 51dc15fbd813
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/bin/sh
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
2
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
3 # Libervia container manager
86
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
4 # Copyright (C) 2014-2016 Jérôme Poisson (goffi@goffi.org)
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
5
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
10
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
15
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
18
86
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
19 VERSION="0.3.0"
103
e69883c1ec30 docker (libervia_cont): added a "status" command:
Goffi <goffi@goffi.org>
parents: 102
diff changeset
20 APP_NAME="Libervia"
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
21 ACCOUNT="salutatoi"
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
22
88
f7d275afc4f2 docker (libervia_cont): TLS dir (directory with certificate) can now be specified with env variable "SAT_CONT_TLS_DIR"
Goffi <goffi@goffi.org>
parents: 87
diff changeset
23 # environment variables that can be used for configuration:
f7d275afc4f2 docker (libervia_cont): TLS dir (directory with certificate) can now be specified with env variable "SAT_CONT_TLS_DIR"
Goffi <goffi@goffi.org>
parents: 87
diff changeset
24 # SAT_CONT_TLS_DIR for TLS certificates directory
89
09099ce530da docker (libervia_cont): domain can now be specified with "SAT_CONT_DOMAIN" env variable in addition to command line argument + use https for help site (wiki)
Goffi <goffi@goffi.org>
parents: 88
diff changeset
25 # SAT_CONT_DOMAIN for the host name
90
64623a78af2f docker (libervia_cont): backup dir can now be specified on command line or with SAT_CONT_BACKUP_DIR environment variable
Goffi <goffi@goffi.org>
parents: 89
diff changeset
26 # SAT_CONT_BACKUP_DIR is the directory where tar.gz backup will be written
93
70f65a6b3392 docker (libervia_cont): added SAT_CONT_DK_EXTRA environment variable for specifying extra options when running containers
Goffi <goffi@goffi.org>
parents: 92
diff changeset
27 # SAT_CONT_DK_EXTRA is used for extra options (used with all containers but sat_data)
95
33f9610480ea docker (libervia_cont): SAT_CONT_PORT_<port> environment variable can now be used to specify destination ports when -p is used
Goffi <goffi@goffi.org>
parents: 93
diff changeset
28 # SAT_CONT_PORT_<port> is used to specify port when -p is used, <port> must be an exposed port
88
f7d275afc4f2 docker (libervia_cont): TLS dir (directory with certificate) can now be specified with env variable "SAT_CONT_TLS_DIR"
Goffi <goffi@goffi.org>
parents: 87
diff changeset
29
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
30 CONTAINERS="prosody sat_pubsub salut sat libervia"
103
e69883c1ec30 docker (libervia_cont): added a "status" command:
Goffi <goffi@goffi.org>
parents: 102
diff changeset
31 TEST_CONT="libervia" # container used to test status
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
32
86
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
33 DK_DETACH="-d"
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
34 DK_TERM="-ti"
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
35
24
f0a59c8f3490 docker: added docker presence check + if image are not present locally on run, download them without catching the output (so we can se the progress)
Goffi <goffi@goffi.org>
parents: 23
diff changeset
36 VOLUME_NAME="data"
f0a59c8f3490 docker: added docker presence check + if image are not present locally on run, download them without catching the output (so we can se the progress)
Goffi <goffi@goffi.org>
parents: 23
diff changeset
37 VOLUME_CONT="$ACCOUNT/$VOLUME_NAME"
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
38 VOLUME_ALIAS="sat_data"
86
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
39 DK_VOLUME="--volumes-from $VOLUME_ALIAS"
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
40
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
41 PUBLIC=0
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
42
91
30f3f83d6959 docker (prosody, libervia_cont): expose HTTP upload ports in Prosody image
Goffi <goffi@goffi.org>
parents: 90
diff changeset
43 PROSODY_PORTS="5222 5269 5280 5281"
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
44 PORT_5222_NAME="XMPP client to server"
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
45 PORT_5269_NAME="XMPP server to server"
91
30f3f83d6959 docker (prosody, libervia_cont): expose HTTP upload ports in Prosody image
Goffi <goffi@goffi.org>
parents: 90
diff changeset
46 PORT_5280_NAME="HTTP Upload"
30f3f83d6959 docker (prosody, libervia_cont): expose HTTP upload ports in Prosody image
Goffi <goffi@goffi.org>
parents: 90
diff changeset
47 PORT_5281_NAME="HTTP Upload (HTTPS)"
108
a7b8bb39736b Docker (libervia_cont, sat, sat_nomedia): removed port 28915 which was used for SI File Transfer and is not used anymore (it may reappear in the futur if force_port is reimplemented)
Goffi <goffi@goffi.org>
parents: 104
diff changeset
48 SAT_PORTS="10143 10125"
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
49 PORT_10143_NAME="IMAP server"
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
50 PORT_10125_NAME="SMTP server"
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
51 LIBERVIA_PORTS="8080 8443"
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
52 PORT_8080_NAME="HTTP"
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
53 PORT_8443_NAME="HTTPS"
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
54 NO_PORT="No public port"
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
55
24
f0a59c8f3490 docker: added docker presence check + if image are not present locally on run, download them without catching the output (so we can se the progress)
Goffi <goffi@goffi.org>
parents: 23
diff changeset
56 DOCKER_EXE="docker"
f0a59c8f3490 docker: added docker presence check + if image are not present locally on run, download them without catching the output (so we can se the progress)
Goffi <goffi@goffi.org>
parents: 23
diff changeset
57
104
b59491821a8a docker (libervia_cont): added a "stats" command for containers resources usage statistics
Goffi <goffi@goffi.org>
parents: 103
diff changeset
58 USAGE="Usage: $0 [start|stop|restart|status|update|backup|restore|ports|config|stats] [ARGS...]"
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
59
89
09099ce530da docker (libervia_cont): domain can now be specified with "SAT_CONT_DOMAIN" env variable in addition to command line argument + use https for help site (wiki)
Goffi <goffi@goffi.org>
parents: 88
diff changeset
60 HELP_SITE="https://wiki.goffi.org/wiki/Docker/en"
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
61 HELP_MUC="sat@chat.jabberfr.org"
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
62
88
f7d275afc4f2 docker (libervia_cont): TLS dir (directory with certificate) can now be specified with env variable "SAT_CONT_TLS_DIR"
Goffi <goffi@goffi.org>
parents: 87
diff changeset
63 CONT_CERT_DIR="/usr/share/sat/certificates"
86
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
64 DEFAULT_TMP_DIR="/tmp/tmp_sat_docker"
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
65
109
cb16c0a1f194 docker (libervia_cont): added eprintf function to print to stderr
Goffi <goffi@goffi.org>
parents: 108
diff changeset
66 eprintf()
cb16c0a1f194 docker (libervia_cont): added eprintf function to print to stderr
Goffi <goffi@goffi.org>
parents: 108
diff changeset
67 {
cb16c0a1f194 docker (libervia_cont): added eprintf function to print to stderr
Goffi <goffi@goffi.org>
parents: 108
diff changeset
68 >&2 printf "$@"
cb16c0a1f194 docker (libervia_cont): added eprintf function to print to stderr
Goffi <goffi@goffi.org>
parents: 108
diff changeset
69 }
cb16c0a1f194 docker (libervia_cont): added eprintf function to print to stderr
Goffi <goffi@goffi.org>
parents: 108
diff changeset
70
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
71 get_dyn_var() {
26
a5e4c6c2a37d docker: replaces tabs by spaces, download first app containers then data container + minor changes
Goffi <goffi@goffi.org>
parents: 25
diff changeset
72 # get dynamicly variable based on given name
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
73
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
74 name=$1
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
75 var_type=$2
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
76 name_upp=$(echo "$name" | tr '[:lower:]' '[:upper:]')
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
77 case $var_type in
96
c425b8a99a29 docker (libervia_cont): removed useless echo in get_dyn_var
Goffi <goffi@goffi.org>
parents: 95
diff changeset
78 ports) eval echo "\$${name_upp}_PORTS";;
c425b8a99a29 docker (libervia_cont): removed useless echo in get_dyn_var
Goffi <goffi@goffi.org>
parents: 95
diff changeset
79 port_name) eval echo "\$PORT_${name_upp}_NAME";;
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
80 esac
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
81 }
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
82
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
83 list_ports() {
26
a5e4c6c2a37d docker: replaces tabs by spaces, download first app containers then data container + minor changes
Goffi <goffi@goffi.org>
parents: 25
diff changeset
84 # list used ports in currently running containers
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
85
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
86 for cont in $CONTAINERS; do
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
87 # we get variable name with uppercase container name
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
88 # some magic to get the ports
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
89 ports=$(get_dyn_var $cont ports)
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
90
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
91 [ -n "$ports" ] && printf "== $cont ==\n\n"
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
92
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
93 for port in $ports; do
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
94 # some magic to get port human readable name
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
95 port_name=$(get_dyn_var $port port_name)
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
96 real_port=$(docker port $cont $port 2>&1)
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
97 if [ $? -ne 0 ]; then
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
98 real_port=$NO_PORT
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
99 fi
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
100
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
101 # we now show the ports with nice alignment
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
102 desc="port $port ($port_name):"
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
103 nb_tabs=$((5-${#desc}/8))
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
104 printf "$desc"
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
105 for i in $(seq $nb_tabs); do
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
106 printf "\t"
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
107 done
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
108 printf "$real_port\n"
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
109 done
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
110 [ -n "$ports" ] && printf '\n'
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
111 done
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
112 }
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
113
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
114 public_ports_arg() {
26
a5e4c6c2a37d docker: replaces tabs by spaces, download first app containers then data container + minor changes
Goffi <goffi@goffi.org>
parents: 25
diff changeset
115 # create Docker arg to have public ports corresponding to container ports
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
116
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
117 if [ $PUBLIC -ne 1 ]; then
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
118 return
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
119 fi
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
120 cont=$1
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
121 ports=$(get_dyn_var $cont ports)
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
122 ARG=""
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
123 for port in $ports; do
95
33f9610480ea docker (libervia_cont): SAT_CONT_PORT_<port> environment variable can now be used to specify destination ports when -p is used
Goffi <goffi@goffi.org>
parents: 93
diff changeset
124 host_port=$(eval echo "\$SAT_CONT_PORT_${port}")
33f9610480ea docker (libervia_cont): SAT_CONT_PORT_<port> environment variable can now be used to specify destination ports when -p is used
Goffi <goffi@goffi.org>
parents: 93
diff changeset
125 if [ -z "$host_port" ]; then
33f9610480ea docker (libervia_cont): SAT_CONT_PORT_<port> environment variable can now be used to specify destination ports when -p is used
Goffi <goffi@goffi.org>
parents: 93
diff changeset
126 host_port=$port
33f9610480ea docker (libervia_cont): SAT_CONT_PORT_<port> environment variable can now be used to specify destination ports when -p is used
Goffi <goffi@goffi.org>
parents: 93
diff changeset
127 fi
33f9610480ea docker (libervia_cont): SAT_CONT_PORT_<port> environment variable can now be used to specify destination ports when -p is used
Goffi <goffi@goffi.org>
parents: 93
diff changeset
128 if [ "$host_port" != 0 ]; then
33f9610480ea docker (libervia_cont): SAT_CONT_PORT_<port> environment variable can now be used to specify destination ports when -p is used
Goffi <goffi@goffi.org>
parents: 93
diff changeset
129 ARG="$ARG -p $host_port:$port"
33f9610480ea docker (libervia_cont): SAT_CONT_PORT_<port> environment variable can now be used to specify destination ports when -p is used
Goffi <goffi@goffi.org>
parents: 93
diff changeset
130 fi
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
131 done
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
132 echo $ARG
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
133 }
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
134
24
f0a59c8f3490 docker: added docker presence check + if image are not present locally on run, download them without catching the output (so we can se the progress)
Goffi <goffi@goffi.org>
parents: 23
diff changeset
135 download_missing() {
26
a5e4c6c2a37d docker: replaces tabs by spaces, download first app containers then data container + minor changes
Goffi <goffi@goffi.org>
parents: 25
diff changeset
136 # download images wich are not present locally
a5e4c6c2a37d docker: replaces tabs by spaces, download first app containers then data container + minor changes
Goffi <goffi@goffi.org>
parents: 25
diff changeset
137 for cont in $CONTAINERS $VOLUME_NAME; do
a5e4c6c2a37d docker: replaces tabs by spaces, download first app containers then data container + minor changes
Goffi <goffi@goffi.org>
parents: 25
diff changeset
138 image="$ACCOUNT/$cont"
a5e4c6c2a37d docker: replaces tabs by spaces, download first app containers then data container + minor changes
Goffi <goffi@goffi.org>
parents: 25
diff changeset
139 docker inspect $image:latest > /dev/null 2>&1
a5e4c6c2a37d docker: replaces tabs by spaces, download first app containers then data container + minor changes
Goffi <goffi@goffi.org>
parents: 25
diff changeset
140 if [ $? -ne 0 ]; then
a5e4c6c2a37d docker: replaces tabs by spaces, download first app containers then data container + minor changes
Goffi <goffi@goffi.org>
parents: 25
diff changeset
141 printf "$image is not present locally, downloading it\n"
a5e4c6c2a37d docker: replaces tabs by spaces, download first app containers then data container + minor changes
Goffi <goffi@goffi.org>
parents: 25
diff changeset
142 docker pull $image:latest
a5e4c6c2a37d docker: replaces tabs by spaces, download first app containers then data container + minor changes
Goffi <goffi@goffi.org>
parents: 25
diff changeset
143 if [ $? -eq 0 ]; then
a5e4c6c2a37d docker: replaces tabs by spaces, download first app containers then data container + minor changes
Goffi <goffi@goffi.org>
parents: 25
diff changeset
144 printf "\nDownload of latest $image finished\n\n"
a5e4c6c2a37d docker: replaces tabs by spaces, download first app containers then data container + minor changes
Goffi <goffi@goffi.org>
parents: 25
diff changeset
145 else
a5e4c6c2a37d docker: replaces tabs by spaces, download first app containers then data container + minor changes
Goffi <goffi@goffi.org>
parents: 25
diff changeset
146 printf "\nError while downloading $image, please check your connection and logs\n"
a5e4c6c2a37d docker: replaces tabs by spaces, download first app containers then data container + minor changes
Goffi <goffi@goffi.org>
parents: 25
diff changeset
147 return 1
a5e4c6c2a37d docker: replaces tabs by spaces, download first app containers then data container + minor changes
Goffi <goffi@goffi.org>
parents: 25
diff changeset
148 fi
a5e4c6c2a37d docker: replaces tabs by spaces, download first app containers then data container + minor changes
Goffi <goffi@goffi.org>
parents: 25
diff changeset
149 fi
a5e4c6c2a37d docker: replaces tabs by spaces, download first app containers then data container + minor changes
Goffi <goffi@goffi.org>
parents: 25
diff changeset
150 done
24
f0a59c8f3490 docker: added docker presence check + if image are not present locally on run, download them without catching the output (so we can se the progress)
Goffi <goffi@goffi.org>
parents: 23
diff changeset
151 }
f0a59c8f3490 docker: added docker presence check + if image are not present locally on run, download them without catching the output (so we can se the progress)
Goffi <goffi@goffi.org>
parents: 23
diff changeset
152
f0a59c8f3490 docker: added docker presence check + if image are not present locally on run, download them without catching the output (so we can se the progress)
Goffi <goffi@goffi.org>
parents: 23
diff changeset
153 check_docker() {
26
a5e4c6c2a37d docker: replaces tabs by spaces, download first app containers then data container + minor changes
Goffi <goffi@goffi.org>
parents: 25
diff changeset
154 which $DOCKER_EXE > /dev/null 2>&1
a5e4c6c2a37d docker: replaces tabs by spaces, download first app containers then data container + minor changes
Goffi <goffi@goffi.org>
parents: 25
diff changeset
155 if [ $? -ne 0 ]; then
86
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
156 printf "Docker is not installed or not accessible, please install it.\nYou can check $HELP_SITE for instructions\n"
26
a5e4c6c2a37d docker: replaces tabs by spaces, download first app containers then data container + minor changes
Goffi <goffi@goffi.org>
parents: 25
diff changeset
157 return 1
a5e4c6c2a37d docker: replaces tabs by spaces, download first app containers then data container + minor changes
Goffi <goffi@goffi.org>
parents: 25
diff changeset
158 fi
24
f0a59c8f3490 docker: added docker presence check + if image are not present locally on run, download them without catching the output (so we can se the progress)
Goffi <goffi@goffi.org>
parents: 23
diff changeset
159 }
f0a59c8f3490 docker: added docker presence check + if image are not present locally on run, download them without catching the output (so we can se the progress)
Goffi <goffi@goffi.org>
parents: 23
diff changeset
160
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
161 parse_run_args() {
26
a5e4c6c2a37d docker: replaces tabs by spaces, download first app containers then data container + minor changes
Goffi <goffi@goffi.org>
parents: 25
diff changeset
162 # manage arguments for run command
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
163
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
164 while [ $# -gt 0 ]; do
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
165 case "$1" in
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
166
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
167 -h|--help)
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
168 cat << OPT_END
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
169 options available for the run command:
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
170
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
171 -h, --help display this help message
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
172 -p, --public publish using true ports
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
173 -d DOMAIN, --domain DOMAIN use DOMAIN as domain name
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
174 OPT_END
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
175 exit 0
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
176 ;;
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
177
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
178 -d|--domain)
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
179 shift
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
180 if [ $# -eq 0 ]; then
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
181 printf "no domain given, --domain must be followed by a domain\n"
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
182 exit 1
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
183 fi
89
09099ce530da docker (libervia_cont): domain can now be specified with "SAT_CONT_DOMAIN" env variable in addition to command line argument + use https for help site (wiki)
Goffi <goffi@goffi.org>
parents: 88
diff changeset
184 SAT_CONT_DOMAIN="$1"
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
185 shift
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
186 ;;
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
187
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
188 -p|--public)
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
189 shift
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
190 PUBLIC=1
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
191 ;;
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
192
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
193 *) printf "Invalid argument, please check \"$0 run --help\"\n"
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
194 exit 1
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
195 ;;
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
196 esac
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
197 done
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
198 }
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
199
24
f0a59c8f3490 docker: added docker presence check + if image are not present locally on run, download them without catching the output (so we can se the progress)
Goffi <goffi@goffi.org>
parents: 23
diff changeset
200 check_docker || exit 1
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
201
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
202 if [ $# -ge 1 ];then
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
203 case $1 in
86
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
204 start) CMD=START;;
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
205 stop) CMD=STOP;;
86
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
206 restart) CMD=RESTART;;
103
e69883c1ec30 docker (libervia_cont): added a "status" command:
Goffi <goffi@goffi.org>
parents: 102
diff changeset
207 status) CMD=STATUS;;
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
208 update) CMD=UPDATE;;
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
209 backup) CMD=BACKUP;;
87
53a579906c32 docker(libervia_cont): added a "restore" command
Goffi <goffi@goffi.org>
parents: 86
diff changeset
210 restore) CMD=RESTORE;;
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
211 ports) CMD=PORTS;;
86
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
212 config) CMD=CONFIG;;
104
b59491821a8a docker (libervia_cont): added a "stats" command for containers resources usage statistics
Goffi <goffi@goffi.org>
parents: 103
diff changeset
213 stats) CMD=STATS;;
26
a5e4c6c2a37d docker: replaces tabs by spaces, download first app containers then data container + minor changes
Goffi <goffi@goffi.org>
parents: 25
diff changeset
214 -v|--version) printf "$VERSION\n"; exit 0;;
a5e4c6c2a37d docker: replaces tabs by spaces, download first app containers then data container + minor changes
Goffi <goffi@goffi.org>
parents: 25
diff changeset
215 -h|--help) printf "$USAGE\n\nYou can check $HELP_SITE for instructions, or go to $HELP_MUC XMPP MUC room for help\n"; exit 0;;
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
216 *) echo $USAGE
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
217 exit 1
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
218 esac
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
219 shift
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
220 else
86
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
221 CMD=START
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
222 fi
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
223
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
224 case $CMD in
86
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
225 START)
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
226 parse_run_args "$@"
24
f0a59c8f3490 docker: added docker presence check + if image are not present locally on run, download them without catching the output (so we can se the progress)
Goffi <goffi@goffi.org>
parents: 23
diff changeset
227 download_missing || exit 1
f0a59c8f3490 docker: added docker presence check + if image are not present locally on run, download them without catching the output (so we can se the progress)
Goffi <goffi@goffi.org>
parents: 23
diff changeset
228
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
229 printf "Running data container... "
89
09099ce530da docker (libervia_cont): domain can now be specified with "SAT_CONT_DOMAIN" env variable in addition to command line argument + use https for help site (wiki)
Goffi <goffi@goffi.org>
parents: 88
diff changeset
230 # we use -d even if data container doesn't stay in background to get id of the container
09099ce530da docker (libervia_cont): domain can now be specified with "SAT_CONT_DOMAIN" env variable in addition to command line argument + use https for help site (wiki)
Goffi <goffi@goffi.org>
parents: 88
diff changeset
231 docker_id=$(docker run -d --name $VOLUME_ALIAS $VOLUME_CONT 2>&1)
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
232 if [ $? -eq 0 ]; then
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
233 printf "OK ($docker_id)\n"
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
234 else
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
235 echo $docker_id | grep Conflict > /dev/null 2>&1
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
236 if [ $? -eq 0 ]; then
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
237 printf "A data container already exists ($VOLUME_ALIAS), use \"docker ps -a\" to see it\n"
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
238 else
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
239 printf "Error, please check data volume\nerror message: $docker_id\n"
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
240 exit 1
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
241 fi
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
242 fi
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
243 printf "\nRunning Libervia\n\n"
88
f7d275afc4f2 docker (libervia_cont): TLS dir (directory with certificate) can now be specified with env variable "SAT_CONT_TLS_DIR"
Goffi <goffi@goffi.org>
parents: 87
diff changeset
244 # we first check if we need to mount TLS directory
f7d275afc4f2 docker (libervia_cont): TLS dir (directory with certificate) can now be specified with env variable "SAT_CONT_TLS_DIR"
Goffi <goffi@goffi.org>
parents: 87
diff changeset
245 if [ -n "$SAT_CONT_TLS_DIR" ]; then
f7d275afc4f2 docker (libervia_cont): TLS dir (directory with certificate) can now be specified with env variable "SAT_CONT_TLS_DIR"
Goffi <goffi@goffi.org>
parents: 87
diff changeset
246 printf "$SAT_CONT_TLS_DIR will be used for TLS certificate\n"
f7d275afc4f2 docker (libervia_cont): TLS dir (directory with certificate) can now be specified with env variable "SAT_CONT_TLS_DIR"
Goffi <goffi@goffi.org>
parents: 87
diff changeset
247 DK_TLS="--volume=$SAT_CONT_TLS_DIR:$CONT_CERT_DIR"
f7d275afc4f2 docker (libervia_cont): TLS dir (directory with certificate) can now be specified with env variable "SAT_CONT_TLS_DIR"
Goffi <goffi@goffi.org>
parents: 87
diff changeset
248 fi
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
249 for CONT in $CONTAINERS; do
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
250 case $CONT in
88
f7d275afc4f2 docker (libervia_cont): TLS dir (directory with certificate) can now be specified with env variable "SAT_CONT_TLS_DIR"
Goffi <goffi@goffi.org>
parents: 87
diff changeset
251 prosody) OPTS="$DK_DETACH $DK_TERM $DK_VOLUME $DK_TLS $(public_ports_arg $CONT) --name prosody"
89
09099ce530da docker (libervia_cont): domain can now be specified with "SAT_CONT_DOMAIN" env variable in addition to command line argument + use https for help site (wiki)
Goffi <goffi@goffi.org>
parents: 88
diff changeset
252 if [ -n "$SAT_CONT_DOMAIN" ]; then
09099ce530da docker (libervia_cont): domain can now be specified with "SAT_CONT_DOMAIN" env variable in addition to command line argument + use https for help site (wiki)
Goffi <goffi@goffi.org>
parents: 88
diff changeset
253 OPTS="-e DOMAIN=$SAT_CONT_DOMAIN $OPTS"
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
254 fi
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
255 ;;
86
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
256 sat_pubsub) OPTS="$DK_DETACH $DK_TERM $DK_VOLUME --name sat_pubsub --link=prosody:prosody";;
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
257 salut) OPTS="$DK_DETACH $DK_TERM $DK_VOLUME --name salut --link=prosody:prosody";;
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
258 sat) OPTS="$DK_DETACH $DK_TERM $DK_VOLUME -P $(public_ports_arg $CONT) --name sat --link=prosody:prosody";;
88
f7d275afc4f2 docker (libervia_cont): TLS dir (directory with certificate) can now be specified with env variable "SAT_CONT_TLS_DIR"
Goffi <goffi@goffi.org>
parents: 87
diff changeset
259 libervia) OPTS="$DK_DETACH $DK_TERM $DK_VOLUME --volumes-from sat $DK_TLS -P $(public_ports_arg $CONT) --name libervia --link=sat:sat";;
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
260 *) printf "Unkown container $CONT\n"; exit 1
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
261 esac
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
262 printf "Launching $CONT... "
93
70f65a6b3392 docker (libervia_cont): added SAT_CONT_DK_EXTRA environment variable for specifying extra options when running containers
Goffi <goffi@goffi.org>
parents: 92
diff changeset
263 docker_id=$(docker run $OPTS $SAT_CONT_DK_EXTRA $ACCOUNT/$CONT 2>&1)
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
264 if [ $? -eq 0 ]; then
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
265 printf "OK ($docker_id)\n"
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
266 else
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
267 printf "Error, please check container or ask help on XMPP MUC sat@chat.jabberfr.org\nerror message: $docker_id\n"
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
268 printf "Abandon\n"
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
269 exit 1
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
270 fi
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
271 done
92
5a0ed7f94ab8 docker (libervia_cont): added "-f" option in help message for logs
Goffi <goffi@goffi.org>
parents: 91
diff changeset
272 printf '\nLibervia is launched and should be reachable in a couple of seconds.\nYou can check logs with "docker logs -f libervia" (or any other container name).\n'
26
a5e4c6c2a37d docker: replaces tabs by spaces, download first app containers then data container + minor changes
Goffi <goffi@goffi.org>
parents: 25
diff changeset
273 printf "An \"admin\" account has been created, you can check its password on $VOLUME_ALIAS container, in file /home/sat/ADMIN_PWD. Config can be tuned on this container.\n"
95
33f9610480ea docker (libervia_cont): SAT_CONT_PORT_<port> environment variable can now be used to specify destination ports when -p is used
Goffi <goffi@goffi.org>
parents: 93
diff changeset
274 printf 'Below are the ports used to connect, you can go with your browser to Libervia HTTP(S) port.\n\n'
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
275 list_ports
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
276 ;;
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
277 STOP)
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
278 printf "stopping Libervia\n"
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
279 REVERSED=""
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
280 for CONT in $CONTAINERS; do
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
281 REVERSED="$CONT $REVERSED"
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
282 done;
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
283 for CONT in $REVERSED; do
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
284 printf "\nStopping container $CONT"
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
285 docker stop $CONT > /dev/null 2>&1 || printf "... Error while stopping $CONT\n"
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
286 printf "\rDeleting container $CONT"
102
61ff3bef94a6 docker (libervia_cont): remove volumes from container on "stop" command
Goffi <goffi@goffi.org>
parents: 101
diff changeset
287 docker rm -v $CONT > /dev/null 2>&1 || printf "... Error while removing $CONT\n"
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
288 done
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
289 printf "\n"
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
290 ;;
87
53a579906c32 docker(libervia_cont): added a "restore" command
Goffi <goffi@goffi.org>
parents: 86
diff changeset
291 RESTART)
53a579906c32 docker(libervia_cont): added a "restore" command
Goffi <goffi@goffi.org>
parents: 86
diff changeset
292 printf "restarting containers...\n"
53a579906c32 docker(libervia_cont): added a "restore" command
Goffi <goffi@goffi.org>
parents: 86
diff changeset
293 "$0" stop && "$0" start "$@"
53a579906c32 docker(libervia_cont): added a "restore" command
Goffi <goffi@goffi.org>
parents: 86
diff changeset
294 ;;
103
e69883c1ec30 docker (libervia_cont): added a "status" command:
Goffi <goffi@goffi.org>
parents: 102
diff changeset
295 STATUS)
e69883c1ec30 docker (libervia_cont): added a "status" command:
Goffi <goffi@goffi.org>
parents: 102
diff changeset
296 docker inspect $TEST_CONT > /dev/null 2>&1
e69883c1ec30 docker (libervia_cont): added a "status" command:
Goffi <goffi@goffi.org>
parents: 102
diff changeset
297 if [ $? -eq 0 ]; then
e69883c1ec30 docker (libervia_cont): added a "status" command:
Goffi <goffi@goffi.org>
parents: 102
diff changeset
298 printf "$APP_NAME is running"
e69883c1ec30 docker (libervia_cont): added a "status" command:
Goffi <goffi@goffi.org>
parents: 102
diff changeset
299 # we test the presence of "starting on xxxx" (where xxxx is one of the exposed ports)
e69883c1ec30 docker (libervia_cont): added a "status" command:
Goffi <goffi@goffi.org>
parents: 102
diff changeset
300 # this is not really reliable as ports can be changed in configuration
e69883c1ec30 docker (libervia_cont): added a "status" command:
Goffi <goffi@goffi.org>
parents: 102
diff changeset
301 # but in most case it should work OK
e69883c1ec30 docker (libervia_cont): added a "status" command:
Goffi <goffi@goffi.org>
parents: 102
diff changeset
302 PORTS_REGEX=$(get_dyn_var $TEST_CONT ports | sed 's/ /\\|/')
e69883c1ec30 docker (libervia_cont): added a "status" command:
Goffi <goffi@goffi.org>
parents: 102
diff changeset
303 docker logs $TEST_CONT | grep "starting on \($PORTS_REGEX\)" > /dev/null 2>&1
e69883c1ec30 docker (libervia_cont): added a "status" command:
Goffi <goffi@goffi.org>
parents: 102
diff changeset
304 if [ $? -ne 0 ]; then
e69883c1ec30 docker (libervia_cont): added a "status" command:
Goffi <goffi@goffi.org>
parents: 102
diff changeset
305 printf " but no server is started\n"
e69883c1ec30 docker (libervia_cont): added a "status" command:
Goffi <goffi@goffi.org>
parents: 102
diff changeset
306 exit 2
e69883c1ec30 docker (libervia_cont): added a "status" command:
Goffi <goffi@goffi.org>
parents: 102
diff changeset
307 fi
e69883c1ec30 docker (libervia_cont): added a "status" command:
Goffi <goffi@goffi.org>
parents: 102
diff changeset
308 printf "\n"
e69883c1ec30 docker (libervia_cont): added a "status" command:
Goffi <goffi@goffi.org>
parents: 102
diff changeset
309 exit 0
e69883c1ec30 docker (libervia_cont): added a "status" command:
Goffi <goffi@goffi.org>
parents: 102
diff changeset
310 else
e69883c1ec30 docker (libervia_cont): added a "status" command:
Goffi <goffi@goffi.org>
parents: 102
diff changeset
311 printf "$APP_NAME is not running\n"
e69883c1ec30 docker (libervia_cont): added a "status" command:
Goffi <goffi@goffi.org>
parents: 102
diff changeset
312 exit 1
e69883c1ec30 docker (libervia_cont): added a "status" command:
Goffi <goffi@goffi.org>
parents: 102
diff changeset
313 fi
e69883c1ec30 docker (libervia_cont): added a "status" command:
Goffi <goffi@goffi.org>
parents: 102
diff changeset
314 ;;
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
315 UPDATE)
28
9ca1e7fe0f87 Docker: we update images, not containers
Goffi <goffi@goffi.org>
parents: 26
diff changeset
316 printf "updating images...\n"
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
317 errors=0
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
318 for CONT in $CONTAINERS data; do
25
25b7452c2d5a docker: "docker pull" result is not hidden anymore in libervia_cons.sh update, so download progress can be followed
Goffi <goffi@goffi.org>
parents: 24
diff changeset
319 printf "\n*** updating $CONT ***\n"
25b7452c2d5a docker: "docker pull" result is not hidden anymore in libervia_cons.sh update, so download progress can be followed
Goffi <goffi@goffi.org>
parents: 24
diff changeset
320 docker pull $ACCOUNT/$CONT:latest
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
321 if [ $? -ne 0 ]; then
25
25b7452c2d5a docker: "docker pull" result is not hidden anymore in libervia_cons.sh update, so download progress can be followed
Goffi <goffi@goffi.org>
parents: 24
diff changeset
322 printf "\nError while updating $ACCOUNT/$CONT\n"
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
323 errors=1
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
324 fi
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
325 done
23
b10f01885949 docker: fixed libervia_cont update + added some newlines
Goffi <goffi@goffi.org>
parents: 22
diff changeset
326 if [ $errors -eq 0 ]; then
28
9ca1e7fe0f87 Docker: we update images, not containers
Goffi <goffi@goffi.org>
parents: 26
diff changeset
327 printf "\n\nImages are up-to-date\n"
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
328 else
28
9ca1e7fe0f87 Docker: we update images, not containers
Goffi <goffi@goffi.org>
parents: 26
diff changeset
329 printf "\n\nSome errors happened while updating images\n"
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
330 exit 1
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
331 fi
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
332 ;;
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
333 BACKUP)
90
64623a78af2f docker (libervia_cont): backup dir can now be specified on command line or with SAT_CONT_BACKUP_DIR environment variable
Goffi <goffi@goffi.org>
parents: 89
diff changeset
334 case $# in
64623a78af2f docker (libervia_cont): backup dir can now be specified on command line or with SAT_CONT_BACKUP_DIR environment variable
Goffi <goffi@goffi.org>
parents: 89
diff changeset
335 0) SAT_CONT_BACKUP_DIR="$(pwd)";;
64623a78af2f docker (libervia_cont): backup dir can now be specified on command line or with SAT_CONT_BACKUP_DIR environment variable
Goffi <goffi@goffi.org>
parents: 89
diff changeset
336 1) SAT_CONT_BACKUP_DIR="$1";;
64623a78af2f docker (libervia_cont): backup dir can now be specified on command line or with SAT_CONT_BACKUP_DIR environment variable
Goffi <goffi@goffi.org>
parents: 89
diff changeset
337 *) printf "syntaxe is $0 backup [backup_dir_absolute_path]\n[backup_dir_absolute_path] default to current working dir\n"
64623a78af2f docker (libervia_cont): backup dir can now be specified on command line or with SAT_CONT_BACKUP_DIR environment variable
Goffi <goffi@goffi.org>
parents: 89
diff changeset
338 exit 1
64623a78af2f docker (libervia_cont): backup dir can now be specified on command line or with SAT_CONT_BACKUP_DIR environment variable
Goffi <goffi@goffi.org>
parents: 89
diff changeset
339 ;;
64623a78af2f docker (libervia_cont): backup dir can now be specified on command line or with SAT_CONT_BACKUP_DIR environment variable
Goffi <goffi@goffi.org>
parents: 89
diff changeset
340 esac
64623a78af2f docker (libervia_cont): backup dir can now be specified on command line or with SAT_CONT_BACKUP_DIR environment variable
Goffi <goffi@goffi.org>
parents: 89
diff changeset
341 SAT_CONT_BACKUP_DIR=$(echo $SAT_CONT_BACKUP_DIR | sed 's%^\/*\|\/*$%\/%g') # we want to be sure that path starts and finishes with "/"
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
342 filename="sat_data_backup_$(date '+%Y-%m-%d_%H:%M:%S').tar.gz"
90
64623a78af2f docker (libervia_cont): backup dir can now be specified on command line or with SAT_CONT_BACKUP_DIR environment variable
Goffi <goffi@goffi.org>
parents: 89
diff changeset
343 printf "backing up data container to ${SAT_CONT_BACKUP_DIR}${filename}\n\n"
64623a78af2f docker (libervia_cont): backup dir can now be specified on command line or with SAT_CONT_BACKUP_DIR environment variable
Goffi <goffi@goffi.org>
parents: 89
diff changeset
344 docker run --rm $DK_VOLUME -v "$SAT_CONT_BACKUP_DIR:/backup" debian:jessie tar zcvf "/backup/$filename" -C / -h volumes
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
345 if [ $? -eq 0 ]; then
90
64623a78af2f docker (libervia_cont): backup dir can now be specified on command line or with SAT_CONT_BACKUP_DIR environment variable
Goffi <goffi@goffi.org>
parents: 89
diff changeset
346 printf "\nBackup finished and available at ${SAT_CONT_BACKUP_DIR}${filename}\n"
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
347 else
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
348 printf "\nBackup Error !\n"
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
349 exit 1
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
350 fi
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
351 ;;
87
53a579906c32 docker(libervia_cont): added a "restore" command
Goffi <goffi@goffi.org>
parents: 86
diff changeset
352 RESTORE)
53a579906c32 docker(libervia_cont): added a "restore" command
Goffi <goffi@goffi.org>
parents: 86
diff changeset
353 if [ $# -ne 1 ]; then
90
64623a78af2f docker (libervia_cont): backup dir can now be specified on command line or with SAT_CONT_BACKUP_DIR environment variable
Goffi <goffi@goffi.org>
parents: 89
diff changeset
354 printf "syntaxe is $0 restore <backup_file.tar.gz>\n"
87
53a579906c32 docker(libervia_cont): added a "restore" command
Goffi <goffi@goffi.org>
parents: 86
diff changeset
355 exit 1
53a579906c32 docker(libervia_cont): added a "restore" command
Goffi <goffi@goffi.org>
parents: 86
diff changeset
356 fi
53a579906c32 docker(libervia_cont): added a "restore" command
Goffi <goffi@goffi.org>
parents: 86
diff changeset
357 docker run --name $VOLUME_ALIAS $VOLUME_CONT > /dev/null 2>&1
53a579906c32 docker(libervia_cont): added a "restore" command
Goffi <goffi@goffi.org>
parents: 86
diff changeset
358 if [ $? -ne 0 ]; then
53a579906c32 docker(libervia_cont): added a "restore" command
Goffi <goffi@goffi.org>
parents: 86
diff changeset
359 printf "Can't create $VOLUME_ALIAS container.\n\
101
83dacf8fda47 docker (libervia_cont): added -v argument in help message for removing sat_data in restore command
Goffi <goffi@goffi.org>
parents: 100
diff changeset
360 If you have an existing one, please remove it with \"docker rm -v $VOLUME_ALIAS\" (/!\\ it will remove *ALL* your data)\n\n\
99
15e317bb602f docker (libervia_cont): removed instructions about commiting sat_data, as a volume container will not commit data (see https://github.com/docker/docker/issues/7583)
Goffi <goffi@goffi.org>
parents: 96
diff changeset
361 Hint: you can also rename your current data container with \"docker rename $VOLUME_ALIAS new_container_name\"\n"
87
53a579906c32 docker(libervia_cont): added a "restore" command
Goffi <goffi@goffi.org>
parents: 86
diff changeset
362 exit 1
53a579906c32 docker(libervia_cont): added a "restore" command
Goffi <goffi@goffi.org>
parents: 86
diff changeset
363 fi
53a579906c32 docker(libervia_cont): added a "restore" command
Goffi <goffi@goffi.org>
parents: 86
diff changeset
364
53a579906c32 docker(libervia_cont): added a "restore" command
Goffi <goffi@goffi.org>
parents: 86
diff changeset
365 printf "restoring $1 to $VOLUME_ALIAS container\n\n"
100
d9f9de4bd7a0 docker (libervia_cont): fixed restore when full backup path is used
Goffi <goffi@goffi.org>
parents: 99
diff changeset
366 HOST_BACKUP_DIR=$(dirname "$1")
d9f9de4bd7a0 docker (libervia_cont): fixed restore when full backup path is used
Goffi <goffi@goffi.org>
parents: 99
diff changeset
367 HOST_BACKUP_NAME=$(basename "$1")
87
53a579906c32 docker(libervia_cont): added a "restore" command
Goffi <goffi@goffi.org>
parents: 86
diff changeset
368 if [ $HOST_BACKUP_DIR = "." ]; then
88
f7d275afc4f2 docker (libervia_cont): TLS dir (directory with certificate) can now be specified with env variable "SAT_CONT_TLS_DIR"
Goffi <goffi@goffi.org>
parents: 87
diff changeset
369 # workaround for a Docker bug (container crash if "." is used)
87
53a579906c32 docker(libervia_cont): added a "restore" command
Goffi <goffi@goffi.org>
parents: 86
diff changeset
370 HOST_BACKUP_DIR=$(pwd)
53a579906c32 docker(libervia_cont): added a "restore" command
Goffi <goffi@goffi.org>
parents: 86
diff changeset
371 fi
100
d9f9de4bd7a0 docker (libervia_cont): fixed restore when full backup path is used
Goffi <goffi@goffi.org>
parents: 99
diff changeset
372 docker run --rm $DK_VOLUME -v "$HOST_BACKUP_DIR:/backup" debian:jessie tar zxvf "/backup/$HOST_BACKUP_NAME" -C / -h volumes
87
53a579906c32 docker(libervia_cont): added a "restore" command
Goffi <goffi@goffi.org>
parents: 86
diff changeset
373 if [ $? -eq 0 ]; then
53a579906c32 docker(libervia_cont): added a "restore" command
Goffi <goffi@goffi.org>
parents: 86
diff changeset
374 printf "\nRestore finished\n"
53a579906c32 docker(libervia_cont): added a "restore" command
Goffi <goffi@goffi.org>
parents: 86
diff changeset
375 else
53a579906c32 docker(libervia_cont): added a "restore" command
Goffi <goffi@goffi.org>
parents: 86
diff changeset
376 printf "\nRestore Error !\n"
53a579906c32 docker(libervia_cont): added a "restore" command
Goffi <goffi@goffi.org>
parents: 86
diff changeset
377 exit 1
53a579906c32 docker(libervia_cont): added a "restore" command
Goffi <goffi@goffi.org>
parents: 86
diff changeset
378 fi
53a579906c32 docker(libervia_cont): added a "restore" command
Goffi <goffi@goffi.org>
parents: 86
diff changeset
379 ;;
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
380 PORTS)
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
381 list_ports
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
382 ;;
86
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
383 CONFIG)
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
384 case $# in
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
385 0) CONF="libervia";;
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
386 1) CONF="$1";;
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
387 *) CONF="";;
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
388 esac
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
389 case $CONF in
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
390 libervia)
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
391 CONT_CONF_FILE="/home/sat/.config/sat/sat.conf"
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
392 ;;
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
393 prosody)
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
394 CONT_CONF_FILE="/etc/prosody/prosody_sat_cfg/prosody.cfg.lua"
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
395 ;;
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
396 *) printf "\nPlease enter type of configuration to edit (libervia, prosody)\n"
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
397 exit 1
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
398 ;;
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
399 esac
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
400
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
401 HOST_CONF_FILE=$(basename $CONT_CONF_FILE)
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
402
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
403 printf "\ngetting configuration for $CONF\n"
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
404 # we copy config file to a temporary dit
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
405 # then edit with $EDITOR and put it back
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
406
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
407 TMP_DIR=$(mktemp -d 2>/dev/null)
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
408 if [ $? -ne 0 ]; then
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
409 TMP_DIR="$DEFAULT_TMP_DIR"
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
410 mkdir -p "$TMP_DIR"
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
411 fi
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
412
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
413 docker cp "$VOLUME_ALIAS:$CONT_CONF_FILE" "$TMP_DIR/$HOST_CONF_FILE"
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
414 "$EDITOR" "$TMP_DIR/$HOST_CONF_FILE"
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
415 if [ $? -eq 0 -a -s "$TMP_DIR/$HOST_CONF_FILE" ]; then
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
416 printf "updating configuration\n"
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
417 docker cp "$TMP_DIR/$HOST_CONF_FILE" "$VOLUME_ALIAS:$CONT_CONF_FILE"
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
418 fi
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
419 rm -rf "$TMP_DIR"
f5067e3112ba docker (libervia_cont): new commands:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
420 ;;
104
b59491821a8a docker (libervia_cont): added a "stats" command for containers resources usage statistics
Goffi <goffi@goffi.org>
parents: 103
diff changeset
421 STATS)
b59491821a8a docker (libervia_cont): added a "stats" command for containers resources usage statistics
Goffi <goffi@goffi.org>
parents: 103
diff changeset
422 if [ -n "$1" -a "$1" != "--no-stream" ]; then
b59491821a8a docker (libervia_cont): added a "stats" command for containers resources usage statistics
Goffi <goffi@goffi.org>
parents: 103
diff changeset
423 printf "usage: $0 stats [--no-stream]\n"
b59491821a8a docker (libervia_cont): added a "stats" command for containers resources usage statistics
Goffi <goffi@goffi.org>
parents: 103
diff changeset
424 exit 1
b59491821a8a docker (libervia_cont): added a "stats" command for containers resources usage statistics
Goffi <goffi@goffi.org>
parents: 103
diff changeset
425 fi
b59491821a8a docker (libervia_cont): added a "stats" command for containers resources usage statistics
Goffi <goffi@goffi.org>
parents: 103
diff changeset
426 docker stats $1 $CONTAINERS
b59491821a8a docker (libervia_cont): added a "stats" command for containers resources usage statistics
Goffi <goffi@goffi.org>
parents: 103
diff changeset
427 ;;
21
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
428 *) printf "Error: unknown command !"
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
429 exit 2
0e78c8a4626e Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
Goffi <goffi@goffi.org>
parents:
diff changeset
430 esac