blob: 7233fdafa9c86c7b9c806ea8d460fe8ce5fd95c6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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
|