PLATFORM_IF_MATCH(linux)
PLATFORM_ELSE
PLATFORM_ENDIF
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
#include
#include
+#include
#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);
]]>
:
./package/compile
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
:
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.rclocal.orig
mv package/boot.rclocal package/boot.rclocal.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}
&1
exec /command/multilog t /usr/local/var/multilog/svscan
]]>
/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"
]]>
/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
]]>
/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
]]>
/tmp/svscan.rc.log 2>&1
SZ:S016:once:/command/svscan.rc stop < /dev/null
]]>
/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
]]>
$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"
]]>
description daemontools - a collection of tools for managing UNIX services
exclude src
exclude package