Merge pull request #62 from painless-security/jennifer/report_incoming_ipaddr
[trust_router.git] / redhat / tids.init
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
51                 if [ -d "/proc/${OLD_PID}" ] ;
52                 then
53                         echo "Error: TIDS already running" ; exit 1
54                 else
55                         rm ${PIDFILE}
56                 fi
57         fi
58
59         timestamp=$(date)
60         echo "${timestamp} Starting TIDS..." >> ${LOGFILE}
61         echo -n "Starting TIDS..."
62         daemon --user="${TIDS_USER}" --pidfile="${PIDFILE}" "${prog}" "${OPTIONS}"
63         echo
64
65         exit $?
66         ;;
67     stop)
68         timestamp=$(date)
69         echo "${timestamp} Stopping TIDS..." >> ${LOGFILE}
70         echo -n "Stopping TIDS..."
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         if [ -f ${PIDFILE} ] ;
82         then
83                 PID=$(cat "${PIDFILE}")
84
85                 if [ -d "/proc/${PID}" ] ;
86                 then
87                         echo "TIDS is running (pid ${PID})"
88                 else
89                         if [ -e ${PIDFILE} ] ; then
90                                 echo "TIDS appears to be dead but its PID file exists"
91                         else
92                                 echo "TIDS appears to be stopped"
93                         fi
94                 fi
95         else
96                 echo "TIDS appears to be stopped"
97         fi
98         exit 0
99         ;;
100     reload | force-reload | condrestart | try-restart)
101         usage
102         exit 3
103         ;;
104     *)
105         usage
106         exit 2
107         ;;
108 esac