-
Notifications
You must be signed in to change notification settings - Fork 0
/
launchsdi.sh
executable file
·126 lines (95 loc) · 3.08 KB
/
launchsdi.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
#!/bin/bash
PREFIX=$(dirname $0)
if [ ! -e $PREFIX'/sdi.conf' ]; then
echo "ERROR: The $PREFIX/sdi.conf file does not exist or can not be accessed"
exit 1
fi
source $PREFIX'/sdi.conf'
#test if config is loaded
if test $? != 0; then
echo "ERROR: failed to load $PREFIX/sdi.conf file"
exit 1
elif ! source $PREFIX/misc.sh; then
echo "ERROR: failed to load $PREFIX/misc.sh file"
exit 1
fi
# check if realpath command is available
test -x "$(which realpath)" ||
{ printf "FATAL: \"realpath\" must be installed\n" && exit 1; }
# define STATEDIR
STATEDIR=$WWWDIR/states
# Create necessary folders
SDIMKDIR $TMPDIR || exit 1
SDIMKDIR $PIDDIR || exit 1
SDIMKDIR $PIDDIRSYS || exit 1
SDIMKDIR $WWWDIR/hosts || exit 1
SDIMKDIR $STATEDIR || exit 1
SDIMKDIR $FIFODIR || exit 1
SDIMKDIR $CLASSESDIR || exit 1
# Start runing tunnels for hosts
CLASSES=$(ls $CLASSESDIR)
CLASSESNUM=$(ls $CLASSESDIR | wc -l)
if test $CLASSESNUM -eq 0; then
printf "ERROR: no class set. At least one class of hosts must be defined in $CLASSESDIR directory.\n"
exit 1
fi
# Check if web mode is enabled
if test $WEBMODE = true; then
source $SDIWEB/generatewebfiles.sh
# Start states daemon
printf "Launching states daemon... "
bash $PREFIX/states.sh
printf "done\n"
else
printf "WARNING: web mode is disabled.\n"
fi
# Open socketdaemon
# PS: Sockets foram usados pelo vinicius, essa versão utilizará o SSH, não sockets para comunicação...
#$PREFIX/socketdaemon.py & disown
# Start sendfile deamon
DAEMON="$PIDDIRSYS/sendfiledaemon.pid"
printf "Launching sendfile deamon... "
if (test -f $DAEMON && ! test -d /proc/$(cat $DAEMON)) ||
(! test -f $DAEMON); then
bash $PREFIX/launchsendfile.sh
else
printf "already running, "
fi
printf "done\n"
# Check if must use a fast dir or the disk
if test "$USEFASTDATADIR" = "yes"; then
SDIMKDIR "$FASTDATADIR" || exit 1
else
SDIMKDIR "$DATADIR" || exit 1
fi
# Start launching the tunnels
COUNT=0
for CLASS in $CLASSES; do
((COUNT++))
printf "\nStarting $CLASS ($COUNT/$CLASSESNUM)...\n"
sleep $LAUNCHDELAY
HOSTS=$(awk -F':' '{print $1}' $CLASSESDIR/$CLASS)
# Launch the tunnels
DAEMON=true CLASS=$CLASS $CORESHELL $PREFIX/launchsditunnel.sh "$HOSTS"
sleep $LAUNCHDELAY
done
#send the core to the clients
echo "DOCKER_REGISTRY_IP=$DOCKER_REGISTRY_IP" > $PREFIX/coresdi-client/config
echo "MAX_CONTAINERS_BY_HOST=1" >> $PREFIX/coresdi-client/config
bash $PREFIX/createcore.sh
#start docker registry if enable
if $DOCKER_REGISTRY = 'true'; then
#fazer if pra ver se o container existe, se nao existe cria, se não so executa
printf "\nInicializando Docker Registry (localhost:5000)..."
if [ ! -f $TMPDIR/.dkregistry ]; then
docker run -d -p 5000:5000 --name registry registry:2
echo 1 > $TMPDIR/.dkregistry
else
docker start registry
fi
echo "bash /coresdi-client/cfgdocker.sh" >> $CMDGENERAL
printf "Docker Registry Done..."
else
printf "WARNING: Docker Registry is not enabled. The function --createcontainer will not work!\n"
fi
printf "\nAll done.\n"