diff options
Diffstat (limited to 'package/service')
-rwxr-xr-x | package/service | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/package/service b/package/service new file mode 100755 index 0000000..7233fda --- /dev/null +++ b/package/service @@ -0,0 +1,83 @@ +#!/bin/sh + +shout() { echo "${0}: $@" >&2; } +barf() { shout "fatal: $@"; exit 111; } +safe() { "$@" || barf "cannot $@"; } + +safe umask 022 +here=`env - PATH=$PATH pwd` +mypwd=${here%package} +mypwd=${mypwd%/} +home=`head -1 $mypwd/conf-home` +logdir=`head -1 $mypwd/conf-log` +svcdir=`head -1 $mypwd/conf-svcdir` +[ -d $home/control ] || barf "no control directory" + +nofiles=`grep auxiliar $mypwd/conf-ids | awk -F: '{print $2}'` +qmaill=`grep Log $mypwd/conf-ids | awk -F: '{print $2}'` + +[ -d ${svcdir} ] || barf "No /service directory available." +[ `which supervise` ] || barf "No supervise available. Skipping" +[ `which multilog` ] || log=0 + +for i in `sed -e '/^svc:/!d' -e 's/^svc://' < package/services=d` +do + all="$all $i" +done + +# Generate log service dir + +[ "X$logdir" = "X" ] || safe mkdir -p $logdir +[ -d $logdir ] && log=1 + +# Walks thru all configured services + +for i in $all +do + service=`echo $i | awk -F: '{print $1}'` + svcname=`echo $i | awk -F: '{print $2}'` + svc_run=`echo $i | awk -F: '{print $3}'` + +# Generate $home/svc dirs and populate + + [ ! -d /$home/svc/$svcname ] && \ + safe mkdir -p $home/svc/$svcname && \ + safe cat $mypwd/service/$svc_run \ + | eval sed -e 's}/var/qmail}$home}g' \ + > $home/svc/$svcname/run && \ + safe chmod +x $home/svc/$svcname/run && \ + safe touch $home/svc/$svcname/down && \ + shout "Created '$home/svc/$svcname' dir" + +# Generate logdir for services and set permissions + + [ ! -d $logdir/$svcname -a $log -eq 1 ] && \ + safe mkdir -p $logdir/$svcname && \ + shout "Created '$logdir/$svcname' dir" + + [ -d $logdir/$svcname -a $log -eq 1 ] && \ + safe chown $qmaill:$nofiles $logdir/$svcname && \ + shout "Set permissions for '$logdir/$svcname' dir" + +# Include log services + + [ ! -d /$home/svc/$svcname/log -a -d $logdir/$svcname -a $log -eq 1 ] && \ + safe mkdir -p $home/svc/$svcname/log && \ + safe cat $mypwd/service/run_log \ + | eval sed -e 's}qmaill}$qmaill}g' \ + -e 's}nofiles}$nofiles}g' \ + > $home/svc/$svcname/log/run && \ + safe chmod +x $home/svc/$svcname/log/run && \ + safe ln -s $logdir/$svcname $home/svc/$svcname/log/main && \ + shout "Created '$home/svc/$svcname/log' dir" + +# Put the service under supervise (/$svcdir) + + [ ! -d /$svcdir/$svcname ] && \ + safe ln -s $home/svc/$svcname /$svcdir/$svcname && \ + safe ln -s $home/control /$svcdir/$svcname/ctl && \ + shout "Created '/$svcdir/$svcname' dir -- still 'down'" + +done + +exit 0 |