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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
|
<?xml version="1.0"?>
<!-- $Id$ -->
<encap_profile
profile_ver="1.0"
pkgspec="daemontools-0.76"
>
<prereq package="m4-1.4.4" />
<prereq package="patch-2.5.9" />
<environment
variable="CC"
value="gcc"
type="set"
/>
<environment
variable="PATH"
PLATFORM_IF_MATCH(solaris)
value="/usr/local/lib/bcfg2/bin:/usr/local/bin:/usr/sfw/bin:/usr/ccs/bin:"
PLATFORM_ELSE
value="/usr/local/lib/bcfg2/bin:/usr/local/bin:"
PLATFORM_ENDIF
type="prepend"
/>
PLATFORM_IF_MATCH(linux)
PLATFORM_ELSE
<environment
variable="MAKE"
value="gmake"
type="set"
/>
PLATFORM_ENDIF
<source
url="http://www.pobox.com/users/dclark/mirror/daemontools/daemontools-0.76.tar.gz
http://cr.yp.to/daemontools/daemontools-0.76.tar.gz"
use_objdir="no"
subdir="admin/daemontools-0.76"
>
<patch options="-p1"><![CDATA[
#
# http://www.gluelogic.com/code/
#
diff -ru daemontools-0.76/src/error.h daemontools-0.76.new/src/error.h
--- daemontools-0.76/src/error.h 2001-07-12 12:49:49.000000000 -0400
+++ daemontools-0.76.new/src/error.h 2004-01-10 06:50:37.000000000 -0500
@@ -3,7 +3,7 @@
#ifndef ERROR_H
#define ERROR_H
-extern int errno;
+#include <errno.h>
extern int error_intr;
extern int error_nomem;
diff -ru daemontools-0.76/src/svscan.c daemontools-0.76.new/src/svscan.c
--- daemontools-0.76/src/svscan.c 2001-07-12 12:49:49.000000000 -0400
+++ daemontools-0.76.new/src/svscan.c 2004-02-08 01:50:27.000000000 -0500
@@ -1,6 +1,7 @@
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <fcntl.h>
#include "direntry.h"
#include "strerr.h"
#include "error.h"
@@ -14,6 +15,11 @@
#define SERVICES 1000
+#ifndef SVSCANINFO
+#define SVSCANINFO ".svscan" /* must begin with dot ('.') */
+#endif
+
+#define INFO "svscan: info: "
#define WARNING "svscan: warning: "
#define FATAL "svscan: fatal: "
@@ -38,7 +44,7 @@
int i;
const char *args[3];
- if (fn[0] == '.') return;
+ if (fn[0] == '.' && str_diff(fn,SVSCANINFO)) return;
if (stat(fn,&st) == -1) {
strerr_warn4(WARNING,"unable to stat ",fn,": ",&strerr_sys);
@@ -59,7 +65,8 @@
}
x[i].ino = st.st_ino;
x[i].dev = st.st_dev;
- x[i].pid = 0;
+ /*(fn[0]=='.' here only if SVSCANINFO; if so only supervise log/ subdir)*/
+ x[i].pid = (fn[0] != '.') ? 0 : -1;
x[i].pidlog = 0;
x[i].flaglog = 0;
@@ -190,12 +197,39 @@
}
}
+static void open_svscan_log(void)
+{
+ const int i = numx;
+ struct stat st;
+ static char fn[] = SVSCANINFO; /* avoid compiler warning on const string */
+
+ /* (semi-paranoid; could be moreso) */
+ if (fstat(STDIN_FILENO,&st) != 0 && errno == EBADF)
+ (void) open("/dev/null", O_RDONLY);
+ if (fstat(STDOUT_FILENO,&st) != 0 && errno == EBADF)
+ (void) open("/dev/null", O_WRONLY);
+ if (fstat(STDERR_FILENO,&st) != 0 && errno == EBADF)
+ (void) open("/dev/null", O_WRONLY);
+
+ if (stat(fn,&st) == 0) {
+ start(fn);
+ if (i+1 == numx && x[i].pidlog != 0) {
+ (void) dup2(x[i].pi[1], STDOUT_FILENO);
+ (void) dup2(x[i].pi[1], STDERR_FILENO);
+ strerr_warn1("",0);
+ strerr_warn2(INFO,"*** Starting svscan",0);
+ }
+ }
+}
+
int main(int argc,char **argv)
{
if (argv[0] && argv[1])
if (chdir(argv[1]) == -1)
strerr_die4sys(111,FATAL,"unable to chdir to ",argv[1],": ");
+ open_svscan_log();
+
for (;;) {
doit();
sleep(5);
]]></patch>
<patch options="-p1"><![CDATA[
# daemontools-0.76.sigq12.patch
#
# This patch adds the following signal capabilities to the
# daemontools-0.76 "svc"/"supervise" utilities:
#
# option signal
# ------ -------
# svc -q SIGQUIT
# svc -1 SIGUSR1
# svc -2 SIGUSR2
#
# Apply the patch:
#
# # cd /package/admin/daemontools-0.76
# # patch -p1 < /path/to/this/patch
#
# Then (re)compile/(re)install daemontools:
#
# # package/install
#
# Notes:
#
# The SIGUSR1/SIGUSR2 patch originally by Scott Gifford:
# http://www.suspectclass.com/~sgifford/daemontools/daemontools-0.76-usr12.README
#
# We added SIGQUIT for the mathopd web server:
# http://thedjbway.org/services/mathopd.html
#
# wcm, 2004.03.17 - 2004.03.17
# ===
diff -ru daemontools-0.76/src/supervise.c daemontools-0.76.sigq12/src/supervise.c
--- daemontools-0.76/src/supervise.c Thu Jul 12 19:49:49 2001
+++ daemontools-0.76.sigq12/src/supervise.c Wed Mar 17 10:30:25 2004
@@ -187,6 +187,15 @@
case 'i':
if (pid) kill(pid,SIGINT);
break;
+ case 'q':
+ if (pid) kill(pid,SIGQUIT);
+ break;
+ case '1':
+ if (pid) kill(pid,SIGUSR1);
+ break;
+ case '2':
+ if (pid) kill(pid,SIGUSR2);
+ break;
case 'p':
flagpaused = 1;
announce();
diff -ru daemontools-0.76/src/svc.c daemontools-0.76.sigq12/src/svc.c
--- daemontools-0.76/src/svc.c Thu Jul 12 19:49:49 2001
+++ daemontools-0.76.sigq12/src/svc.c Wed Mar 17 10:31:47 2004
@@ -27,9 +27,9 @@
sig_ignore(sig_pipe);
- while ((opt = getopt(argc,argv,"udopchaitkx")) != opteof)
+ while ((opt = getopt(argc,argv,"udopchaitkxq12")) != opteof)
if (opt == '?')
- strerr_die1x(100,"svc options: u up, d down, o once, x exit, p pause, c continue, h hup, a alarm, i interrupt, t term, k kill");
+ strerr_die1x(100,"svc options: u up, d down, o once, x exit, p pause, c continue, h hup, a alarm, i interrupt, t term, k kill, q quit, 1 SIGUSR1, 2 SIGUSR2");
else
if (datalen < sizeof data)
if (byte_chr(data,datalen,opt) == datalen)
]]></patch>
<patch options="-p2"><![CDATA[
diff -ur admin/daemontools-0.76-orig/src/supervise.c admin/daemontools-0.76/src/supervise.c
--- admin/daemontools-0.76-orig/src/supervise.c 2001-07-12 12:49:27.000000000 -0400
+++ admin/daemontools-0.76/src/supervise.c 2005-12-27 16:15:41.000000000 -0500
@@ -148,7 +148,6 @@
pidchange();
announce();
if (flagexit) return;
- if (flagwant && flagwantup) trystart();
break;
}
}
@@ -165,7 +164,6 @@
flagwant = 1;
flagwantup = 1;
announce();
- if (!pid) trystart();
break;
case 'o':
flagwant = 0;
@@ -202,6 +200,8 @@
announce();
break;
}
+
+ if (!pid && flagwant && flagwantup) trystart();
}
}
]]></patch>
<configure>
:
</configure>
<build>
./package/compile
</build>
<install>
test -d ${ENCAP_SOURCE} || mkdir ${ENCAP_SOURCE}
test -d ${ENCAP_SOURCE}/${ENCAP_PKGNAME} || mkdir ${ENCAP_SOURCE}/${ENCAP_PKGNAME}
test -d ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/bin || mkdir ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/bin
test -d ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/src || mkdir ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/src
test -d ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/package || mkdir ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/package
cp command/* ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/bin
cp package/run ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/package
cp package/commands ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/package
cp package/boot.inittab ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/package
cp package/boot.rclocal ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/package
cp package/run.inittab ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/package
cp package/run.rclocal ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/package
</install>
<clean>
:
</clean>
</source>
<prepackage>
mv package/run package/run.orig
mv package/run.inittab package/run.inittab.orig
mv package/boot.inittab package/boot.inittab.orig
mv package/run.rclocal package/run.inittab.orig
mv package/boot.rclocal package/boot.inittab.orig
test -d var || mkdir var
test -d var/svc.d || mkdir var/svc.d
test -d var/svc.d/svscan || mkdir var/svc.d/svscan
test -d var/svc.d/svscan/log || mkdir var/svc.d/svscan/log
# Make "this encap is installed" sentinal file available in /usr/local/var/encap
test -d var/encap || mkdir var/encap
touch var/encap/${ENCAP_PKGNAME}
</prepackage>
<include_file name="var/svc.d/svscan/log/run" mode="0755"><![CDATA[
#!/bin/sh
exec 2>&1
exec /command/multilog t /usr/local/var/multilog/svscan
]]></include_file>
<include_file name="bin/svrm" mode="0755"><![CDATA[
#!/bin/sh
# Remove a daemontools service
PATH=/command:$PATH
export PATH
if [ "${1}x" = "x" -o "${2}x" != "x" ]; then
printf "Usage: svrm [SERVICE]\n"
exit 1
fi
SERVICE="`basename ${1}`"
if [ ! -e "/service/$SERVICE" ]; then
printf "Service \"${SERVICE}\" not installed. Installed services:\n"
svstat /service/*
exit 1
else
cd /service/$SERVICE
REALDIR=`pwd -P`
rm /service/$SERVICE
svc -dx . log
rm -rf ${REALDIR}/supervise
rm -rf ${REALDIR}/log/supervise
fi
exit 0
]]></include_file>
<include_file name="bin/svscan.rc" mode="0755"><![CDATA[
#!/bin/sh
# svscan.rc - replacement for /command/svscanboot
# * Combined with .svscan patch, logs svscan to a file
# * If /service/*/shutdown exists, run it before killing service
PATH=/command:/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin
SERVICES=${2:-"/service"}
exec </dev/null >/dev/null 2>&1
for log_dir in "$SERVICES"/*/log "$SERVICES"/.svscan/log; do
if [ -d "$log_dir" ] \
&& svok "$log_dir" \
&& svstat "$log_dir" | grep -q ": up"
then
svc -ox "$log_dir"
fi
done
for service_dir in "$SERVICES"/*; do
if [ -d "$service_dir" ] \
&& svok "$service_dir" \
&& svstat "$service_dir" | grep -q ": up"
then
[ -x "$service_dir"/shutdown ] && "$service_dir"/shutdown
svc -dx "$service_dir"
fi
done
[ "$1" = "start" ] && exec env - PATH=$PATH svscan "$SERVICES"
]]></include_file>
<include_file name="package/run" mode="0755"><![CDATA[
#!/bin/sh -e
umask 022
test -d package || ( echo 'Wrong working directory.'; exit 1 )
test -d src || ( echo 'Wrong working directory.'; exit 1 )
if test -d /service
then
echo '/service exists. I assume that svscan is already running.'
exit 0
fi
echo 'Creating /service...'
mkdir /service
echo 'Creating symlink /service/.svscan -> /usr/local/var/svc.d/svscan ...'
ln -s /usr/local/var/svc.d/svscan /service/.svscan
if test -r /etc/inittab
then
/command/setlock /etc/inittab package/run.inittab
else
/command/setlock /etc/rc.local package/run.rclocal
fi
]]></include_file>
<include_file name="package/run.inittab" mode="0755"><![CDATA[
#!/bin/sh -e
if grep svscan.rc /etc/inittab >/dev/null
then
echo 'inittab contains an svscan.rc line. I assume that svscan is already running.
'
else
echo 'Adding svscan.rc to inittab...'
rm -f /etc/inittab'{new}'
cat /etc/inittab package/boot.inittab > /etc/inittab'{new}'
mv -f /etc/inittab'{new}' /etc/inittab
kill -HUP 1
echo 'init should start svscan now.'
fi
]]></include_file>
<include_file name="package/boot.inittab" mode="0644"><![CDATA[
SV:2345:respawn:/command/svscan.rc start
SZ:S016:once:/command/svscan.rc stop
]]></include_file>
<include_file name="package/run.rclocal" mode="0755"><![CDATA[
#!/bin/sh -e
if grep svscan.rc /etc/rc.local >/dev/null
then
echo 'rc.local contains an svscan.rc line. I assume that svscan is already running
.'
else
echo 'Adding svscan.rc to /etc/rc.local...'
rm -f /etc/rc.local'{new}'
cat /etc/rc.local package/boot.rclocal > /etc/rc.local'{new}'
mv -f /etc/rc.local'{new}' /etc/rc.local
echo 'Reboot now to start svscan.'
fi
]]></include_file>
<include_file name="package/boot.rclocal" mode="0644"><![CDATA[
csh -cf '/command/svscan.rc start &'
]]></include_file>
<include_file name="postinstall" mode="0755"><![CDATA[
#!/bin/sh -e
umask 002
BASEDIR="`echo ${0} | xargs -n1 dirname`"
LOG=${BASEDIR}/postinstall.log
exec > $LOG 2>&1
printf "Running daemontools postinstall script...\n"
date
test -d /usr/local/var || mkdir /usr/local/var
test -d /usr/local/var/multilog || mkdir /usr/local/var/multilog
test -d /usr/local/var/multilog/svscan || mkdir /usr/local/var/multilog/svscan
test -h /command || ln -s /usr/local/encap/daemontools-0.76/bin /command
cd /usr/local/encap/daemontools-0.76 && ./package/run
printf "Finished daemontools postinstall script.\n"
]]></include_file>
<encapinfo>
description daemontools - a collection of tools for managing UNIX services
exclude src
exclude package
</encapinfo>
</encap_profile>
|