Skip to content

Commit 2af31ea

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 0c4944b commit 2af31ea

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
@@ -575,6 +575,28 @@ int runat_push_command_line (struct runat *r,
575575
return rc;
576576
}
577577

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