Merge Stefan's changes for TIDS init scripts for Centos. 1.4
authorMargaret Wasserman <mrw@painless-security.com>
Tue, 23 Sep 2014 19:23:06 +0000 (15:23 -0400)
committerMargaret Wasserman <mrw@painless-security.com>
Tue, 23 Sep 2014 19:23:06 +0000 (15:23 -0400)
redhat/sysconfig.tids [new file with mode: 0644]
redhat/tids-wrapper [new file with mode: 0644]
tids.initd [new file with mode: 0644]
trust_router.spec

diff --git a/redhat/sysconfig.tids b/redhat/sysconfig.tids
new file mode 100644 (file)
index 0000000..a1e5b80
--- /dev/null
@@ -0,0 +1,17 @@
+## Define the variables needed to run TIDS
+##
+## /usr/bin/tids <ip-address> <gss-name> <hostname> <database-name>
+##
+
+TIDS_SERVER_IP="127.0.0.1"                              # IP address that the TIDS is reachable on
+TIDS_SERVER_NAME="localhost"                            # The host name that the TIDS is known as
+TIDS_USER="trustrouter"                                        # The user that the TIDS is running as
+TIDS_GROUP="trustrouter"                               # The group that the TIDS is running as 
+
+TIDS_GSS_NAME="trustrouter@apc.moonshot.ja.net"                # The GSS service name for the TIDS APC
+KEYFILE="/var/lib/trust_router/keys"                   # The key file that the TIDS will store keys in
+
+## Static variables that you can also adjust
+
+TIDS_PIDDIR="/var/run/tids"
+TIDS_LOGDIR="/var/log/tids"
diff --git a/redhat/tids-wrapper b/redhat/tids-wrapper
new file mode 100644 (file)
index 0000000..55e3d0d
--- /dev/null
@@ -0,0 +1,14 @@
+#! /usr/bin/env bash
+
+PIDFILE=${1}
+LOGFILE=${2}
+shift 2
+
+unset DISPLAY
+/usr/bin/tids $@ >> ${LOGFILE} 2>&1 &
+BGPID=$!
+RET=$?
+
+echo "${BGPID}" > "${PIDFILE}"
+
+exit "${RET}"
diff --git a/tids.initd b/tids.initd
new file mode 100644 (file)
index 0000000..3af387a
--- /dev/null
@@ -0,0 +1,108 @@
+#!/bin/bash
+### BEGIN INIT INFO
+# Provides: tids
+# Default-Start: 3 5
+# Default-Stop: 0 1 2 4 6
+# Required-Start: radiusd
+# Should-Start: $network
+# Short-Description: Starts Moonshot TIDS
+# Description: Starts the Moonshot Temporary ID Service
+### END INIT INFO
+# chkconfig: - 89 11
+#
+# description: Starts the Moonshot Temporary ID Service
+#
+# Source function library.
+. /etc/init.d/functions
+
+[ -z "$HOME" ] && export HOME=/
+
+usage() {
+    echo "Usage: $0 {start|stop|status}"
+}
+
+# Load the configuration
+[ -f /etc/sysconfig/tids ] || exit 6
+. /etc/sysconfig/tids
+
+# Create the PID and LOG directories
+[ -d ${TIDS_PIDDIR} ] || mkdir -p ${TIDS_PIDDIR} && chown ${TIDS_USER}:${TIDS_GROUP} ${TIDS_PIDDIR}
+[ -d ${TIDS_LOGDIR} ] || mkdir -p ${TIDS_LOGDIR} && chown ${TIDS_USER}:${TIDS_GROUP} ${TIDS_LOGDIR}
+
+# Some variables
+prog=/usr/bin/tids-wrapper
+PIDFILE="${TIDS_PIDDIR}/tids.pid"
+LOGFILE="${TIDS_LOGDIR}/tids.log"
+
+# Does the trust router and wrapper exist
+[ -x /usr/bin/tids ] || exit 5
+[ -x /usr/bin/tids-wrapper ] || exit 5
+
+[ -f ${LOGFILE} ] || touch ${LOGFILE} && chown ${TIDS_USER}:${TIDS_GROUP} ${LOGFILE}
+
+OPTIONS="${PIDFILE} ${LOGFILE} ${TIDS_SERVER_IP} ${TIDS_GSS_NAME} ${TIDS_SERVER_NAME} ${KEYFILE}"
+
+case "$1" in
+    start)
+        if [ -f ${PIDFILE} ] ;
+        then
+                OLD_PID=$(cat "${PIDFILE}")
+
+                if [ -d "/proc/${OLD_PID}" ] ;
+                then
+                        echo "Error: TIDS already running" ; exit 1
+                else
+                        rm ${PIDFILE}
+                fi
+        fi
+
+        timestamp=$(date)
+        echo "${timestamp} Starting TIDS..." >> ${LOGFILE}
+        echo -n "Starting TIDS..."
+        daemon --user="${TIDS_USER}" --pidfile="{PIDFILE}" "${prog}" "${OPTIONS}"
+        echo
+
+        exit $?
+        ;;
+    stop)
+        timestamp=$(date)
+        echo "${timestamp} Stopping TIDS..." >> ${LOGFILE}
+        echo -n "Stopping TIDS..."
+        if [ -f "${PIDFILE}" ] ;
+        then
+                killproc -p "${PIDFILE}" "${prog}"
+               echo
+       else
+               echo "TIDS does not appear to be running"
+       fi
+        exit $?
+        ;;
+    status)
+        if [ -f ${PIDFILE} ] ;
+        then
+                PID=$(cat "${PIDFILE}")
+
+                if [ -d "/proc/${PID}" ] ;
+                then
+                        echo "TIDS is running (pid ${PID})"
+                else
+                        if [ -e ${PIDFILE} ] ; then
+                                echo "TIDS appears to be dead but its PID file exists"
+                        else
+                                echo "TIDS appears to be stopped"
+                        fi
+                fi
+        else
+                echo "TIDS appears to be stopped"
+        fi
+        exit 0
+        ;;
+    reload | force-reload | condrestart | try-restart)
+        usage
+        exit 3
+        ;;
+    *)
+        usage
+        exit 2
+        ;;
+esac
index da46e7c..1d449ed 100644 (file)
@@ -60,6 +60,8 @@ install -D -m 640 redhat/trusts.cfg $RPM_BUILD_ROOT/%{_sysconfdir}/trust_router/
 install -D -m 640 redhat/default-main.cfg $RPM_BUILD_ROOT/%{_sysconfdir}/trust_router/conf.d/default/main.cfg
 install -D -m 640 redhat/tr-test-main.cfg $RPM_BUILD_ROOT/%{_sysconfdir}/trust_router/conf.d/tr-test/main.cfg
 install -D -m 640 redhat/sysconfig $RPM_BUILD_ROOT/%{_sysconfdir}/sysconfig/trust_router
+install -D -m 640 redhat/sysconfig.tids $RPM_BUILD_ROOT/%{_sysconfdir}/sysconfig/tids
+install -D -m 755 tids.initd $RPM_BUILD_ROOT/%{_initrddir}/tids
 
 # Link shared config
 ln -s ../../trusts.cfg $RPM_BUILD_ROOT/%{_sysconfdir}/trust_router/conf.d/default/trusts.cfg
@@ -67,6 +69,7 @@ ln -s ../../trusts.cfg $RPM_BUILD_ROOT/%{_sysconfdir}/trust_router/conf.d/tr-tes
 
 # Install wrapper scripts
 install -D -m 755 redhat/tidc-wrapper $RPM_BUILD_ROOT/%{_bindir}/tidc-wrapper
+install -D -m 755 redhat/tids-wrapper $RPM_BUILD_ROOT/%{_bindir}/tids-wrapper
 install -D -m 755 redhat/trust_router-wrapper $RPM_BUILD_ROOT/%{_bindir}/trust_router-wrapper
 
 # As we're building an RPM, we don't need the init scripts etc. in /usr/share
@@ -109,8 +112,10 @@ chmod 770 /var/log/trust_router
 %{_datadir}/trust_router/schema.sql
 #/lib/systemd/system/tids.service
 
+%{_initrddir}/tids
 %{_initrddir}/trust_router
 
+%config(noreplace) %{_sysconfdir}/sysconfig/tids
 %config(noreplace) %{_sysconfdir}/sysconfig/trust_router
 
 %dir %attr(755,root,trustrouter) %{_sysconfdir}/trust_router
@@ -132,6 +137,3 @@ chmod 770 /var/log/trust_router
 %defattr(-,root,root,-)
 %{_includedir}/*
 %{_libdir}/*.so
-
-
-