764ce1c9070f7207cc59f0ef22d076075ca84dfb
[trust_router.git] / tids.initd
1 #!/bin/bash
2 ### BEGIN INIT INFO
3 # Provides: tids
4 # Default-Start: 3 5
5 # Default-Stop: 0 1 2 4 6
6 # Required-Start: radiusd
7 # Should-Start: $network
8 # Short-Description: Starts Moonshot TIDS
9 # Description: Starts the Moonshot Temporary ID Service
10 ### END INIT INFO
11 # chkconfig: - 89 11
12 #
13 # description: Starts the Moonshot Temporary ID Service
14 #
15 # Source function library.
16 . /etc/init.d/functions
17
18 [ -z "$HOME" ] && export HOME=/
19
20 usage() {
21     echo "Usage: $0 {start|stop|status}"
22 }
23
24 # Load the configuration
25 [ -f /etc/sysconfig/tids ] || exit 6
26 . /etc/sysconfig/tids
27
28 # Create the PID and LOG directories
29 [ -d ${TIDS_PIDDIR} ] || mkdir -p ${TIDS_PIDDIR} && chown ${TIDS_USER}:${TIDS_GROUP} ${TIDS_PIDDIR}
30 [ -d ${TIDS_LOGDIR} ] || mkdir -p ${TIDS_LOGDIR} && chown ${TIDS_USER}:${TIDS_GROUP} ${TIDS_LOGDIR}
31
32 # Some variables
33 prog=/usr/bin/tids-wrapper
34 PIDFILE="${TIDS_PIDDIR}/tids.pid"
35 LOGFILE="${TIDS_LOGDIR}/tids.log"
36
37 # Does the trust router and wrapper exist
38 [ -x /usr/bin/tids ] || exit 5
39 [ -x /usr/bin/tids-wrapper ] || exit 5
40
41 [ -f ${LOGFILE} ] || touch ${LOGFILE} && chown ${TIDS_USER}:${TIDS_GROUP} ${LOGFILE}
42
43 OPTIONS="${PIDFILE} ${LOGFILE} ${TIDS_SERVER_IP} ${TIDS_GSS_NAME} ${TIDS_SERVER_NAME} ${KEYFILE}"
44
45 case "$1" in
46     start)
47         if [ -f ${PIDFILE} ] ;
48         then
49                 OLD_PID=$(cat "${PIDFILE}")
50                 if [ -d "/proc/${OLD_PID}" ] ;
51                 then
52                         echo "Error: TIDS already running" ; exit 1
53                 else
54                         rm ${PIDFILE}
55                 fi
56         fi
57
58         timestamp=$(date)
59         echo "${timestamp} Starting TIDS..." >> ${LOGFILE}
60         echo -n "Starting TIDS..."
61         daemon --user="${TIDS_USER}" --pidfile="{PIDFILE}" "${prog}" "${OPTIONS}"
62         echo
63
64         exit $?
65         ;;
66     stop)
67         timestamp=$(date)
68         echo "${timestamp} Stopping TIDS..." >> ${LOGFILE}
69         echo -n "Stopping TIDS..."
70         
71         if [ -f "${PIDFILE}" ]  ;
72         then
73             killproc -p "${PIDFILE}" "${prog}"
74             echo
75         else
76             echo "TIDS does not appear to be running..."
77         fi
78         exit $?
79         ;;
80     status)
81         PID=$(cat "${PIDFILE}")
82
83         if [ -d "/proc/${PID}" ] ;
84         then
85                 echo "TIDS is running (pid ${PID})"
86         else
87                 if [ -e ${PIDFILE} ] ; then
88                         echo "TIDS appears to be dead but its PID file exists"
89                 else
90                         echo "TIDS appears to be stopped"
91                 fi
92         fi
93         exit 0
94         ;;
95     reload | force-reload | condrestart | try-restart)
96         usage
97         exit 3
98         ;;
99     *)
100         usage
101         exit 2
102         ;;
103 esac