blob: 863184f9b70803b566c202df0a60cc767dc79fda (
plain)
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
#!/bin/bash
### BEGIN INIT INFO
# Provides: opengnsys
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 1
# Short-Description: Servicios del sistema OpenGnSys
# Description: Servicios del sistema OpenGnSys:
### END INIT INFO
#
# Definiciones globales
#
BASEDIR=/opt/opengnsys
OPENGNSYSUSER="opengnsys"
IMAGEDIR=$BASEDIR/images
CLIENTLOGDIR=$BASEDIR/log/clients
#
# Servidor de OpenGnSys
#
SERVERNAME=ogAdmServer
SERVERDAEMON=$BASEDIR/sbin/$SERVERNAME
SERVERCFG=$BASEDIR/etc/$SERVERNAME.cfg
SERVERLOG=$BASEDIR/log/$SERVERNAME.log
SERVERDAEMON_OPTIONS="-f $SERVERCFG -l $SERVERLOG"
#
# Servidor de Repositorio
#
REPONAME=ogAdmRepo
REPODAEMON=$BASEDIR/sbin/$REPONAME
REPOCFG=$BASEDIR/etc/$REPONAME.cfg
REPOLOG=$BASEDIR/log/$REPONAME.log
REPODAEMON_OPTIONS="-f $REPOCFG -l $REPOLOG"
############## ADV
REPOAUXNAME=ogAdmRepoAux
REPOAUXDAEMON=$BASEDIR/sbin/$REPOAUXNAME
REPOAUXPORT=$(awk -F= '/PUERTO/ {print $2+1}' $SERVERCFG 2>/dev/null)
############## ADV
#
# Servidor de tareas programadas
#
AGENTNAME=ogAdmAgent
AGENTDAEMON=$BASEDIR/sbin/$AGENTNAME
AGENTCFG=$BASEDIR/etc/$AGENTNAME.cfg
AGENTLOG=$BASEDIR/log/$AGENTNAME.log
AGENTDAEMON_OPTIONS="-f $AGENTCFG -l $AGENTLOG"
#
# Opciones Bittorrent
#
BTTRACK=/usr/bin/bttrack.bittorrent
BTSEEDER=/usr/bin/btlaunchmany.bittornado
BTTRACKPORT=6969
BTTRACKDFILE=/tmp/dstate
BTTRACKLOG=$BASEDIR/log/bttrack.log
BTINTERVAL=30
BTTORRENTSDIR=$BASEDIR/images
BTALLOW_GET=1
BTTRACK_OPTIONS=" --port $BTTRACKPORT --dfile $BTTRACKDFILE --reannounce_interval $BTINTERVAL --logfile $BTTRACKLOG --allowed_dir $BTTORRENTSDIR --allow_get $BTALLOW_GET --parse_allowed_interval 1"
BTTRACKPID="/var/run/bttrack.pid"
BTSEEDERPID="/var/run/btseeder.pid"
export PATH="${PATH:+$PATH:}/usr/sbin:/sbin:/usr/bin"
# Read config file if it is present.
if [ -r /etc/default/opengnsys ]
then
source /etc/default/opengnsys
fi
# Configuración de arranque según la distribución Linux usada.
config() {
OSDISTRIB=$(lsb_release -is 2>/dev/null)
case "$OSDISTRIB" in
Ubuntu|Debian|LinuxMint)
INITFUNCTIONS=/lib/lsb/init-functions
DAEMONSTART="start-stop-daemon --start --quiet --background --exec"
EXTRAOPTS="--"
DAEMONSTOP="start-stop-daemon --stop --quiet --oknodo --exec"
ACTIONMSG="log_daemon_msg"
SUCCESSMSG="log_end_msg 0"
FAILMSG="log_end_msg 1"
;;
CentOS|Fedora)
INITFUNCTIONS=/etc/init.d/functions
DAEMONSTART="daemon"
ENDOPTS="&"
DAEMONSTOP="killproc"
ACTIONMSG="echo -n"
SUCCESSMSG="eval ( success; echo )"
FAILMSG="eval ( failure; echo )"
;;
*) echo "Distribución Linux desconcocida o no soportada."
exit ;;
esac
if [ -r $INITFUNCTIONS ]; then
source $INITFUNCTIONS
fi
}
arranca_demonios() {
# Comprobar que está instalado OpenGnSys.
if [ ! -d $BASEDIR ]; then
$ACTIONMSG "ERROR: No existe el directorio $BASEDIR"
$FAILMSG
exit $?
fi
# Verificar permisos básicos.
if [ "$(stat --printf="%A%G" $IMAGEDIR 2>/dev/null)" != "drwxrwxr-x$OPENGNSYSUSER" ]; then
mkdir $IMAGEDIR 2>/dev/null
chmod 775 $IMAGEDIR
chgrp $OPENGNSYSUSER $IMAGEDIR
fi
if [ "$(stat --printf="%A%G" $CLIENTLOGDIR 2>/dev/null)" != "drwxrwxr-x$OPENGNSYSUSER" ]; then
mkdir -p $CLIENTLOGDIR 2>/dev/null
chmod 775 $CLIENTLOGDIR
chgrp $OPENGNSYSUSER $CLIENTLOGDIR
fi
# Arrancar los servicios indicados.
if [ $RUN_OGADMSERVER = "yes" ]
then
$ACTIONMSG "Iniciando demonio: $SERVERNAME"
$DAEMONSTART $SERVERDAEMON $EXTRAOPTS $SERVERDAEMON_OPTIONS $ENDOPTS
[ $? = 0 ] && $SUCCESSMSG || $FAILMSG
fi
if [ $RUN_OGADMSERVER = "yes" ] && [ $RUN_OGADMREPO = "yes" ]
then
sleep 5 # Damos tiempo a que ogAdmServer este funcionando
fi
if [ $RUN_OGADMREPO = "yes" ]
then
$ACTIONMSG "Iniciando demonio: $REPONAME"
$DAEMONSTART $REPODAEMON $EXTRAOPTS $REPODAEMON_OPTIONS $ENDOPTS
[ $? = 0 ] && $SUCCESSMSG || $FAILMSG
############ ADV
$ACTIONMSG "Iniciando demonio: $REPOAUXNAME"
faucet $REPOAUXPORT --daemon --in bash -c "$REPOAUXDAEMON"
[ $? = 0 ] && $SUCCESSMSG || $FAILMSG
############ ADV
fi
if [ $RUN_OGADMAGENT = "yes" ]
then
$ACTIONMSG "Iniciando demonio: $AGENTNAME"
$DAEMONSTART $AGENTDAEMON $EXTRAOPTS $AGENTDAEMON_OPTIONS $ENDOPTS
[ $? = 0 ] && $SUCCESSMSG || $FAILMSG
fi
if [ $RUN_BTTRACKER = "yes" ]
then
$ACTIONMSG "Iniciando demonio: $BTTRACK"
start-stop-daemon --make-pidfile --pidfile $BTTRACKPID --start --quiet --background --exec $BTTRACK -- $BTTRACK_OPTIONS
[ $? = 0 ] && $SUCCESSMSG || $FAILMSG
fi
if [ $RUN_BTSEEDER = "yes" ]
then
$ACTIONMSG "Iniciando demonio: $BTSEEDER"
start-stop-daemon --make-pidfile --pidfile $BTSEEDERPID --start --quiet --background --exec $BTSEEDER -- $BTTORRENTSDIR
[ $? = 0 ] && $SUCCESSMSG || $FAILMSG
fi
}
para_demonios() {
if [ -e $BTSEEDERPID ]
then
$ACTIONMSG "Parando demonio: $BTSEEDER"
start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile $BTSEEDERPID
[ $? = 0 ] && $SUCCESSMSG || $FAILMSG
rm -f $BTSEEDERPID
fi
if [ -e $BTTRACKPID ]
then
$ACTIONMSG "Parando demonio: $BTTRACK"
start-stop-daemon --stop --quiet --oknodo --pidfile $BTTRACKPID
[ $? = 0 ] && $SUCCESSMSG || $FAILMSG
rm -f $BTTRACKPID
fi
$ACTIONMSG "Parando demonio: $AGENTNAME"
$DAEMONSTOP $AGENTDAEMON
[ $? = 0 ] && $SUCCESSMSG || $FAILMSG
$ACTIONMSG "Parando demonio: $REPONAME"
$DAEMONSTOP $REPODAEMON
[ $? = 0 ] && $SUCCESSMSG || $FAILMSG
############# ADV
$ACTIONMSG "Parando demonio: $REPOAUXNAME"
pkill faucet
[ $? -le 1 ] && $SUCCESSMSG || $FAILMSG
############ ADV
$ACTIONMSG "Parando demonio: $SERVERNAME"
$DAEMONSTOP $SERVERDAEMON
[ $? = 0 ] && $SUCCESSMSG || $FAILMSG
}
config
case "$1" in
start)
arranca_demonios
;;
stop)
para_demonios
;;
restart)
para_demonios
arranca_demonios
;;
*)
echo "Uso: $0 {start|stop|restart}"
exit 1
;;
esac
exit 0
|