First commit of tag changes. bug-1444
[cacert-devel.git] / CommModule / commdaemon
1 #! /bin/bash
2 # @(#)(CAcert) $Id: commdaemon,v 1.2 2009-12-28 15:14:40 wytze Exp $
3 # commdaemon - script to run CommModule script in a loop,
4 # while checking for removal of activation by external script
5
6 NAME=CommModule/commdaemon
7 PID=$$
8 TAG=${NAME}\[${PID}]
9
10 case $# in
11 1) SCRIPT=$1
12 ACTIVE=${SCRIPT}-active
13 ;;
14 *) echo "Usage: $0 <script>" 1>&2
15 exit 1
16 ;;
17 esac
18
19 syslog_error()
20 {
21 logger -t ${TAG} -p user.err $1
22 }
23
24 syslog_notice()
25 {
26 logger -t ${TAG} -p user.notice $1
27 }
28
29 if [ ! -x ${SCRIPT} ]
30 then
31 syslog_error "${SCRIPT} not found or not executable"
32 exit 1
33 fi
34
35 (echo -n "${TAG}: "; date) >${ACTIVE}
36
37 syslog_notice "main loop started"
38 while [ -f ${ACTIVE} ]
39 do
40 syslog_notice "${SCRIPT} started"
41 ${SCRIPT} >>nohup.out 2>&1
42 syslog_notice "${SCRIPT} ended"
43 sleep 1
44 done
45 syslog_notice "main loop stopped"