Skip to content

Commit 8e0660b

Browse files
committed
broker: add shutdown force option
Problem: we need a way for the shutdown command to pass a "force" option to the shutdown script. Add a {"force"?b} parameter to the shutdown request payload. If specified, the shutdown script is called with the --force option.
1 parent 2aa9530 commit 8e0660b

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

src/broker/runat.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,28 @@ int runat_push_command_line (struct runat *r,
576576
return rc;
577577
}
578578

579+
int runat_add_arg (struct runat *r, const char *name, const char *arg)
580+
{
581+
struct runat_entry *entry;
582+
struct runat_command *command;
583+
584+
if (!r || !name || !arg) {
585+
errno = EINVAL;
586+
return -1;
587+
}
588+
if (!(entry = zhashx_lookup (r->entries, name))) {
589+
errno = ENOENT;
590+
return -1;
591+
}
592+
command = zlist_first (entry->commands);
593+
while (command) {
594+
if (flux_cmd_argv_append (command->cmd, arg) < 0)
595+
return -1;
596+
command = zlist_next (entry->commands);
597+
}
598+
return 0;
599+
}
600+
579601
int runat_get_exit_code (struct runat *r, const char *name, int *rc)
580602
{
581603
struct runat_entry *entry;

src/broker/runat.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ int runat_push_command_line (struct runat *r,
6161
const char *cmdline,
6262
int flags);
6363

64+
/* Add an argument to all commands registered under 'name'.
65+
*/
66+
int runat_add_arg (struct runat *r, const char *name, const char *arg);
67+
6468
/* Get exit code of completed command list.
6569
* If multiple commands fail, the exit code is that of the first failure.
6670
*/

src/broker/shutdown.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "src/common/libutil/stdlog.h"
2020

2121
#include "shutdown.h"
22+
#include "runat.h"
2223
#include "state_machine.h"
2324

2425
#include "broker.h"
@@ -154,14 +155,24 @@ static void start_cb (flux_t *h,
154155
struct shutdown *shutdown = arg;
155156
flux_error_t error;
156157
const char *errmsg = NULL;
158+
int force = 0;
157159

158-
if (flux_request_decode (msg, NULL, NULL) < 0)
160+
if (flux_request_unpack (msg,
161+
NULL,
162+
"{s?b}",
163+
"force", &force) < 0)
159164
goto error;
160165
if (shutdown->request) {
161166
errno = EINVAL;
162167
errmsg = "shutdown is already in progress";
163168
goto error;
164169
}
170+
if (force) {
171+
if (runat_add_arg (shutdown->ctx->runat, "shutdown", "-f") < 0) {
172+
errmsg = "error setting shutdown -f option";
173+
goto error;
174+
}
175+
}
165176
if (state_machine_shutdown (shutdown->ctx->state_machine, &error) < 0) {
166177
errmsg = error.text;
167178
goto error;

src/cmd/builtin/shutdown.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ static int subcmd (optparse_t *p, int ac, char *av[])
119119
int loglevel = quiet ? LOG_WARNING
120120
: verbose == 0 ? LOG_INFO : LOG_DEBUG;
121121
const char *target = NULL;
122+
int force = 0;
122123

123124
log_init ("flux-shutdown");
124125

@@ -161,15 +162,19 @@ static int subcmd (optparse_t *p, int ac, char *av[])
161162
log_msg ("shutdown will dump KVS (this may take some time)");
162163
}
163164

165+
if (optparse_hasopt (p, "force"))
166+
force = 1;
167+
164168
/* N.B. set nodeid=FLUX_NODEID_ANY so we get immediate error from
165169
* broker if run on rank > 0.
166170
*/
167171
if (!(f = flux_rpc_pack (h,
168172
"shutdown.start",
169173
FLUX_NODEID_ANY,
170174
flags,
171-
"{s:i}",
172-
"loglevel", loglevel)))
175+
"{s:i s:b}",
176+
"loglevel", loglevel,
177+
"force", force)))
173178
log_err_exit ("could not send shutdown.start request");
174179

175180
if ((flags & FLUX_RPC_STREAMING))
@@ -209,6 +214,9 @@ static struct optparse_option opts[] = {
209214
{ .name = "no", .key = 'n', .has_arg = 0,
210215
.usage = "Answer no to any yes/no questions",
211216
},
217+
{ .name = "force", .key = 'f', .has_arg = 0,
218+
.usage = "Force shutdown even if jobs are running",
219+
},
212220
OPTPARSE_TABLE_END
213221
};
214222

0 commit comments

Comments
 (0)