Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customizable component startup waits #58

Open
wants to merge 9 commits into
base: v2.x/master
Choose a base branch
from
40 changes: 36 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ extern char ** environ;
*/

#define CONFIG_DEBUG_MODE_KEY "ZLDEBUG"
/* delay between starting each component, in seconds */
#define CONFIG_SLEEP_TIME_KEY "ZLDELAYS"
#define DEFAULT_SLEEP_TIME_SEC 5
#define ZOWE_CONFIG_NAME "ZOWEYAML"
#define CONFIG_DEBUG_MODE_VALUE "ON"

Expand Down Expand Up @@ -100,6 +103,7 @@ typedef struct zl_int_array_t {

typedef struct zl_config_t {
bool debug_mode;
int sleep_time;
} zl_config_t;

typedef struct zl_comp_t {
Expand Down Expand Up @@ -160,7 +164,11 @@ struct {

pid_t pid;
char userid[9];


/* Sleep time of 5 seconds during startup of components
is to temporarily workaround parallelism performance issues on z/OS
If the situation improves in the future, we can reduce this.
*/
} zl_context = {.config = {.debug_mode = false}, .userid = "(NONE)"} ;


Expand Down Expand Up @@ -584,6 +592,7 @@ static int start_component(zl_comp_t *comp) {
"--component", comp->name,
NULL
};

comp->pid = spawn(bin, fd_count, fd_map, &inherit, c_args, c_envp);
if (comp->pid == -1) {
DEBUG("spawn() failed for %s - %s\n", comp->name, strerror(errno));
Expand All @@ -606,13 +615,17 @@ static int start_component(zl_comp_t *comp) {
return 0;
}

static int start_components(void) {
static int start_components(zl_config_t *config) {

INFO(MSG_STARTING_COMPS);

int rc = 0;

for (size_t i = 0; i < zl_context.child_count; i++) {
if (config->sleep_time) {
INFO(MSG_COMP_SLEEP, config->sleep_time);
sleep(config->sleep_time);
}
if (start_component(&zl_context.children[i])) {
ERROR(MSG_COMP_START_FAILED, zl_context.children[i].name);
rc = -1;
Expand Down Expand Up @@ -920,6 +933,17 @@ static zl_config_t read_config(int argc, char **argv) {
result.debug_mode = true;
}

char *sleep_value = getenv(CONFIG_SLEEP_TIME_KEY);
if (sleep_value) {
char *end;
long int sleep_number = strtol(sleep_value, &end, 10);
result.sleep_time = sleep_number;
INFO("sleep_time changed to %d\n",sleep_number);
} else {
result.sleep_time = DEFAULT_SLEEP_TIME_SEC;
INFO("Using sleep_time default of %d\n",result.sleep_time);
}

return result;
}

Expand Down Expand Up @@ -1245,12 +1269,20 @@ int main(int argc, char **argv) {
ConfigManager *configmgr = makeConfigManager(); /* configs,schemas,1,stderr); */
CFGConfig *theConfig = addConfig(configmgr,ZOWE_CONFIG_NAME);
cfgSetTraceStream(configmgr,stderr);
cfgSetTraceLevel(configmgr, zl_context.config.debug_mode ? 2 : 0);

INFO("configmgr debug=%d\n",config.debug_mode);
cfgSetTraceLevel(configmgr, config.debug_mode ? 2 : 0);

if (init_context(argc, argv, &config, configmgr)) {
ERROR(MSG_CTX_INIT_FAILED);
exit(EXIT_FAILURE);
}

if (config.sleep_time) {
INFO(MSG_CONFIG_SLEEP, config.sleep_time);
} else {
INFO("Launcher is not using sleeps\n");
}

cfgSetConfigPath(configmgr, ZOWE_CONFIG_NAME, zl_context.yaml_file);
int parm_member_len = strlen(zl_context.parm_member);
Expand Down Expand Up @@ -1306,7 +1338,7 @@ int main(int argc, char **argv) {
exit(EXIT_FAILURE);
}

start_components();
start_components(&config);

if (start_console_tread()) {
ERROR(MSG_CONS_START_ERR);
Expand Down
2 changes: 2 additions & 0 deletions src/msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
#define MSG_CFG_INTERNAL_FAIL MSG_PREFIX "0071E" " Internal failure during validation, please contact support\n"
#define MSG_CFG_LOAD_FAIL MSG_PREFIX "0072E" " Launcher Could not load configurations\n"
#define MSG_CFG_SCHEMA_FAIL MSG_PREFIX "0073E" " Launcher Could not load schemas, status=%d\n"
#define MSG_CONFIG_SLEEP MSG_PREFIX "0074I" " Launcher configured to stagger initial component start by %d seconds\n"
#define MSG_COMP_SLEEP MSG_PREFIX "0075I" " Waiting %d seconds before component start\n"

#endif // MSG_H

Expand Down