[d4e90c1] | 1 | #!/bin/bash |
---|
[ca6183e] | 2 | |
---|
| 3 | ### BEGIN INIT INFO |
---|
| 4 | # Provides: opengnsys |
---|
| 5 | # Required-Start: |
---|
| 6 | # Required-Stop: |
---|
| 7 | # Default-Start: 2 3 4 5 |
---|
| 8 | # Default-Stop: 1 |
---|
| 9 | # Short-Description: Servicios del sistema OpenGnSys |
---|
[9d859d0] | 10 | # Description: Servicios del sistema OpenGnSys |
---|
[ca6183e] | 11 | ### END INIT INFO |
---|
| 12 | |
---|
| 13 | # |
---|
| 14 | # Definiciones globales |
---|
| 15 | # |
---|
| 16 | BASEDIR=/opt/opengnsys |
---|
[e3d8dd1] | 17 | OPENGNSYSUSER="opengnsys" |
---|
| 18 | IMAGEDIR=$BASEDIR/images |
---|
| 19 | CLIENTLOGDIR=$BASEDIR/log/clients |
---|
[ca6183e] | 20 | |
---|
| 21 | # |
---|
| 22 | # Servidor de OpenGnSys |
---|
| 23 | # |
---|
| 24 | SERVERNAME=ogAdmServer |
---|
| 25 | SERVERDAEMON=$BASEDIR/sbin/$SERVERNAME |
---|
| 26 | SERVERCFG=$BASEDIR/etc/$SERVERNAME.cfg |
---|
| 27 | SERVERLOG=$BASEDIR/log/$SERVERNAME.log |
---|
| 28 | SERVERDAEMON_OPTIONS="-f $SERVERCFG -l $SERVERLOG" |
---|
| 29 | |
---|
| 30 | # |
---|
| 31 | # Servidor de Repositorio |
---|
| 32 | # |
---|
| 33 | REPONAME=ogAdmRepo |
---|
| 34 | REPODAEMON=$BASEDIR/sbin/$REPONAME |
---|
| 35 | REPOCFG=$BASEDIR/etc/$REPONAME.cfg |
---|
| 36 | REPOLOG=$BASEDIR/log/$REPONAME.log |
---|
| 37 | REPODAEMON_OPTIONS="-f $REPOCFG -l $REPOLOG" |
---|
[8fc9552] | 38 | ############## ADV |
---|
| 39 | REPOAUXNAME=ogAdmRepoAux |
---|
| 40 | REPOAUXDAEMON=$BASEDIR/sbin/$REPOAUXNAME |
---|
[e3d8dd1] | 41 | REPOAUXPORT=$(awk -F= '/PUERTO/ {print $2+1}' $SERVERCFG 2>/dev/null) |
---|
[8fc9552] | 42 | ############## ADV |
---|
[831830f] | 43 | ############# IRINA # para setBootMode desde el cliente |
---|
| 44 | SERVERAUXNAME=ogAdmServerAux |
---|
| 45 | SERVERAUXDAEMON=$BASEDIR/sbin/$SERVERAUXNAME |
---|
| 46 | SERVERAUXPORT=2011 |
---|
| 47 | ############# IRINA |
---|
[aeb0e7d7] | 48 | |
---|
| 49 | # |
---|
| 50 | # Servidor de tareas programadas |
---|
| 51 | # |
---|
| 52 | AGENTNAME=ogAdmAgent |
---|
| 53 | AGENTDAEMON=$BASEDIR/sbin/$AGENTNAME |
---|
| 54 | AGENTCFG=$BASEDIR/etc/$AGENTNAME.cfg |
---|
| 55 | AGENTLOG=$BASEDIR/log/$AGENTNAME.log |
---|
| 56 | AGENTDAEMON_OPTIONS="-f $AGENTCFG -l $AGENTLOG" |
---|
| 57 | |
---|
[ca6183e] | 58 | # |
---|
| 59 | # Opciones Bittorrent |
---|
| 60 | # |
---|
| 61 | |
---|
| 62 | BTTRACK=/usr/bin/bttrack.bittorrent |
---|
| 63 | BTSEEDER=/usr/bin/btlaunchmany.bittornado |
---|
| 64 | BTTRACKPORT=6969 |
---|
| 65 | BTTRACKDFILE=/tmp/dstate |
---|
[e3d8dd1] | 66 | BTTRACKLOG=$BASEDIR/log/bttrack.log |
---|
[ca6183e] | 67 | BTINTERVAL=30 |
---|
[e3d8dd1] | 68 | BTTORRENTSDIR=$BASEDIR/images |
---|
[1cf578b] | 69 | BTTRACK_OPTIONS=" --port $BTTRACKPORT --dfile $BTTRACKDFILE --reannounce_interval $BTINTERVAL --logfile $BTTRACKLOG --allowed_dir $BTTORRENTSDIR --allow_get 1" |
---|
[ca6183e] | 70 | BTTRACKPID="/var/run/bttrack.pid" |
---|
| 71 | BTSEEDERPID="/var/run/btseeder.pid" |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | export PATH="${PATH:+$PATH:}/usr/sbin:/sbin:/usr/bin" |
---|
| 75 | |
---|
| 76 | # Read config file if it is present. |
---|
[1cf578b] | 77 | if [ -r /etc/default/opengnsys ]; then |
---|
[4b08fa5] | 78 | source /etc/default/opengnsys |
---|
[ca6183e] | 79 | fi |
---|
| 80 | |
---|
[2777f20] | 81 | # Configuración de arranque según la distribución Linux usada. |
---|
| 82 | config() { |
---|
[6374326] | 83 | if [ -f /etc/os-release ]; then |
---|
| 84 | source /etc/os-release |
---|
[eeb438a] | 85 | OSDISTRIB="$ID" |
---|
[6374326] | 86 | else |
---|
| 87 | OSDISTRIB=$(lsb_release -is 2>/dev/null) |
---|
| 88 | fi |
---|
[eeb438a] | 89 | OSDISTRIB="${OSDISTRIB,,}" |
---|
[2777f20] | 90 | case "$OSDISTRIB" in |
---|
[eeb438a] | 91 | ubuntu|debian|linuxmint) |
---|
[5454b9d] | 92 | INITFUNCTIONS=/lib/lsb/init-functions |
---|
[e64207e] | 93 | DAEMONSTART="start-stop-daemon --start --quiet --background --exec" |
---|
| 94 | EXTRAOPTS="--" |
---|
[9d859d0] | 95 | DAEMONSTOP="start-stop-daemon --stop --quiet --oknodo --name" |
---|
[5454b9d] | 96 | ACTIONMSG="log_daemon_msg" |
---|
| 97 | SUCCESSMSG="log_end_msg 0" |
---|
| 98 | FAILMSG="log_end_msg 1" |
---|
[1cf578b] | 99 | TRACKERSTART="start-stop-daemon --make-pidfile --pidfile $BTTRACKPID --start --quiet --background --exec" |
---|
| 100 | BTTRACK_OPTIONS="$BTTRACK_OPTIONS --parse_allowed_interval 1" |
---|
[9d859d0] | 101 | TRACKERSTOP="start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile $BTTRACKPID" |
---|
[1cf578b] | 102 | SEEDERSTART="start-stop-daemon --make-pidfile --pidfile $BTSEEDERPID --start --quiet --background --exec" |
---|
| 103 | SEEDERSTOP="start-stop-daemon --stop --quiet --oknodo --pidfile $BTSEEDERPID" |
---|
[2777f20] | 104 | ;; |
---|
[eeb438a] | 105 | centos|fedora) |
---|
[5454b9d] | 106 | INITFUNCTIONS=/etc/init.d/functions |
---|
[2777f20] | 107 | DAEMONSTART="daemon" |
---|
[55477d2] | 108 | ENDOPTS="&" |
---|
[2777f20] | 109 | DAEMONSTOP="killproc" |
---|
[5454b9d] | 110 | ACTIONMSG="echo -n" |
---|
[55477d2] | 111 | SUCCESSMSG="eval ( success; echo )" |
---|
| 112 | FAILMSG="eval ( failure; echo )" |
---|
[1cf578b] | 113 | BTTRACK=/usr/bin/bttrack.py |
---|
| 114 | BTSEEDER=/usr/bin/btlaunchmany.py |
---|
| 115 | TRACKERSTART="daemon --pidfile $BTTRACKPID" |
---|
| 116 | TRACKERSTOP="killproc -p $BTTRACKPID $BTTRACK" |
---|
| 117 | SEEDERSTART="daemon --pidfile $BTSEEDERPID" |
---|
| 118 | SEEDERSTOP="killproc -p $BTSEEDERPID $BTSEEDER" |
---|
[2777f20] | 119 | ;; |
---|
[6ef01d9] | 120 | *) echo "Distribución Linux desconcocida o no soportada." |
---|
[2777f20] | 121 | exit ;; |
---|
| 122 | esac |
---|
[d4e90c1] | 123 | if [ -r $INITFUNCTIONS ]; then |
---|
[5454b9d] | 124 | source $INITFUNCTIONS |
---|
| 125 | fi |
---|
[2777f20] | 126 | } |
---|
| 127 | |
---|
[ca6183e] | 128 | arranca_demonios() { |
---|
[e3d8dd1] | 129 | # Comprobar que está instalado OpenGnSys. |
---|
| 130 | if [ ! -d $BASEDIR ]; then |
---|
| 131 | $ACTIONMSG "ERROR: No existe el directorio $BASEDIR" |
---|
| 132 | $FAILMSG |
---|
| 133 | exit $? |
---|
| 134 | fi |
---|
[ea60f41] | 135 | # Deshabilitar modo reforzado de SELinux. |
---|
| 136 | [ -f /selinux/enforce ] && echo 0 > /selinux/enforce |
---|
[e3d8dd1] | 137 | # Verificar permisos básicos. |
---|
| 138 | if [ "$(stat --printf="%A%G" $IMAGEDIR 2>/dev/null)" != "drwxrwxr-x$OPENGNSYSUSER" ]; then |
---|
| 139 | mkdir $IMAGEDIR 2>/dev/null |
---|
| 140 | chmod 775 $IMAGEDIR |
---|
| 141 | chgrp $OPENGNSYSUSER $IMAGEDIR |
---|
| 142 | fi |
---|
| 143 | if [ "$(stat --printf="%A%G" $CLIENTLOGDIR 2>/dev/null)" != "drwxrwxr-x$OPENGNSYSUSER" ]; then |
---|
| 144 | mkdir -p $CLIENTLOGDIR 2>/dev/null |
---|
| 145 | chmod 775 $CLIENTLOGDIR |
---|
| 146 | chgrp $OPENGNSYSUSER $CLIENTLOGDIR |
---|
| 147 | fi |
---|
| 148 | # Arrancar los servicios indicados. |
---|
[1cf578b] | 149 | if [ $RUN_OGADMSERVER = "yes" ]; then |
---|
[5454b9d] | 150 | $ACTIONMSG "Iniciando demonio: $SERVERNAME" |
---|
[55477d2] | 151 | $DAEMONSTART $SERVERDAEMON $EXTRAOPTS $SERVERDAEMON_OPTIONS $ENDOPTS |
---|
[5454b9d] | 152 | [ $? = 0 ] && $SUCCESSMSG || $FAILMSG |
---|
[831830f] | 153 | # Para SetBootmode desde el cliente |
---|
| 154 | $ACTIONMSG "Iniciando demonio: $SERVERAUXNAME" # |
---|
| 155 | faucet $SERVERAUXPORT --daemon --in bash -c "$SERVERAUXDAEMON" # NUEVO |
---|
| 156 | [ $? = 0 ] && $SUCCESSMSG || $FAILMSG |
---|
[ca6183e] | 157 | fi |
---|
[1cf578b] | 158 | if [ $RUN_OGADMSERVER = "yes" ] && [ $RUN_OGADMREPO = "yes" ]; then |
---|
[ca6183e] | 159 | sleep 5 # Damos tiempo a que ogAdmServer este funcionando |
---|
| 160 | fi |
---|
[1cf578b] | 161 | if [ $RUN_OGADMREPO = "yes" ]; then |
---|
[1eb49f5] | 162 | $ACTIONMSG "Iniciando demonio: $REPONAME" |
---|
| 163 | $DAEMONSTART $REPODAEMON $EXTRAOPTS $REPODAEMON_OPTIONS $ENDOPTS |
---|
| 164 | [ $? = 0 ] && $SUCCESSMSG || $FAILMSG |
---|
[5454b9d] | 165 | $ACTIONMSG "Iniciando demonio: $REPOAUXNAME" |
---|
| 166 | faucet $REPOAUXPORT --daemon --in bash -c "$REPOAUXDAEMON" |
---|
| 167 | [ $? = 0 ] && $SUCCESSMSG || $FAILMSG |
---|
[ca6183e] | 168 | fi |
---|
[1cf578b] | 169 | if [ $RUN_OGADMAGENT = "yes" ]; then |
---|
[5454b9d] | 170 | $ACTIONMSG "Iniciando demonio: $AGENTNAME" |
---|
[55477d2] | 171 | $DAEMONSTART $AGENTDAEMON $EXTRAOPTS $AGENTDAEMON_OPTIONS $ENDOPTS |
---|
[5454b9d] | 172 | [ $? = 0 ] && $SUCCESSMSG || $FAILMSG |
---|
[aeb0e7d7] | 173 | fi |
---|
[1cf578b] | 174 | if [ $RUN_BTTRACKER = "yes" ]; then |
---|
[5454b9d] | 175 | $ACTIONMSG "Iniciando demonio: $BTTRACK" |
---|
[1cf578b] | 176 | $TRACKERSTART $BTTRACK $EXTRAOPTS $BTTRACK_OPTIONS $ENDOPTS |
---|
[5454b9d] | 177 | [ $? = 0 ] && $SUCCESSMSG || $FAILMSG |
---|
[ca6183e] | 178 | fi |
---|
[1cf578b] | 179 | if [ $RUN_BTSEEDER = "yes" ]; then |
---|
[5454b9d] | 180 | $ACTIONMSG "Iniciando demonio: $BTSEEDER" |
---|
[1cf578b] | 181 | $SEEDERSTART $BTSEEDER $EXTRAOPTS $BTTORRENTSDIR &>/dev/null $ENDOPTS |
---|
[5454b9d] | 182 | [ $? = 0 ] && $SUCCESSMSG || $FAILMSG |
---|
[ca6183e] | 183 | fi |
---|
| 184 | |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | para_demonios() { |
---|
[1cf578b] | 188 | if [ -e $BTSEEDERPID ]; then |
---|
[5454b9d] | 189 | $ACTIONMSG "Parando demonio: $BTSEEDER" |
---|
[1cf578b] | 190 | $SEEDERSTOP |
---|
[5454b9d] | 191 | [ $? = 0 ] && $SUCCESSMSG || $FAILMSG |
---|
| 192 | rm -f $BTSEEDERPID |
---|
[ca6183e] | 193 | fi |
---|
[1cf578b] | 194 | if [ -e $BTTRACKPID ]; then |
---|
[5454b9d] | 195 | $ACTIONMSG "Parando demonio: $BTTRACK" |
---|
[1cf578b] | 196 | $TRACKERSTOP |
---|
[5454b9d] | 197 | [ $? = 0 ] && $SUCCESSMSG || $FAILMSG |
---|
| 198 | rm -f $BTTRACKPID |
---|
[aeb0e7d7] | 199 | fi |
---|
[5454b9d] | 200 | $ACTIONMSG "Parando demonio: $AGENTNAME" |
---|
[9d859d0] | 201 | $DAEMONSTOP $AGENTNAME |
---|
[5454b9d] | 202 | [ $? = 0 ] && $SUCCESSMSG || $FAILMSG |
---|
| 203 | $ACTIONMSG "Parando demonio: $REPONAME" |
---|
[9d859d0] | 204 | $DAEMONSTOP $REPONAME |
---|
[5454b9d] | 205 | [ $? = 0 ] && $SUCCESSMSG || $FAILMSG |
---|
| 206 | $ACTIONMSG "Parando demonio: $REPOAUXNAME" |
---|
[8fc9552] | 207 | pkill faucet |
---|
[4b08fa5] | 208 | [ $? -le 1 ] && $SUCCESSMSG || $FAILMSG |
---|
[5454b9d] | 209 | $ACTIONMSG "Parando demonio: $SERVERNAME" |
---|
[9d859d0] | 210 | $DAEMONSTOP $SERVERNAME |
---|
[5454b9d] | 211 | [ $? = 0 ] && $SUCCESSMSG || $FAILMSG |
---|
[ca6183e] | 212 | } |
---|
| 213 | |
---|
[2777f20] | 214 | config |
---|
| 215 | |
---|
[ca6183e] | 216 | case "$1" in |
---|
| 217 | start) |
---|
| 218 | arranca_demonios |
---|
| 219 | ;; |
---|
| 220 | stop) |
---|
| 221 | para_demonios |
---|
| 222 | ;; |
---|
| 223 | restart) |
---|
| 224 | para_demonios |
---|
| 225 | arranca_demonios |
---|
| 226 | ;; |
---|
| 227 | |
---|
| 228 | *) |
---|
[6ef01d9] | 229 | echo "Uso: $0 {start|stop|restart}" |
---|
[ca6183e] | 230 | exit 1 |
---|
| 231 | ;; |
---|
| 232 | esac |
---|
| 233 | |
---|
| 234 | exit 0 |
---|
[e3d8dd1] | 235 | |
---|