5
5
* Copyright (C) 2008 Lawrence Livermore National Security.
6
6
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
7
7
* Written by Morris Jette <jette@llnl.gov>
8
* CODE-OCEC-09-009. All rights reserved.
10
10
* This file is part of SLURM, a resource management program.
11
* For details, see <http://www.llnl.gov/linux/slurm/>.
11
* For details, see <https://computing.llnl.gov/linux/slurm/>.
12
* Please also read the included file: DISCLAIMER.
13
14
* SLURM is free software; you can redistribute it and/or modify it under
14
15
* the terms of the GNU General Public License as published by the Free
106
108
_parse_commandline(argc, argv);
107
109
_update_logging();
109
if (gethostname_short(node_name, sizeof(node_name)))
110
fatal("getnodename: %m");
111
if (slurmdbd_conf->dbd_host &&
112
strcmp(slurmdbd_conf->dbd_host, node_name) &&
113
strcmp(slurmdbd_conf->dbd_host, "localhost")) {
114
fatal("This host not configured to run SlurmDBD (%s != %s)",
115
node_name, slurmdbd_conf->dbd_host);
117
111
if (slurm_auth_init(NULL) != SLURM_SUCCESS) {
118
112
fatal("Unable to initialize %s authentication plugin",
119
113
slurmdbd_conf->auth_type);
147
141
assoc_init_arg.cache_level = ASSOC_MGR_CACHE_USER;
148
142
if(slurmdbd_conf->track_wckey)
149
143
assoc_init_arg.cache_level |= ASSOC_MGR_CACHE_WCKEY;
151
145
if(assoc_mgr_init(db_conn, &assoc_init_arg) == SLURM_ERROR) {
152
146
error("Problem getting cache of data");
153
147
acct_storage_g_close_connection(&db_conn);
158
/* Create attached thread to process incoming RPCs */
159
slurm_attr_init(&thread_attr);
160
if (pthread_create(&rpc_handler_thread, &thread_attr,
162
fatal("pthread_create error %m");
163
slurm_attr_destroy(&thread_attr);
167
/* Create attached thread to do usage rollup */
168
slurm_attr_init(&thread_attr);
169
if (pthread_create(&rollup_handler_thread, &thread_attr,
170
_rollup_handler, db_conn))
171
fatal("pthread_create error %m");
172
slurm_attr_destroy(&thread_attr);
175
/* Daemon is fully operational here */
176
info("slurmdbd version %s started", SLURM_VERSION);
151
if (gethostname_short(node_name, sizeof(node_name)))
152
fatal("getnodename: %m");
155
if (slurmdbd_conf->dbd_backup &&
156
(!strcmp(node_name, slurmdbd_conf->dbd_backup) ||
157
!strcmp(slurmdbd_conf->dbd_backup, "localhost"))) {
158
info("slurmdbd running in background mode");
159
have_control = false;
163
assoc_mgr_refresh_lists(db_conn, NULL);
164
} else if (slurmdbd_conf->dbd_host &&
165
(!strcmp(slurmdbd_conf->dbd_host, node_name) ||
166
!strcmp(slurmdbd_conf->dbd_host, "localhost"))) {
170
fatal("This host not configured to run SlurmDBD "
171
"(%s != %s | (backup) %s)",
172
node_name, slurmdbd_conf->dbd_host,
173
slurmdbd_conf->dbd_backup);
177
/* Create attached thread to process incoming RPCs */
178
slurm_attr_init(&thread_attr);
179
if (pthread_create(&rpc_handler_thread, &thread_attr,
181
fatal("pthread_create error %m");
182
slurm_attr_destroy(&thread_attr);
186
/* Create attached thread to do usage rollup */
187
slurm_attr_init(&thread_attr);
188
if (pthread_create(&rollup_handler_thread,
190
_rollup_handler, db_conn))
191
fatal("pthread_create error %m");
192
slurm_attr_destroy(&thread_attr);
195
/* Daemon is fully operational here */
196
if(!shutdown_time || primary_resumed) {
198
info("slurmdbd version %s started", SLURM_VERSION);
203
/* this is only ran if not backup */
204
if(rollup_handler_thread)
205
pthread_join(rollup_handler_thread, NULL);
206
if(rpc_handler_thread)
207
pthread_join(rpc_handler_thread, NULL);
209
if(backup && primary_resumed) {
211
info("Backup has given up control");
178
217
/* Daemon termination handled here */
179
if(rollup_handler_thread)
180
pthread_join(rollup_handler_thread, NULL);
182
if(rpc_handler_thread)
183
pthread_join(rpc_handler_thread, NULL);
185
219
if(signal_handler_thread)
186
220
pthread_join(signal_handler_thread, NULL);
189
223
acct_storage_g_close_connection(&db_conn);
191
225
if (slurmdbd_conf->pid_file &&
192
226
(unlink(slurmdbd_conf->pid_file) < 0)) {
193
227
verbose("Unable to remove pidfile '%s': %m",
194
228
slurmdbd_conf->pid_file);
197
231
assoc_mgr_fini(NULL);
198
232
slurm_acct_storage_fini();
199
233
slurm_auth_fini();
457
498
case SIGINT: /* kill -2 or <CTRL-C> */
458
499
case SIGTERM: /* kill -15 */
459
500
info("Terminate signal (SIGINT or SIGTERM) received");
460
shutdown_time = time(NULL);
462
_rollup_handler_cancel();
464
502
return NULL; /* Normal termination */
465
503
case SIGABRT: /* abort */
466
504
info("SIGABRT received");
467
505
abort(); /* Should terminate here */
468
shutdown_time = time(NULL);
470
_rollup_handler_cancel();
473
509
error("Invalid signal (%d) received", sig);