Skip to content

Instantly share code, notes, and snippets.

@kaorukobo
Created May 15, 2011 01:46
Show Gist options
  • Save kaorukobo/972822 to your computer and use it in GitHub Desktop.
Save kaorukobo/972822 to your computer and use it in GitHub Desktop.
Reduce/less disk seek patch for daemontools-0.76 ( delays the scanning interval to 15sec (default is 5sec) - can change with 'export SVSCAN_INTERVAL_SEC=nnn'), suitable for developer's machine!)
Index: daemontools-0.76/src/supervise.c
===================================================================
RCS file: /home/shirai/root/cvs/project/other/daemontools/daemontools-0.76/src/supervise.c,v
retrieving revision 1.1.1.1
retrieving revision 1.4
diff -u -r1.1.1.1 -r1.4
--- daemontools-0.76/src/supervise.c 16 Dec 2001 02:54:52 -0000 1.1.1.1
+++ daemontools-0.76/src/supervise.c 30 May 2002 07:33:07 -0000 1.4
@@ -15,6 +15,10 @@
#include "iopause.h"
#include "taia.h"
#include "deepsleep.h"
+#include "scan.h"
+
+#define IOPAUSE_TIMEOUT_ENV "SUPERVISE_MONITOR_MSEC"
+#define IOPAUSE_TIMEOUT_DEFAULT 30000
#define FATAL "supervise: fatal: "
#define WARNING "supervise: warning: "
@@ -34,6 +38,8 @@
char status[18];
+int iopause_timeout = IOPAUSE_TIMEOUT_DEFAULT;
+
void pidchange(void)
{
struct taia now;
@@ -130,7 +136,7 @@
x[1].fd = fdcontrol;
x[1].events = IOPAUSE_READ;
taia_now(&stamp);
- taia_uint(&deadline,3600);
+ taia_uint(&deadline, iopause_timeout);
taia_add(&deadline,&stamp,&deadline);
iopause(x,2,&deadline,&stamp);
@@ -205,6 +211,17 @@
}
}
+/* terminate supervised program on SIGTERM. */
+void on_sig_term(void)
+{
+ flagwant = 1;
+ flagwantup = 0;
+ if (pid) { kill(pid,SIGTERM); kill(pid,SIGCONT); flagpaused = 0; }
+ announce();
+ flagexit = 1;
+ announce();
+}
+
int main(int argc,char **argv)
{
struct stat st;
@@ -213,6 +230,15 @@
if (!dir || argv[2])
strerr_die1x(100,"supervise: usage: supervise dir");
+ {
+ char * iopause_timeout_env = env_get(IOPAUSE_TIMEOUT_ENV);
+ if (iopause_timeout_env) {
+ unsigned long msec;
+ scan_ulong(iopause_timeout_env, &msec);
+ iopause_timeout = (int)msec;
+ }
+ }
+
if (pipe(selfpipe) == -1)
strerr_die4sys(111,FATAL,"unable to create pipe for ",dir,": ");
coe(selfpipe[0]);
@@ -222,6 +248,8 @@
sig_block(sig_child);
sig_catch(sig_child,trigger);
+
+ sig_catch(sig_term, on_sig_term);
if (chdir(dir) == -1)
strerr_die4sys(111,FATAL,"unable to chdir to ",dir,": ");
Index: daemontools-0.76/src/svscan.c
===================================================================
RCS file: /home/shirai/root/cvs/project/other/daemontools/daemontools-0.76/src/svscan.c,v
retrieving revision 1.1.1.1
retrieving revision 1.4
diff -u -r1.1.1.1 -r1.4
--- daemontools-0.76/src/svscan.c 16 Dec 2001 02:54:52 -0000 1.1.1.1
+++ daemontools-0.76/src/svscan.c 30 May 2002 07:34:04 -0000 1.4
@@ -1,6 +1,7 @@
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <signal.h>
#include "direntry.h"
#include "strerr.h"
#include "error.h"
@@ -8,12 +9,17 @@
#include "coe.h"
#include "fd.h"
#include "env.h"
+#include "sig.h"
#include "str.h"
#include "byte.h"
#include "pathexec.h"
+#include "scan.h"
#define SERVICES 1000
+#define SCAN_INTERVAL_ENV "SVSCAN_INTERVAL_SEC"
+#define SCAN_INTERVAL_DEFAULT 15
+
#define WARNING "svscan: warning: "
#define FATAL "svscan: fatal: "
@@ -190,14 +196,42 @@
}
}
+/* terminate each supervise on SIGTERM. */
+void on_sig_term(void)
+{
+ int i;
+ for (i = 0; i < numx; ++i) {
+ if (x[i].pid) {
+ kill(x[i].pid, SIGTERM);
+ }
+ if (x[i].pidlog) {
+ kill(x[i].pidlog, SIGTERM);
+ }
+ }
+ _exit(0);
+}
+
int main(int argc,char **argv)
{
+ unsigned long scan_interval;
+
if (argv[0] && argv[1])
if (chdir(argv[1]) == -1)
strerr_die4sys(111,FATAL,"unable to chdir to ",argv[1],": ");
+ {
+ char * scan_interval_env = env_get(SCAN_INTERVAL_ENV);
+ if (scan_interval_env) {
+ scan_ulong(scan_interval_env, &scan_interval);
+ } else {
+ scan_interval = SCAN_INTERVAL_DEFAULT;
+ }
+ }
+
+ sig_catch(sig_term, on_sig_term);
+
for (;;) {
doit();
- sleep(5);
+ sleep(scan_interval);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment