refactor(worker): remove config file and deprecated CLI flags

Remove -c (config file), -p (remote port), -m (remote host) flags.
Worker now uses CLI defaults (localhost:9990) or --peers for HA.
No config file dependency — four settings don't justify file overhead.
Default remote_port changed from 6789 to 9990 (controller default).
This commit is contained in:
Rongsong Shen 2026-08-10 10:40:59 +00:00
parent 9ffb1d511f
commit 5e4baa2745
Signed by: rshen
SSH key fingerprint: SHA256:8Vf2pZ3h6rJa7EhGK+WaAQ9Mta/apZvteW6g9U/WKKk

View file

@ -294,10 +294,7 @@ static int check_user(void)
int main(int argc, char* argv[])
{
int opt;
config_result_t* config_result = NULL;
int ret = XCECD_OK;
int config_flag = 0;
char* custom_config_path = NULL;
__attribute__((unused)) char worker_log[1024] = { 0 };
const char* peers_str = NULL;
xce_cluster_config_t cluster_cfg = {0};
@ -333,7 +330,7 @@ int main(int argc, char* argv[])
.domain_sock_file = "/var/run/.xcecd.sock",
.virutal_name = "localhost01",
.remote_host = "localhost",
.remote_port = 6789,
.remote_port = 9990,
.join_interval = 5,
.update_interval = 5,
.resource_update_interval = 1,
@ -342,54 +339,19 @@ int main(int argc, char* argv[])
char logfile[1024] = { 0 };
char* logdir = NULL;
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "-c") == 0 && i + 1 < argc) {
custom_config_path = argv[i + 1];
config_flag = 1;
break;
}
}
if (config_flag == 0) {
custom_config_path = strdup(DEFAULT_CONFIG_PATH);
}
static struct option long_opts[] = {
{ "peers", required_argument, NULL, OPT_PEERS },
{ "help", no_argument, NULL, 'h' },
{ NULL, 0, NULL, 0 }
};
while ((opt = getopt_long(argc, argv, "c:p:m:n:l:h", long_opts, NULL))
while ((opt = getopt_long(argc, argv, "n:l:h", long_opts, NULL))
!= -1) {
switch (opt) {
case 'c':
break; /* Custom config file already handled above */
case 'p':
if (config_flag) {
fprintf(stderr, "Custom config file already specified, "
"ignoring -p option.\n");
break;
}
config.remote_port = atoi(optarg);
break;
case 'm':
if (config_flag) {
fprintf(stderr, "Custom config file already specified, "
"ignoring -m option.\n");
break;
}
config.remote_host = optarg;
break;
case 'n':
config.virutal_name = optarg;
break;
case 'l':
if (config_flag) {
fprintf(stderr, "Custom config file already specified, "
"ignoring -l option.\n");
break;
}
if (optarg) {
if (logdir) {
FREEUP(logdir);
@ -402,60 +364,18 @@ int main(int argc, char* argv[])
break;
case 'h':
default:
#ifdef VIRTUAL_CLUSTER
printf("Usage: %s -n virtual_name [-p remote_port] [-m "
"remote_host] [-l log_dir] [--peers list] "
"[-h help]\n",
argv[0]);
#else
printf("Usage: %s [-p remote_port] [-m remote_host] [-l log_dir] "
printf("Usage: %s [-n name] [-l log_dir] "
"[--peers ctrl-1=host:port,...] "
"[-h help]\n",
argv[0]);
#endif
return 0;
}
}
/* Performed after argument parsing so -h/--help exits immediately
* without requiring root privileges or a configuration file. */
* without requiring root privileges. */
check_user();
if (access(custom_config_path, F_OK) == 0) {
/* load config from custom file */
config_result = config_load(custom_config_path);
if (!config_result) {
fprintf(stderr, "Failed to load config from %s\n",
custom_config_path);
return -1;
}
if (config_result->error_code == CONFIG_SUCCESS) {
if (config_result->config->controller_port > 0) {
config.remote_port = config_result->config->controller_port;
}
if (config_result->config->log_dir) {
logdir = strdup(config_result->config->log_dir);
}
if (config_result->config->log_level) {
config.debug_level
= level_to_int(config_result->config->log_level);
}
if (config_result->config->management_list_count > 0) {
config.remote_host
= config_result->config->management_list[0].hostname;
}
}
} else {
fprintf(stderr, "Configuration file %s not found.\n",
custom_config_path);
return -1;
}
/* P2.5-5: populate and validate xce_cluster_config_t when --peers given */
if (peers_str) {
if (xce_parse_peers(peers_str, &cluster_cfg) != 0) {