flux-core icon indicating copy to clipboard operation
flux-core copied to clipboard

how to distinguish between jobs that start an instance and those that don't in a shell plugin

Open ryanday36 opened this issue 3 years ago • 1 comments

We would our mpibind shell plugin to run when users launch a flux job that runs a user's code, but not when they just start a new instance. I.e. we'd like it to run by default when a user runs a 'flux mini run' or 'flux mini submit' command, but not when they run 'flux mini alloc' or 'flux mini batch'. Can this be detected in the initrc or in the plugin itself?

ryanday36 avatar Sep 27 '22 23:09 ryanday36

I think this will work for now while we figure out a better way to do it (perhaps an addition to the shell API along with a Lua interface for use in shell initrc scripts):

function is_flux_instance (shell)
    local basename = require 'posix'.basename
    local args = shell.info.jobspec.tasks[1].command
    if #args > 1 then
        local cmd = basename (args[1])
        local arg = args[2]
        if cmd == "flux" and (arg == "start" or arg == "broker") then
            return true
        end
    end
    return false
end

This returns true if the basename of the command the shell is launching is flux, and the first argument is either start or broker.

grondo avatar Sep 28 '22 00:09 grondo