Package: runit
Version: 2.1.1-6.2
Severity: wishlist
Tags: patch
Hi,
I use runit extensively in vservers. Restarting a vserver occasionally takes
a lot longer than necessary because runit(8) insists on calling sync()
before shutting down. This is desirable on physical hosts, of course, but
not in a vserver (which is basically just a glorified chroot).
I wrote a small patch that adds a /etc/runit/nosync flag file that, if it
exists, inhibits calling sync() on reboot/shutdown.
Please consider applying it.
Thanks
Andras
--
Andras Korn <korn at elan.rulez.org>
There is an answer to every question. Usually it's No.
diff -ru runit-2.1.1/doc/runit.8.html runit-2.1.1+nosync/doc/runit.8.html
--- runit-2.1.1/doc/runit.8.html 2009-10-04 22:44:02.000000000 +0200
+++ runit-2.1.1+nosync/doc/runit.8.html 2012-12-06 16:48:51.239082000 +0100
@@ -34,6 +34,8 @@
and possibly halt or reboot the system are done here. If stage 3 returns,
<b>runit</b> checks if the file <i>/etc/runit/reboot</i> exists and has the execute by
owner permission set. If so, the system is rebooted, it’s halted otherwise.
+If <i>/etc/runit/nosync</i> exists, <b>runit</b> doesn’t invoke
+sync(). This is useful in vservers.
<h2><a name='sect6'>Ctrl-alt-del</a></h2>
If <b>runit</b> receives the ctrl-alt-del keyboard request and the file
diff -ru runit-2.1.1/man/runit.8 runit-2.1.1+nosync/man/runit.8
--- runit-2.1.1/man/runit.8 2009-10-04 22:44:02.000000000 +0200
+++ runit-2.1.1+nosync/man/runit.8 2012-12-06 16:48:52.392406000 +0100
@@ -48,6 +48,11 @@
.I /etc/runit/reboot
exists and has the execute by owner permission set.
If so, the system is rebooted, it's halted otherwise.
+If
+.I /etc/runit/nosync
+exists,
+.B runit
+doesn't invoke sync(). This is useful in vservers.
.SH CTRL-ALT-DEL
If
.B runit
diff -ru runit-2.1.1/src/runit.c runit-2.1.1+nosync/src/runit.c
--- runit-2.1.1/src/runit.c 2009-10-04 22:44:02.000000000 +0200
+++ runit-2.1.1+nosync/src/runit.c 2012-12-06 16:44:30.055219000 +0100
@@ -41,6 +41,11 @@
}
void sig_child_handler (void) { write(selfpipe[1], "", 1); }
+void sync_if_needed() {
+ struct stat s;
+ if (stat(NOSYNC, &s) == -1) sync();
+}
+
int main (int argc, const char * const *argv, char * const *envp) {
const char * prog[2];
int pid, pid2;
@@ -305,28 +310,28 @@
case -1:
if ((stat(REBOOT, &s) != -1) && (s.st_mode & S_IXUSR)) {
strerr_warn2(INFO, "system reboot.", 0);
- sync();
+ sync_if_needed();
reboot_system(RB_AUTOBOOT);
}
else {
#ifdef RB_POWER_OFF
strerr_warn2(INFO, "power off...", 0);
- sync();
+ sync_if_needed();
reboot_system(RB_POWER_OFF);
sleep(2);
#endif
#ifdef RB_HALT_SYSTEM
strerr_warn2(INFO, "system halt.", 0);
- sync();
+ sync_if_needed();
reboot_system(RB_HALT_SYSTEM);
#else
#ifdef RB_HALT
strerr_warn2(INFO, "system halt.", 0);
- sync();
+ sync_if_needed();
reboot_system(RB_HALT);
#else
strerr_warn2(INFO, "system reboot.", 0);
- sync();
+ sync_if_needed();
reboot_system(RB_AUTOBOOT);
#endif
#endif
diff -ru runit-2.1.1/src/runit.h runit-2.1.1+nosync/src/runit.h
--- runit-2.1.1/src/runit.h 2009-10-04 22:44:02.000000000 +0200
+++ runit-2.1.1+nosync/src/runit.h 2012-12-06 16:39:28.781315000 +0100
@@ -1,4 +1,5 @@
#define RUNIT "/sbin/runit"
#define STOPIT "/etc/runit/stopit"
#define REBOOT "/etc/runit/reboot"
+#define NOSYNC "/erc/runit/nosync"
#define CTRLALTDEL "/etc/runit/ctrlaltdel"