Skip to content

Commit

Permalink
now working without arguments or commands
Browse files Browse the repository at this point in the history
Signed-off-by: Surax98 <[email protected]>
  • Loading branch information
Surax98 committed Jun 14, 2024
1 parent 79c44fb commit 62bbf30
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 34 deletions.
10 changes: 9 additions & 1 deletion pkg/slurm/Create.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@ func (h *SidecarHandler) SubmitHandler(w http.ResponseWriter, r *http.Request) {
singularityOptions = singOpts
}

commstr1 := []string{"singularity", "exec", "--containall", "--nv", singularityMounts, singularityOptions}
commstr1 := []string{"singularity", "run", "--containall", "--nv", singularityMounts, singularityOptions}

/*var commstr1 []string
if len(container.Command) != 0 {
commstr1 = []string{"singularity", "exec", "--containall", "--nv", singularityMounts, singularityOptions}
} else {
commstr1 = []string{"singularity", "exec", "--containall", "--nv", singularityMounts, singularityOptions}
}*/

envs := prepareEnvs(h.Ctx, container)
image := ""
Expand Down
84 changes: 51 additions & 33 deletions pkg/slurm/aux.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,43 +412,61 @@ func produceSLURMScript(
stringToBeWritten += sbatch_macros

for _, singularityCommand := range commands {
f2, err := os.Create(path + "/" + "args_" + singularityCommand.containerName + ".sh")
if err != nil {
log.G(Ctx).Error(err)
return "", err
}
defer f2.Close()
argString := strings.Join(singularityCommand.containerArgs, " ")
_, err = f2.WriteString(argString)
if err != nil {
log.G(Ctx).Error(err)
return "", err
} else {
log.G(Ctx).Debug("---- Written arguments file " + f2.Name())
}

f3, err := os.Create(path + "/" + "command_" + singularityCommand.containerName + ".sh")
if err != nil {
log.G(Ctx).Error(err)
return "", err
cmdString := ""

if len(singularityCommand.containerCommand) != 0 {
f3, err := os.Create(path + "/" + "command_" + singularityCommand.containerName + ".sh")
if err != nil {
log.G(Ctx).Error(err)
return "", err
}
defer f3.Close()

f2, err := os.Create(path + "/" + "args_" + singularityCommand.containerName + ".sh")
if err != nil {
log.G(Ctx).Error(err)
return "", err
}
defer f2.Close()

if len(singularityCommand.containerArgs) != 0 {
cmdString = strings.Join(singularityCommand.containerCommand, " ") + " \"$(cat /tmp/args_" + singularityCommand.containerName + ".sh)\""
} else {
cmdString = strings.Join(singularityCommand.containerCommand, " ")
}

_, err = f3.WriteString(cmdString)
if err != nil {
log.G(Ctx).Error(err)
return "", err
} else {
log.G(Ctx).Debug("---- Written command file " + f3.Name())
}

argString := strings.Join(singularityCommand.containerArgs, " ")
_, err = f2.WriteString(argString)
if err != nil {
log.G(Ctx).Error(err)
return "", err
} else {
log.G(Ctx).Debug("---- Written arguments file " + f2.Name())
}

os.Chmod(f2.Name(), 0777|os.ModePerm)
os.Chmod(f3.Name(), 0777|os.ModePerm)
}
defer f3.Close()
cmdString := strings.Join(singularityCommand.containerCommand, " ") + " \"$(cat /tmp/args_" + singularityCommand.containerName + ".sh)\""
_, err = f3.WriteString(cmdString)
if err != nil {
log.G(Ctx).Error(err)
return "", err

if len(singularityCommand.containerCommand) != 0 {
stringToBeWritten += "\n" + strings.Join(singularityCommand.singularityCommand[:], " ") + " " +
"/bin/sh" + " /tmp/" + "command_" + singularityCommand.containerName + ".sh" +
" &> " + path + "/" + singularityCommand.containerName + ".out; " +
"echo $? > " + path + "/" + singularityCommand.containerName + ".status &"
} else {
log.G(Ctx).Debug("---- Written command file " + f3.Name())
stringToBeWritten += "\n" + strings.Join(singularityCommand.singularityCommand[:], " ") + " " +
" &> " + path + "/" + singularityCommand.containerName + ".out; " +
"echo $? > " + path + "/" + singularityCommand.containerName + ".status &"
}

os.Chmod(f2.Name(), 0777|os.ModePerm)
os.Chmod(f3.Name(), 0777|os.ModePerm)

stringToBeWritten += "\n" + strings.Join(singularityCommand.singularityCommand[:], " ") + " " +
"/bin/sh" + " /tmp/" + "command_" + singularityCommand.containerName + ".sh" +
" &> " + path + "/" + singularityCommand.containerName + ".out; " +
"echo $? > " + path + "/" + singularityCommand.containerName + ".status &"
}

stringToBeWritten += "\n" + postfix
Expand Down

0 comments on commit 62bbf30

Please sign in to comment.