From 29d4f167c61d9a4aa10bb6fe9c86eb6a7d44feae Mon Sep 17 00:00:00 2001 From: Richard Frith-Macdonald Date: Fri, 8 Feb 2019 11:05:41 +0000 Subject: [PATCH] More launch control options --- ChangeLog | 4 +++ Control.plist | 16 ++++++---- EcCommand.m | 82 ++++++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 89 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9ee8d39..947c3c9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,10 @@ of launching tasks is reached, new tasks should be launched as and when launching tasks complete their startup and register with the Command server. + Add suspend and resume command to control whether the Command server + will actually launch/relaunch tasks, along with a LaunchStartSuspended + user default to control whether launching starts as soon as the Command + server starts up (by default launching is not suspended on startup). 2018-12-11 Richard Frith-Macdonald diff --git a/Control.plist b/Control.plist index 8780d93..a34bd12 100644 --- a/Control.plist +++ b/Control.plist @@ -72,11 +72,6 @@ Time = 30; // Interval for relaunching after crash }; }; - /* Specify how many tasks the Command server may have launching - * concurrently (default is 20). You may want to set this to a - * lower value in order to reduce load when the system start up. - */ - LaunchLimit = 20; /* Specify launch order ... Feep first, Bar second * Processes not listed here are launched in lexicographical order * after any processes which are listed. @@ -85,6 +80,17 @@ Feep, // Launch Feep first Bar // Launch Bar second ); + /* Specify how many tasks the Command server may have launching + * concurrently (default is 20). You may want to set this to a + * lower value in order to reduce load when the system start up. + */ + LaunchLimit = 20; + /* Specify whether, when the Command server starts, launching of + * tasks should be suspeneded (as if the 'suspend' command had been + * sent to it from the Console). + * By default this is NO. + */ + LaunchStartSuspended = NO; }; }; /* Section specific for the Control server itself. diff --git a/EcCommand.m b/EcCommand.m index 65dde18..445ee42 100644 --- a/EcCommand.m +++ b/EcCommand.m @@ -126,6 +126,7 @@ static NSString* cmdWord(NSArray* a, unsigned int pos) NSString *logname; NSMutableDictionary *config; NSUInteger launchLimit; + BOOL launchSuspended; NSDictionary *launchInfo; NSArray *launchOrder; NSDictionary *environment; @@ -233,6 +234,13 @@ static NSString* cmdWord(NSArray* a, unsigned int pos) NS_ENDHANDLER } +- (void) ecAwaken +{ + [super ecAwaken]; + launchSuspended = [[self cmdDefaults] boolForKey: @"LaunchStartSuspended"]; + [self _timedOut: nil]; // Simulate timeout to set timer going +} + - (oneway void) unmanage: (in bycopy NSString*)managedObject { NS_DURING @@ -826,7 +834,7 @@ static NSString* cmdWord(NSArray* a, unsigned int pos) { m = @"Commands are -\n" @"Help\tArchive\tControl\tLaunch\tList\tMemory\t" - @"Quit\tRestart\tTell\n\n" + @"Quit\tRestart\tResume\tSuspend\tTell\n\n" @"Type 'help' followed by a command word for details.\n" @"A command line consists of a sequence of words, " @"the first of which is the command to be executed. " @@ -900,6 +908,16 @@ static NSString* cmdWord(NSArray* a, unsigned int pos) @"Restart self\n" @"Shuts down and starts Command server for this host.\n"; } + else if (comp(wd, @"Resume") >= 0) + { + m = @"Resumes the launching/relaunching of tasks.\n" + @"Has no effect if launching has not been suspended.\n"; + } + else if (comp(wd, @"Suspend") >= 0) + { + m = @"Suspends the launching/relaunching of tasks.\n" + @"Has no effect if this has already been suspended.\n"; + } else if (comp(wd, @"Tell") >= 0) { m = @"Tell 'name' 'command'\n" @@ -910,17 +928,29 @@ static NSString* cmdWord(NSArray* a, unsigned int pos) } else if (comp(wd, @"launch") >= 0) { - if ([cmd count] > 1) + if (YES == launchSuspended) + { + m = @"Launching of tasks is suspended.\n" + @"Use the Resume command to resume launching.\n"; + } + else if ([cmd count] > 1) { + NSString *nam = [cmd objectAtIndex: 1]; + BOOL all = NO; + + if ([nam caseInsensitiveCompare: @"all"] == NSOrderedSame) + { + all = YES; + } + if (launchInfo != nil) { NSEnumerator *enumerator; NSString *key; - NSString *nam = [cmd objectAtIndex: 1]; BOOL found = NO; enumerator = [launchOrder objectEnumerator]; - if ([nam caseInsensitiveCompare: @"all"] == NSOrderedSame) + if (YES == all) { NSMutableArray *names = [NSMutableArray array]; @@ -1103,6 +1133,12 @@ static NSString* cmdWord(NSArray* a, unsigned int pos) { m = @"There are no programs we can launch.\n"; } + + if (YES == launchSuspended) + { + m = [m stringByAppendingString: + @"\nLaunching is suspended.\n"]; + } } } else if (comp(wd, @"memory") >= 0) @@ -1327,6 +1363,31 @@ static NSString* cmdWord(NSArray* a, unsigned int pos) m = @"Restart what?.\n"; } } + else if (comp(wd, @"resume") >= 0) + { + if (YES == launchSuspended) + { + launchSuspended = NO; + m = @"Launching is now resumed.\n"; + [self timeoutSoon]; + } + else + { + m = @"Launching was/is not suspended.\n"; + } + } + else if (comp(wd, @"suspend") >= 0) + { + if (YES == launchSuspended) + { + m = @"Launching was/is already suspended.\n"; + } + else + { + launchSuspended = YES; + m = @"Launching is now suspended.\n"; + } + } else if (comp(wd, @"tell") >= 0) { wd = cmdWord(cmd, 1); @@ -1820,8 +1881,6 @@ static NSString* cmdWord(NSArray* a, unsigned int pos) clients = [[NSMutableArray alloc] initWithCapacity: 10]; launches = [[NSMutableDictionary alloc] initWithCapacity: 10]; launching = [[NSMutableDictionary alloc] initWithCapacity: 10]; - - [self _timedOut: nil]; // Simulate timeout to set timer going } return self; } @@ -2029,9 +2088,16 @@ static NSString* cmdWord(NSArray* a, unsigned int pos) - (void) launch { NSAutoreleasePool *arp; - NSMutableArray *toTry = AUTORELEASE([launchOrder mutableCopy]); - NSDate *now = [NSDate date]; + NSMutableArray *toTry; + NSDate *now; + if (launchSuspended) + { + return; + } + + toTry = AUTORELEASE([launchOrder mutableCopy]); + now = [NSDate date]; arp = [NSAutoreleasePool new]; while ([toTry count] > 0)