mirror of
https://github.com/CHN-beta/nixos.git
synced 2026-01-12 04:19:22 +08:00
localPackages.hpcstat: ssh command add time limit
This commit is contained in:
@@ -83,10 +83,10 @@ namespace biu
|
||||
template <ExecMode Mode> struct ExecInput
|
||||
{
|
||||
std::conditional_t<Mode.SearchPath, std::string, std::filesystem::path> Program;
|
||||
std::vector<std::string> Args;
|
||||
std::vector<std::string> Args = {};
|
||||
std::conditional_t<Mode.DirectStdin, Empty, std::string> Stdin = {};
|
||||
std::map<std::string, std::string> ExtraEnv = {};
|
||||
std::optional<std::chrono::milliseconds> Timeout;
|
||||
std::optional<std::chrono::milliseconds> Timeout = {};
|
||||
};
|
||||
}
|
||||
template <detail_::ExecMode Mode = {}> detail_::ExecResult<Mode> exec(detail_::ExecInput<Mode> input);
|
||||
|
||||
@@ -31,11 +31,11 @@ namespace hpcstat::disk
|
||||
else if
|
||||
(
|
||||
auto result = biu::exec<{.DirectStdout = true, .DirectStderr = true}>
|
||||
(
|
||||
({
|
||||
// duc index -d ./duc.db -p ~
|
||||
"{}/duc"_f(*ducbindir),
|
||||
{ "index", "-d", "{}/duc.db"_f(*datadir), "-p", *homedir }
|
||||
);
|
||||
});
|
||||
!result
|
||||
)
|
||||
{ std::cerr << "failed to index\n"; return false; }
|
||||
@@ -57,14 +57,14 @@ namespace hpcstat::disk
|
||||
if
|
||||
(
|
||||
auto result = biu::exec
|
||||
(
|
||||
({
|
||||
// duc ls -d ./duc.db -b -D /data/gpfs01/jykang/linwei/xxx
|
||||
"{}/duc"_f(*ducbindir),
|
||||
{
|
||||
"ls", "-d", "{}/duc.db"_f(*datadir), "-b", "-D",
|
||||
"{}{}{}"_f(*homedir, path ? "/" : "", path.value_or(""))
|
||||
}
|
||||
);
|
||||
});
|
||||
!result
|
||||
)
|
||||
{ std::cerr << "failed to ls {}\n"_f(path); return {}; }
|
||||
@@ -90,7 +90,7 @@ namespace hpcstat::disk
|
||||
(
|
||||
// duc info -d ./duc.db
|
||||
auto result = biu::exec
|
||||
("{}/duc"_f(*ducbindir), { "info", "-d", "{}/duc.db"_f(*datadir) });
|
||||
({"{}/duc"_f(*ducbindir), { "info", "-d", "{}/duc.db"_f(*datadir) }});
|
||||
!result
|
||||
)
|
||||
{ std::cerr << "failed to get duc info\n"; return {}; }
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace hpcstat::lfs
|
||||
}
|
||||
else break;
|
||||
}
|
||||
if (auto result = biu::exec(*bsub, args); !result) return std::nullopt;
|
||||
if (auto result = biu::exec({*bsub, args}); !result) return std::nullopt;
|
||||
else
|
||||
{
|
||||
// Job <462270> is submitted to queue <normal_1day>.
|
||||
@@ -45,10 +45,11 @@ namespace hpcstat::lfs
|
||||
if
|
||||
(
|
||||
auto result = biu::exec<{.SearchPath = true}>
|
||||
(
|
||||
"bjobs", { "-a", "-o", "jobid submit_time stat cpu_used job_name", "-json" },
|
||||
{}, { { "LSB_DISPLAY_YEAR", "Y" } }
|
||||
);
|
||||
({
|
||||
.Program="bjobs",
|
||||
.Args={ "-a", "-o", "jobid submit_time stat cpu_used job_name", "-json" },
|
||||
.ExtraEnv={ { "LSB_DISPLAY_YEAR", "Y" } }
|
||||
});
|
||||
!result
|
||||
)
|
||||
return std::nullopt;
|
||||
@@ -79,7 +80,11 @@ namespace hpcstat::lfs
|
||||
}
|
||||
std::optional<std::string> bjobs_detail(unsigned jobid)
|
||||
{
|
||||
if (auto result = biu::exec<{.SearchPath = true}>("bjobs", { "-l", "{}"_f(jobid) }); !result)
|
||||
if
|
||||
(
|
||||
auto result = biu::exec<{.SearchPath = true}>({"bjobs", { "-l", "{}"_f(jobid) }});
|
||||
!result
|
||||
)
|
||||
return std::nullopt;
|
||||
else return result.Stdout;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@ namespace hpcstat::ssh
|
||||
return std::nullopt;
|
||||
else if
|
||||
(
|
||||
auto output = biu::exec(std::filesystem::path(*sshbindir) / "ssh-add", { "-l" });
|
||||
auto output = biu::exec
|
||||
({.Program=std::filesystem::path(*sshbindir) / "ssh-add", .Args{ "-l" }, .Timeout=10s});
|
||||
!output
|
||||
)
|
||||
{ std::cerr << "Failed to get ssh fingerprints\n"; return std::nullopt; }
|
||||
@@ -41,14 +42,15 @@ namespace hpcstat::ssh
|
||||
else if
|
||||
(
|
||||
auto output = biu::exec
|
||||
(
|
||||
std::filesystem::path(*sshbindir) / "ssh-keygen",
|
||||
{
|
||||
({
|
||||
.Program=std::filesystem::path(*sshbindir) / "ssh-keygen",
|
||||
.Args={
|
||||
"-Y", "sign", "-q", "-f", "{}/keys/{}"_f(*sharedir, Keys[fingerprint].PubkeyFilename),
|
||||
"-n", "hpcstat@chn.moe", "-"
|
||||
},
|
||||
message
|
||||
);
|
||||
.Stdin=message,
|
||||
.Timeout=10s
|
||||
});
|
||||
!output
|
||||
)
|
||||
{ std::cerr << "Failed to sign message: {}\n"_f(message); return {}; }
|
||||
@@ -68,15 +70,16 @@ namespace hpcstat::ssh
|
||||
auto signaturefile = tempdir / "signature";
|
||||
std::ofstream(signaturefile) << signature;
|
||||
auto result = biu::exec
|
||||
(
|
||||
std::filesystem::path(*sshbindir) / "ssh-keygen",
|
||||
{
|
||||
({
|
||||
.Program=std::filesystem::path(*sshbindir) / "ssh-keygen",
|
||||
.Args={
|
||||
"-Y", "verify",
|
||||
"-f", "{}/keys/{}"_f(*sharedir, Keys[fingerprint].PubkeyFilename),
|
||||
"-n", "hpcstat@chn.moe", "-s", signaturefile.string()
|
||||
},
|
||||
message
|
||||
);
|
||||
.Stdin=message,
|
||||
.Timeout=10s
|
||||
});
|
||||
std::filesystem::remove_all(tempdir.string());
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user