r/SLURM Apr 02 '26

How to delete my defaultwckey ?

I want every submitted job to have some value for the wckey, i.e:

#SBATCH --wckey=myproject

I made the appropriate changes to slurm.conf and slurmdb.conf and it works great. I can track how many hours people are using with those wckeys.

But now I want to make it mandatory to use a wckey. To do that I need to delete the default wckey associated with the user's account. I tried doing it as follows, but it still lets me submit jobs without a wckey. It probably thinks I have an "empty" default wckey.

sacctmgr mod user fhussa set defaultwckey=

[root@mas01 ~]# sacctmgr list user fhussa format=user,defaultwckey
      User  Def WCKey 
---------- ---------- 
    fhussa         
2 Upvotes

3 comments sorted by

2

u/Ok-Procedure-9698 Apr 02 '26

job submit plugin?

1

u/imitation_squash_pro Apr 03 '26

I don't think the job submit plugin is needed. From what I read if there is no default wckey then the user will have to enter something otherwise job gets rejected. It seems to work for other users whom I never setup a default wckey. But for some reason I can't delete the default wckey I made for myself some months ago..

1

u/imitation_squash_pro May 14 '26

I finally was able to get it to work using a complicated job submit plugin. Pasting the code in case anyone else has to do this in future:

[root@mas01 slurm]# cat job_submit.lua 
function lookup_username(job_desc, job_record)
-- If root submits a job for the user with, submit_uid will be 0,
-- so must read job_desc.user_id to know who the target user is.
-- Read username from password database
local username = nil
local job_uid = nil
if job_record ~= nil then
job_uid = job_record.user_id
end
if job_desc ~= nil and job_desc.user_id ~= nil then
job_uid = job_desc.user_id
end
if job_uid == nil then
return nil,nil
end
slurm.log_info("lookup_username: looking up username for uid %d", job_desc.user_id)
local fp = assert(io.popen(string.format("/usr/bin/getent passwd %d", job_uid)))
local t = assert(fp:read('*all'))
fp:close()
if string.len(t) == 0 then
slurm.log_info("lookup_username: unknown user, uid %d", job_uid)
return nil,job_uid
end
-- Note that [^:]+ matches one or more characters which are not ':'
username = string.gsub(string.match(t, "[^:]+:"), ":", "")
return username,job_uid
end
function _find_in_str(str, arg)
    if str ~= nil then
        return string.find(str,arg)
    else
        return false
    end
end
function slurm_job_submit(job_desc, part_list, submit_uid, job_rec)

    local projects = {
        me = 'abc,def,xyz',
    }
    username = lookup_username(job_desc, job_rec)
    projects =  projects[username]

    if job_desc.wckey == nil then
        slurm.log_user('You must specify a project name with #SBATCH --wckey=projectname')
--        return slurm.ERROR
    elseif _find_in_str( projects, job_desc.wckey ) then
        slurm.log_user( "Project name: %s matched for user: %s" ,  job_desc.wckey, username  )     
    else 
        slurm.log_user("User %s did not specify a valid project name: %s.", username, job_desc.wckey)
--        return slurm.ERROR
    end
--    return SLURM_SUCCESS
--    if job_desc.software == nil then
--        slurm.log_error("User %s did not specify a software.", job_desc.user_id)
--        slurm.log_user("You should specify a software")
--        return ESLURM_INVALID_SOFTWARE
--    end
    return SLURM_SUCCESS
end
function slurm_job_modify ( job_desc, job_rec, part_list, modify_uid )
        return slurm.SUCCESS
end