More launch control options

This commit is contained in:
Richard Frith-Macdonald 2019-02-08 11:05:41 +00:00
parent 958bb2a4c4
commit 29d4f167c6
3 changed files with 89 additions and 13 deletions

View file

@ -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 <rfm@gnu.org>

View file

@ -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.

View file

@ -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)