forked from LAL/xtremweb-hep
/
build.sh
executable file
·192 lines (145 loc) · 4.93 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/bin/sh
#=============================================================================
#
# File : build.sh
# Date : July 24th, 2017
# Author : Oleg Lodygensky
#
# Change log:
# - Jul 24th,2017 : Oleg Lodygensky; creation
#
# OS : Linux, mac os x
#
# Purpose : this script creates and starts a new Docker container for the XWHEP server
#
#=============================================================================
# Copyrights : CNRS
# Author : Oleg Lodygensky
# Acknowledgment : XtremWeb-HEP is based on XtremWeb 1.8.0 by inria : http://www.xtremweb.net/
# Web : http://www.xtremweb-hep.org
#
# This file is part of XtremWeb-HEP.
#
# XtremWeb-HEP is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# XtremWeb-HEP is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with XtremWeb-HEP. If not, see <http://www.gnu.org/licenses/>.
#
#
THISOS=`uname -s`
case "$THISOS" in
Darwin )
DATE_FORMAT='+%Y-%m-%d %H:%M:%S%z'
;;
Linux )
DATE_FORMAT='--rfc-3339=seconds'
;;
* )
fatal "OS not supported ($THISOS)" TRUE
;;
esac
#=============================================================================
#
# Function fatal (Message, Force)
#
#=============================================================================
fatal ()
{
msg="$1"
FORCE="$2"
[ "$msg" ] || msg="Ctrl+C"
echo "$(date "$DATE_FORMAT") $SCRIPTNAME FATAL : $msg"
docker kill ${CONTAINERNAME}
docker rm ${CONTAINERNAME}
rm -f ${SERVERLOGFILE}
exit 1
}
#=============================================================================
#
# Function usage ()
#
#=============================================================================
usage()
{
cat << END_OF_USAGE
This script create a new container for the XWHEP server.
This is all created from sources downloaded from github.
Worker and client Debian packages are copied from the server container.
END_OF_USAGE
exit 0
}
#=============================================================================
#
# Main
#
#=============================================================================
trap fatal SIGINT SIGTERM
XWVERSION="11.5.0"
ROOTDIR="$(dirname "$0")"
SCRIPTNAME="$(basename "$0")"
XWJOBUID="$(date '+%Y-%m-%d-%H-%M-%S')"
IMAGENAME="xwhepimg_${XWJOBUID}"
CONTAINERNAME="xwhepcontainer_${XWJOBUID}"
DOCKERFILENAME="Dockerfile"
DOCKERFILE="${ROOTDIR}/Dockerfile"
SERVERLOGFILE="${ROOTDIR}/xwserver_${XWJOBUID}.log"
while [ $# -gt 0 ]; do
case "$1" in
--help )
usage
;;
-v | --verbose | --debug )
VERBOSE=1
set -x
;;
esac
shift
done
type docker > /dev/null 2>&1
if [ $? -ne 0 ] ; then
fatal "docker not installed"
fi
if [ ! -f ${DOCKERFILE} ] ; then
fatal "${DOCKERFILE} not found"
fi
docker build --force-rm --tag ${IMAGENAME} .
docker run --name ${CONTAINERNAME} ${IMAGENAME} > ${SERVERLOGFILE} 2>&1 &
COUNTER=0
while ( true ) ; do
grep "INFO : started, listening on port" ${SERVERLOGFILE} > /dev/null 2>&1
[ $? -eq 0 ] && break
COUNTER=$(( COUNTER + 1 ))
[ ${COUNTER} -gt 12 ] && fatal "There must be something wrong..."
sleep 10
done
docker cp ${CONTAINERNAME}:/xwhep/xtremweb-hep-master/build/dist/xwhep-${XWVERSION}/xwhep-server-${XWVERSION}.deb ${ROOTDIR}
docker cp ${CONTAINERNAME}:/xwhep/xtremweb-hep-master/build/dist/xwhep-${XWVERSION}/xwhep-server-conf-${XWVERSION}.deb ${ROOTDIR}
docker cp ${CONTAINERNAME}:/xwhep/xtremweb-hep-master/build/dist/xwhep-${XWVERSION}/xwhep-worker-${XWVERSION}.deb ${ROOTDIR}
docker cp ${CONTAINERNAME}:/xwhep/xtremweb-hep-master/build/dist/xwhep-${XWVERSION}/xwhep-client-${XWVERSION}.deb ${ROOTDIR}
docker kill ${CONTAINERNAME}
docker rm ${CONTAINERNAME}
rm -f ${SERVERLOGFILE}
cat << EOF_INFO
=================
You can now create and start worker & client containers.
Please open another terminal and copy :
- ${ROOTDIR}/xwhep-server-${XWVERSION}.deb to docker/server/ and build the worker container
- ${ROOTDIR}/xwhep-server-conf-${XWVERSION}.deb to docker/server/ and build the worker container
- ${ROOTDIR}/xwhep-worker-${XWVERSION}.deb to docker/worker/ and build the worker container
- ${ROOTDIR}/xwhep-client-${XWVERSION}.deb to docker/client/ and build the client container
=================
EOF_INFO
echo "Press any key"
read
exit 0
###########################################################
# EOF EOF EOF EOF EOF EOF #
###########################################################