Hi,
Finally got around to this. There's a hacky patch attached that
introduces 'reboot' stanza that will issue reboot given that we
hit respawn limit for 'reboot' marked task. While this seems
working, issuing reboot is probably not the correct way to
reboot. Scott, your comments?
--
// Janne
On Tue, Nov 10, 2009 at 9:34 AM, Garrett Cooper <[email protected]> wrote:
> On Mon, Nov 9, 2009 at 11:20 PM, Janne Karhunen
> <[email protected]> wrote:
>> Hi,
>>
>> Any ideas what would be the best way to react to respawn
>> giving up? Certain services are critical enough to warrant a
>> whole device restart once they fail. 'start on stopped
>> <service>' might work, but it can also trigger during normal
>> shutdown and that's not nice.
>>
>> If there is no other way, would you guys be willing to accept
>> a patch for new 'reboot' stanza?
>>
>>
>> --
>> // Janne
>
> Please -- this would get rid of a crappy hack that we have with
> env and export in my group.
> Thanks,
> -Garrett
>
--
// Janne
Index: upstart/init/job_class.h
===================================================================
--- upstart.orig/init/job_class.h
+++ upstart/init/job_class.h
@@ -145,6 +145,7 @@ typedef struct job_class {
struct rlimit *limits[RLIMIT_NLIMITS];
char *chroot;
char *chdir;
+ int reboot;
int deleted;
} JobClass;
Index: upstart/init/parse_job.c
===================================================================
--- upstart.orig/init/parse_job.c
+++ upstart/init/parse_job.c
@@ -209,6 +209,10 @@ static int stanza_chdir (JobClass
const char *file, size_t len,
size_t *pos, size_t *lineno)
__attribute__ ((warn_unused_result));
+static int stanza_reboot (JobClass *class, NihConfigStanza *stanza,
+ const char *file, size_t len,
+ size_t *pos, size_t *lineno)
+ __attribute__ ((warn_unused_result));
/**
@@ -245,6 +249,7 @@ static NihConfigStanza stanzas[] = {
{ "limit", (NihConfigHandler)stanza_limit },
{ "chroot", (NihConfigHandler)stanza_chroot },
{ "chdir", (NihConfigHandler)stanza_chdir },
+ { "reboot", (NihConfigHandler)stanza_reboot },
NIH_CONFIG_LAST
};
@@ -2391,3 +2396,33 @@ stanza_chdir (JobClass *class,
return nih_config_skip_comment (file, len, pos, lineno);
}
+
+/**
+ * stanza_reboot:
+ * @class: job class being parsed,
+ * @stanza: stanza found,
+ * @file: file or string to parse,
+ * @len: length of @file,
+ * @pos: offset within @file,
+ * @lineno: line number.
+ *
+ * Parse a reboot stanza from @file. This takes no arguments.
+ *
+ * Returns: zero on success, negative value on error.
+ **/
+static int
+stanza_reboot (JobClass *class,
+ NihConfigStanza *stanza,
+ const char *file,
+ size_t len,
+ size_t *pos,
+ size_t *lineno)
+{
+ nih_assert (class != NULL);
+ nih_assert (stanza != NULL);
+ nih_assert (file != NULL);
+ nih_assert (pos != NULL);
+
+ class->reboot = TRUE;
+ return nih_config_skip_comment (file, len, pos, lineno);
+}
Index: upstart/init/job_process.c
===================================================================
--- upstart.orig/init/job_process.c
+++ upstart/init/job_process.c
@@ -29,6 +29,7 @@
#include <sys/time.h>
#include <sys/ptrace.h>
#include <sys/resource.h>
+#include <stdlib.h>
#include <time.h>
#include <errno.h>
@@ -1059,11 +1060,20 @@ job_process_terminated (Job *job
*/
if (failed && job->class->respawn) {
if (job_process_catch_runaway (job)) {
- nih_warn (_("%s respawning too fast, stopped"),
- job_name (job));
-
- failed = FALSE;
- job_failed (job, -1, 0);
+ if (job->class->reboot) {
+ nih_warn (_("%s respawning too fast and is marked unrecoverable"),
+ job_name (job));
+ failed = FALSE;
+ job_failed (job, -1, 0);
+ /* FIXME: system call, do something proper */
+ system ("/sbin/reboot");
+ } else {
+ nih_warn (_("%s respawning too fast, stopped"),
+ job_name (job));
+
+ failed = FALSE;
+ job_failed (job, -1, 0);
+ }
} else {
nih_warn (_("%s %s process ended, respawning"),
job_name (job),
--
upstart-devel mailing list
[email protected]
Modify settings or unsubscribe at:
https://lists.ubuntu.com/mailman/listinfo/upstart-devel