Author: rfm
Date: Wed Jul 2 00:06:42 2014
New Revision: 37976
URL: http://svn.gna.org/viewcvs/gnustep?rev=37976&view=rev
Log:
add autorestart
Modified:
libs/ec/trunk/ChangeLog
libs/ec/trunk/Command.m
libs/ec/trunk/Control.m
Modified: libs/ec/trunk/ChangeLog
URL:
http://svn.gna.org/viewcvs/gnustep/libs/ec/trunk/ChangeLog?rev=37976&r1=37975&r2=37976&view=diff
==============================================================================
--- libs/ec/trunk/ChangeLog (original)
+++ libs/ec/trunk/ChangeLog Wed Jul 2 00:06:42 2014
@@ -1,3 +1,12 @@
+2014-07-01 Richard Frith-Macdonald <[email protected]>
+
+ * Command.m:
+ * Control.m:
+ Implement auto-restart ...
+ Run a 'Watcher' process as a daemon with the actual server as a
+ subtask. If the subtask dies with a status other than zero,
+ restart it after a 30 second delay.
+
2014-06-20 Richard Frith-Macdonald <[email protected]>
* EcProcess.m: Make sure the NSHost cache is flushed at least
Modified: libs/ec/trunk/Command.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/ec/trunk/Command.m?rev=37976&r1=37975&r2=37976&view=diff
==============================================================================
--- libs/ec/trunk/Command.m (original)
+++ libs/ec/trunk/Command.m Wed Jul 2 00:06:42 2014
@@ -74,6 +74,112 @@
int
main(int argc, char *argv[])
{
+ NSProcessInfo *pInfo;
+ NSArray *pArgs;
+ NSString *pName;
+ CREATE_AUTORELEASE_POOL(pool);
+
+ pInfo = [NSProcessInfo processInfo];
+ pArgs = [pInfo arguments];
+ pName = [pInfo processName];
+
+ if ([pArgs containsObject: @"--Watched"] == NO)
+ {
+ NSMutableArray *args = AUTORELEASE([pArgs mutableCopy]);
+ NSString *path = [[NSBundle mainBundle] executablePath];
+ NSAutoreleasePool *inner = nil;
+ BOOL done = NO;
+ int status = 0;
+ NSFileHandle *null;
+ NSTask *t;
+
+ [args removeObjectAtIndex: 0];
+
+ if ([pArgs containsObject: @"--Watcher"] == NO)
+ {
+ /* In the top level task ... set flags to create a subtask
+ * to act as a watcher for other tasks, and once that has
+ * been created, exit to leave it running as a daemon.
+ */
+ [args addObject: @"--Watcher"];
+ t = [NSTask new];
+ NS_DURING
+ {
+ [t setLaunchPath: path];
+ [t setArguments: args];
+ [t setEnvironment: [pInfo environment]];
+ null = [NSFileHandle fileHandleWithNullDevice];
+ [t setStandardInput: null];
+ [t setStandardOutput: null];
+ [t setStandardError: null];
+ [t launch];
+ }
+ NS_HANDLER
+ {
+ NSLog(@"Problem creating %@ subprocess: %@",
+ pName, localException);
+ exit(1);
+ }
+ NS_ENDHANDLER
+ [t release];
+ exit(0);
+ }
+
+ /* This is the watcher ... its subtasks are those which are watched.
+ */
+
+ /* Set args to tell subtask task not to make itself a daemon
+ */
+ [args addObject: @"-Daemon"];
+ [args addObject: @"NO"];
+
+ /* Set args to tell task it is being watched.
+ */
+ [args removeObject: @"--Watcher"];
+ [args addObject: @"--Watched"];
+
+ while (NO == done)
+ {
+ DESTROY(inner);
+ inner = [NSAutoreleasePool new];
+ t = [[NSTask new] autorelease];
+ NS_DURING
+ {
+ [t setLaunchPath: path];
+ [t setArguments: args];
+ [t setEnvironment: [pInfo environment]];
+ null = [NSFileHandle fileHandleWithNullDevice];
+ [t setStandardInput: null];
+ [t setStandardOutput: null];
+ [t setStandardError: null];
+ [t launch];
+ [t waitUntilExit];
+ if (0 == [t terminationStatus])
+ {
+ done = YES;
+ }
+ else
+ {
+ /* Subprocess died ... try to restart after 30 seconds
+ */
+ [NSThread sleepForTimeInterval: 30.0];
+ }
+ }
+ NS_HANDLER
+ {
+ done = YES;
+ status = 1;
+ NSLog(@"Problem creating %@ subprocess: %@",
+ pName, localException);
+ }
+ NS_ENDHANDLER
+ }
+ DESTROY(inner);
+ DESTROY(pool);
+ exit(status);
+ }
+ DESTROY(pool);
+
inner_main();
return 0;
}
Modified: libs/ec/trunk/Control.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/ec/trunk/Control.m?rev=37976&r1=37975&r2=37976&view=diff
==============================================================================
--- libs/ec/trunk/Control.m (original)
+++ libs/ec/trunk/Control.m Wed Jul 2 00:06:42 2014
@@ -71,6 +71,112 @@
int
main(int argc, char *argv[])
{
+ NSProcessInfo *pInfo;
+ NSArray *pArgs;
+ NSString *pName;
+ CREATE_AUTORELEASE_POOL(pool);
+
+ pInfo = [NSProcessInfo processInfo];
+ pArgs = [pInfo arguments];
+ pName = [pInfo processName];
+
+ if ([pArgs containsObject: @"--Watched"] == NO)
+ {
+ NSMutableArray *args = AUTORELEASE([pArgs mutableCopy]);
+ NSString *path = [[NSBundle mainBundle] executablePath];
+ NSAutoreleasePool *inner = nil;
+ BOOL done = NO;
+ int status = 0;
+ NSFileHandle *null;
+ NSTask *t;
+
+ [args removeObjectAtIndex: 0];
+
+ if ([pArgs containsObject: @"--Watcher"] == NO)
+ {
+ /* In the top level task ... set flags to create a subtask
+ * to act as a watcher for other tasks, and once that has
+ * been created, exit to leave it running as a daemon.
+ */
+ [args addObject: @"--Watcher"];
+ t = [NSTask new];
+ NS_DURING
+ {
+ [t setLaunchPath: path];
+ [t setArguments: args];
+ [t setEnvironment: [pInfo environment]];
+ null = [NSFileHandle fileHandleWithNullDevice];
+ [t setStandardInput: null];
+ [t setStandardOutput: null];
+ [t setStandardError: null];
+ [t launch];
+ }
+ NS_HANDLER
+ {
+ NSLog(@"Problem creating %@ subprocess: %@",
+ pName, localException);
+ exit(1);
+ }
+ NS_ENDHANDLER
+ [t release];
+ exit(0);
+ }
+
+ /* This is the watcher ... its subtasks are those which are watched.
+ */
+
+ /* Set args to tell subtask task not to make itself a daemon
+ */
+ [args addObject: @"-Daemon"];
+ [args addObject: @"NO"];
+
+ /* Set args to tell task it is being watched.
+ */
+ [args removeObject: @"--Watcher"];
+ [args addObject: @"--Watched"];
+
+ while (NO == done)
+ {
+ DESTROY(inner);
+ inner = [NSAutoreleasePool new];
+ t = [[NSTask new] autorelease];
+ NS_DURING
+ {
+ [t setLaunchPath: path];
+ [t setArguments: args];
+ [t setEnvironment: [pInfo environment]];
+ null = [NSFileHandle fileHandleWithNullDevice];
+ [t setStandardInput: null];
+ [t setStandardOutput: null];
+ [t setStandardError: null];
+ [t launch];
+ [t waitUntilExit];
+ if (0 == [t terminationStatus])
+ {
+ done = YES;
+ }
+ else
+ {
+ /* Subprocess died ... try to restart after 30 seconds
+ */
+ [NSThread sleepForTimeInterval: 30.0];
+ }
+ }
+ NS_HANDLER
+ {
+ done = YES;
+ status = 1;
+ NSLog(@"Problem creating %@ subprocess: %@",
+ pName, localException);
+ }
+ NS_ENDHANDLER
+ }
+ DESTROY(inner);
+ DESTROY(pool);
+ exit(status);
+ }
+ DESTROY(pool);
+
inner_main();
return 0;
}
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs