[slurm-dev] [PATCH] Allow default command for salloc to be specfied in slurm.conf

0 views
Skip to first unread message

Mark A. Grondona

unread,
Sep 30, 2008, 6:53:59 PM9/30/08
to slur...@lists.llnl.gov

Add a new slurm.conf parameter

SallocDefaultCommand = "command"

which overrides salloc's current behavior of running the default
shell of the user when no command is supplied on the salloc command
line. This allows much greater site customization of the default
salloc behavior.

The "command" is passed to 'sh -c' by salloc, so shell syntax
may be used, for instance:

SallocDefaultCommand = "srun --pty -N1 -n1 $SHELL"

would spawn a shell on the first nodfe of the user's allocation.

With the preserve-env plugin, this could be used to migrate
user's sessions from login nodes to compute nodes when they
are using salloc, all while preserving the same SLURM environment
had the shell been directly invoked by salloc.

This patch has only been marginally tested with slurm-1.3.

mark

---
slurm/slurm.h.in | 1 +
src/common/read_config.c | 5 +++++
src/salloc/opt.c | 35 ++++++++++++++++++++++++++++-------
3 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/slurm/slurm.h.in b/slurm/slurm.h.in
index 142db96..585923e 100644
--- a/slurm/slurm.h.in
+++ b/slurm/slurm.h.in
@@ -1063,6 +1063,7 @@ typedef struct slurm_ctl_conf {
* they are considered "unkillable". */
uint16_t use_pam; /* enable/disable PAM support */
uint16_t wait_time; /* default job --wait time */
+ char *salloc_default_command; /* default salloc command */
} slurm_ctl_conf_t;

typedef struct slurmd_status_msg {
diff --git a/src/common/read_config.c b/src/common/read_config.c
index 23fc3a9..9c52f23 100644
--- a/src/common/read_config.c
+++ b/src/common/read_config.c
@@ -200,6 +200,7 @@ s_p_options_t slurm_conf_options[] = {
{"ResumeProgram", S_P_STRING},
{"ResumeRate", S_P_UINT16},
{"ReturnToService", S_P_UINT16},
+ {"SallocDefaultCommand", S_P_STRING},
{"SchedulerAuth", S_P_STRING, defunct_option},
{"SchedulerParameters", S_P_STRING},
{"SchedulerPort", S_P_UINT16},
@@ -1191,6 +1192,7 @@ free_slurm_conf (slurm_ctl_conf_t *ctl_conf_ptr, bool purge_node_hash)
xfree (ctl_conf_ptr->task_prolog);
xfree (ctl_conf_ptr->tmp_fs);
xfree (ctl_conf_ptr->unkillable_program);
+ xfree (ctl_conf_ptr->salloc_default_command);

if (purge_node_hash)
_free_name_hashtbl();
@@ -1881,6 +1883,9 @@ validate_and_set_defaults(slurm_ctl_conf_t *conf, s_p_hashtbl_t *hashtbl)
if (!s_p_get_uint16(&conf->resume_rate, "ResumeRate", hashtbl))
conf->resume_rate = DEFAULT_RESUME_RATE;

+ s_p_get_string(&conf->salloc_default_command, "SallocDefaultCommand",
+ hashtbl);
+
s_p_get_string(&conf->sched_params, "SchedulerParameters", hashtbl);

if (s_p_get_uint16(&conf->schedport, "SchedulerPort", hashtbl)) {
diff --git a/src/salloc/opt.c b/src/salloc/opt.c
index ce1f920..d581d8a 100644
--- a/src/salloc/opt.c
+++ b/src/salloc/opt.c
@@ -985,6 +985,32 @@ static char *_get_shell(void)
return pw_ent_ptr->pw_shell;
}

+static int _salloc_default_command (int *argcp, char **argvp[])
+{
+ slurm_ctl_conf_t *cf = slurm_conf_lock();
+
+ if (cf->salloc_default_command) {
+ /*
+ * Set argv to "/bin/sh -c 'salloc_default_command'"
+ */
+ *argcp = 3;
+ *argvp = xmalloc (sizeof (char *) * 4);
+ (*argvp)[0] = "/bin/sh";
+ (*argvp)[1] = "-c";
+ (*argvp)[2] = xstrdup (cf->salloc_default_command);
+ (*argvp)[3] = NULL;
+ }
+ else {
+ *argcp = 1;
+ *argvp = xmalloc (sizeof (char *) * 2);
+ (*argvp)[0] = _get_shell ();
+ (*argvp)[1] = NULL;
+ }
+
+ slurm_conf_unlock();
+ return (0);
+}
+
/*
* _opt_verify : perform some post option processing verification
*
@@ -1010,13 +1036,8 @@ static bool _opt_verify(void)
if ((opt.egid != (gid_t) -1) && (opt.egid != opt.gid))
opt.gid = opt.egid;

- if ((opt.no_shell == false) && (command_argc == 0)) {
- /* Using default shell as the user command */
- command_argc = 1;
- command_argv = (char **) xmalloc(sizeof(char *) * 2);
- command_argv[0] = _get_shell();
- command_argv[1] = NULL;
- }
+ if ((opt.no_shell == false) && (command_argc == 0))
+ _salloc_default_command (&command_argc, &command_argv);

/* check for realistic arguments */
if (opt.nprocs <= 0) {
--
1.5.4.5

Jerry Smith

unread,
Oct 1, 2008, 12:26:21 PM10/1/08
to slur...@lists.llnl.gov
Mark,

Any idea when this may be in a release version of Slurm? This will be
great for those of us migrating from Torque and "qsub -I" and the
behavior our users are used to.


--Jerry

Mark A. Grondona

unread,
Oct 1, 2008, 12:48:35 PM10/1/08
to slur...@lists.llnl.gov, Jerry Smith
> Mark,
>
> Any idea when this may be in a release version of Slurm? This will be
> great for those of us migrating from Torque and "qsub -I" and the
> behavior our users are used to.

Yes, this was basically the motivation for the patch. It isn't up
to me what release of SLURM will contain the new functionality --
Moe might want to take a different approach or something. I'd like
to see it in the next release of 1.3, since LANL is asking for similar
functionality as well.

Keep in mind that for now you'll need the preserve-env SLURM plugin
(available in the tri-lab OS, or from
http://code.google.com/p/slurm-spank-plugins), or the environment will
not be correct in the shell spawned by srun -n1 -N1.

mark

Reply all
Reply to author
Forward
0 new messages