diff options
Diffstat (limited to 'admin/Sources/Services/opengnsys.init')
-rwxr-xr-x | admin/Sources/Services/opengnsys.init | 107 |
1 files changed, 68 insertions, 39 deletions
diff --git a/admin/Sources/Services/opengnsys.init b/admin/Sources/Services/opengnsys.init index 477cc99b..2c46fc70 100755 --- a/admin/Sources/Services/opengnsys.init +++ b/admin/Sources/Services/opengnsys.init @@ -7,13 +7,16 @@ # Default-Start: 2 3 4 5 # Default-Stop: 1 # Short-Description: Servicios del sistema OpenGnSys -# 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 @@ -35,7 +38,7 @@ REPODAEMON_OPTIONS="-f $REPOCFG -l $REPOLOG" ############## ADV REPOAUXNAME=ogAdmRepoAux REPOAUXDAEMON=$BASEDIR/sbin/$REPOAUXNAME -REPOAUXPORT=$((`cat $SERVERCFG | grep PUERTO | cut -f2 -d"="` + 1)) +REPOAUXPORT=$(awk -F= '/PUERTO/ {print $2+1}' $SERVERCFG 2>/dev/null) ############## ADV # @@ -55,11 +58,10 @@ BTTRACK=/usr/bin/bttrack.bittorrent BTSEEDER=/usr/bin/btlaunchmany.bittornado BTTRACKPORT=6969 BTTRACKDFILE=/tmp/dstate -BTTRACKLOG=/opt/opengnsys/log/bttrack.log +BTTRACKLOG=$BASEDIR/log/bttrack.log BTINTERVAL=30 -BTTORRENTSDIR=/opt/opengnsys/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" +BTTORRENTSDIR=$BASEDIR/images +BTTRACK_OPTIONS=" --port $BTTRACKPORT --dfile $BTTRACKDFILE --reannounce_interval $BTINTERVAL --logfile $BTTRACKLOG --allowed_dir $BTTORRENTSDIR --allow_get 1" BTTRACKPID="/var/run/bttrack.pid" BTSEEDERPID="/var/run/btseeder.pid" @@ -67,8 +69,7 @@ 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 +if [ -r /etc/default/opengnsys ]; then source /etc/default/opengnsys fi @@ -80,10 +81,30 @@ config() { INITFUNCTIONS=/lib/lsb/init-functions DAEMONSTART="start-stop-daemon --start --quiet --background --exec" EXTRAOPTS="--" - DAEMONSTOP="start-stop-daemon --stop --quiet --oknodo --exec" + DAEMONSTOP="start-stop-daemon --stop --quiet --oknodo --name" ACTIONMSG="log_daemon_msg" SUCCESSMSG="log_end_msg 0" FAILMSG="log_end_msg 1" + TRACKERSTART="start-stop-daemon --make-pidfile --pidfile $BTTRACKPID --start --quiet --background --exec" + BTTRACK_OPTIONS="$BTTRACK_OPTIONS --parse_allowed_interval 1" + TRACKERSTOP="start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile $BTTRACKPID" + SEEDERSTART="start-stop-daemon --make-pidfile --pidfile $BTSEEDERPID --start --quiet --background --exec" + SEEDERSTOP="start-stop-daemon --stop --quiet --oknodo --pidfile $BTSEEDERPID" + ;; + CentOS|Fedora) + INITFUNCTIONS=/etc/init.d/functions + DAEMONSTART="daemon" + ENDOPTS="&" + DAEMONSTOP="killproc" + ACTIONMSG="echo -n" + SUCCESSMSG="eval ( success; echo )" + FAILMSG="eval ( failure; echo )" + BTTRACK=/usr/bin/bttrack.py + BTSEEDER=/usr/bin/btlaunchmany.py + TRACKERSTART="daemon --pidfile $BTTRACKPID" + TRACKERSTOP="killproc -p $BTTRACKPID $BTTRACK" + SEEDERSTART="daemon --pidfile $BTSEEDERPID" + SEEDERSTOP="killproc -p $BTSEEDERPID $BTSEEDER" ;; *) echo "Distribución Linux desconcocida o no soportada." exit ;; @@ -94,76 +115,84 @@ config() { } arranca_demonios() { - if [ $RUN_OGADMSERVER = "yes" ] - then + # Comprobar que está instalado OpenGnSys. + if [ ! -d $BASEDIR ]; then + $ACTIONMSG "ERROR: No existe el directorio $BASEDIR" + $FAILMSG + exit $? + fi + # Deshabilitar modo reforzado de SELinux. + [ -f /selinux/enforce ] && echo 0 > /selinux/enforce + # 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 + $DAEMONSTART $SERVERDAEMON $EXTRAOPTS $SERVERDAEMON_OPTIONS $ENDOPTS [ $? = 0 ] && $SUCCESSMSG || $FAILMSG fi - if [ $RUN_OGADMSERVER = "yes" ] && [ $RUN_OGADMREPO = "yes" ] - then + if [ $RUN_OGADMSERVER = "yes" ] && [ $RUN_OGADMREPO = "yes" ]; then sleep 5 # Damos tiempo a que ogAdmServer este funcionando fi - if [ $RUN_OGADMREPO = "yes" ] - then + if [ $RUN_OGADMREPO = "yes" ]; then $ACTIONMSG "Iniciando demonio: $REPONAME" - $DAEMONSTART $REPODAEMON $EXTRAOPTS $REPODAEMON_OPTIONS + $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 + if [ $RUN_OGADMAGENT = "yes" ]; then $ACTIONMSG "Iniciando demonio: $AGENTNAME" - $DAEMONSTART $AGENTDAEMON $EXTRAOPTS $AGENTDAEMON_OPTIONS + $DAEMONSTART $AGENTDAEMON $EXTRAOPTS $AGENTDAEMON_OPTIONS $ENDOPTS [ $? = 0 ] && $SUCCESSMSG || $FAILMSG fi - if [ $RUN_BTTRACKER = "yes" ] - then + if [ $RUN_BTTRACKER = "yes" ]; then $ACTIONMSG "Iniciando demonio: $BTTRACK" - start-stop-daemon --make-pidfile --pidfile $BTTRACKPID --start --quiet --background --exec $BTTRACK -- $BTTRACK_OPTIONS + $TRACKERSTART $BTTRACK $EXTRAOPTS $BTTRACK_OPTIONS $ENDOPTS [ $? = 0 ] && $SUCCESSMSG || $FAILMSG fi - if [ $RUN_BTSEEDER = "yes" ] - then + if [ $RUN_BTSEEDER = "yes" ]; then $ACTIONMSG "Iniciando demonio: $BTSEEDER" - start-stop-daemon --make-pidfile --pidfile $BTSEEDERPID --start --quiet --background --exec $BTSEEDER -- $BTTORRENTSDIR + $SEEDERSTART $BTSEEDER $EXTRAOPTS $BTTORRENTSDIR &>/dev/null $ENDOPTS [ $? = 0 ] && $SUCCESSMSG || $FAILMSG fi } para_demonios() { - if [ -e $BTSEEDERPID ] - then + if [ -e $BTSEEDERPID ]; then $ACTIONMSG "Parando demonio: $BTSEEDER" - start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile $BTSEEDERPID + $SEEDERSTOP [ $? = 0 ] && $SUCCESSMSG || $FAILMSG rm -f $BTSEEDERPID fi - if [ -e $BTTRACKPID ] - then + if [ -e $BTTRACKPID ]; then $ACTIONMSG "Parando demonio: $BTTRACK" - start-stop-daemon --stop --quiet --oknodo --pidfile $BTTRACKPID + $TRACKERSTOP [ $? = 0 ] && $SUCCESSMSG || $FAILMSG rm -f $BTTRACKPID fi $ACTIONMSG "Parando demonio: $AGENTNAME" - $DAEMONSTOP $AGENTDAEMON + $DAEMONSTOP $AGENTNAME [ $? = 0 ] && $SUCCESSMSG || $FAILMSG $ACTIONMSG "Parando demonio: $REPONAME" - $DAEMONSTOP $REPODAEMON + $DAEMONSTOP $REPONAME [ $? = 0 ] && $SUCCESSMSG || $FAILMSG - ############# ADV $ACTIONMSG "Parando demonio: $REPOAUXNAME" pkill faucet [ $? -le 1 ] && $SUCCESSMSG || $FAILMSG - ############ ADV $ACTIONMSG "Parando demonio: $SERVERNAME" - $DAEMONSTOP $SERVERDAEMON + $DAEMONSTOP $SERVERNAME [ $? = 0 ] && $SUCCESSMSG || $FAILMSG } |