summaryrefslogtreecommitdiffstats
path: root/admin/Sources/Services/opengnsys.init
blob: ba08c7adaa92cbc543093f019d6246b1ff4aa3eb (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
#! /bin/sh

##################################################################################################################
####### Script de arranque de los servicios de OpenGnSys: Servidor ogAdmServer, Servidor de repositorio ogAdmRepo,
####### Tracker Bittorrent y seeder de imagenes por Bittorrent
####### autor: jcxifre <jcxifre@unizar.es>
####### basado en http://www.epilogue.org/~xef4/start-stop-example
##################################################################################################################


### 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

#
# 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"

#
# Opciones Bittorrent
#

BTTRACK=/usr/bin/bttrack.bittorrent
BTSEEDER=/usr/bin/btlaunchmany.bittornado
BTTRACKPORT=6969
BTTRACKDFILE=/tmp/dstate
BTTRACKLOG=/opt/opengnsys/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"
BTTRACKPID="/var/run/bttrack.pid"
BTSEEDERPID="/var/run/btseeder.pid"


set -e
export PATH="${PATH:+$PATH:}/usr/sbin:/sbin:/usr/bin"

# Read config file if it is present.
if [ -r /etc/default/opengnsys ]
then
        . /etc/default/opengnsys
fi

arranca_demonios() {
  if [ $RUN_OGADMSERVER = "yes" ]
  then
     echo -n "Iniciando demonio: "$SERVERNAME
     start-stop-daemon --start --quiet --background --exec $SERVERDAEMON -- $SERVERDAEMON_OPTIONS
     echo "."
  fi
  if [ $RUN_OGADMSERVER = "yes" ] && [ $RUN_OGADMREPO = "yes" ]
  then
     sleep 5 # Damos tiempo a que ogAdmServer este funcionando
  fi
  if [ $RUN_OGADMREPO = "yes" ]
  then
     echo -n "Iniciando demonio: "$REPONAME
     start-stop-daemon --start --quiet  --background --exec $REPODAEMON -- $REPODAEMON_OPTIONS
     echo "."
  fi
  if [ $RUN_BTTRACKER = "yes" ]
  then
     echo -n "Iniciando demonio: "$BTTRACK
     start-stop-daemon --make-pidfile --pidfile $BTTRACKPID --start --quiet --background --exec $BTTRACK -- $BTTRACK_OPTIONS
     echo "."
  fi
  if [ $RUN_BTSEEDER = "yes" ]
  then
     echo -n "Iniciando demonio: "$BTSEEDER
     start-stop-daemon --make-pidfile --pidfile $BTSEEDERPID --start --quiet  --background --exec $BTSEEDER -- $BTTORRENTSDIR
     echo "."
  fi

}

para_demonios() {
  if [ -e $BTSEEDERPID ]
  then
    echo -n "Parando demonio: "$BTSEEDER
    start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile $BTSEEDERPID
	echo "."
    rm $BTSEEDERPID > /dev/null
  fi
  if [ -e $BTTRACKPID ]
  then
    echo -n "Parando demonio: "$BTTRACK
    start-stop-daemon --stop --quiet --oknodo --pidfile $BTTRACKPID
	echo "."
    rm $BTTRACKPID > /dev/null
  fi  
  echo -n "Parando demonio: "$REPONAME
  start-stop-daemon --stop --quiet --oknodo --name $REPONAME
  echo "."
  echo -n "Parando demonio: "$SERVERNAME
  start-stop-daemon --stop --quiet --oknodo --name $SERVERNAME
  echo "."
}

case "$1" in
  start)
        arranca_demonios
        ;;
  stop)
        para_demonios
        ;;
  restart)
        para_demonios
        arranca_demonios
        ;;

  *)
        echo "Uso: opengnsys "$1" {start|stop|restart}"
        exit 1
        ;;
esac

exit 0