dockerd-rootless-setuptool.sh: add nsenter subcommand

Usage: `dockerd-rootless-setuptool.sh nsenter -- ip a`

Expected to be used for debugging.

Ported from nerdctl's `containerd-rootless-setuptool.sh`
https://github.com/containerd/nerdctl/blob/v1.7.2/extras/rootless/containerd-rootless-setuptool.sh#L142-L147

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
Akihiro Suda 2024-01-17 00:00:32 +09:00
parent 7d08d84b03
commit 84d2229ffe
No known key found for this signature in database
GPG key ID: 49524C6F9F638F1A

View file

@ -273,10 +273,18 @@ init() {
# CLI subcommand: "check"
cmd_entrypoint_check() {
init
# requirements are already checked in init()
INFO "Requirements are satisfied"
}
# CLI subcommand: "nsenter"
cmd_entrypoint_nsenter() {
# No need to call init()
pid=$(cat "$XDG_RUNTIME_DIR/dockerd-rootless/child_pid")
exec nsenter --no-fork --wd="$(pwd)" --preserve-credentials -m -n -U -t "$pid" -- "$@"
}
show_systemd_error() {
n="20"
ERROR "Failed to start ${SYSTEMD_UNIT}. Run \`journalctl -n ${n} --no-pager --user --unit ${SYSTEMD_UNIT}\` to show the error log."
@ -383,6 +391,7 @@ cli_ctx_rm() {
# CLI subcommand: "install"
cmd_entrypoint_install() {
init
# requirements are already checked in init()
if [ -z "$SYSTEMD" ]; then
install_nonsystemd
@ -416,6 +425,7 @@ cmd_entrypoint_install() {
# CLI subcommand: "uninstall"
cmd_entrypoint_uninstall() {
init
# requirements are already checked in init()
if [ -z "$SYSTEMD" ]; then
INFO "systemd not detected, ${DOCKERD_ROOTLESS_SH} needs to be stopped manually:"
@ -461,6 +471,7 @@ usage() {
echo
echo "Commands:"
echo " check Check prerequisites"
echo " nsenter Enter into RootlessKit namespaces (mostly for debugging)"
echo " install Install systemd unit (if systemd is available) and show how to manage the service"
echo " uninstall Uninstall systemd unit"
}
@ -508,5 +519,4 @@ if ! command -v "cmd_entrypoint_${command}" > /dev/null 2>&1; then
fi
# main
init
"cmd_entrypoint_${command}"
"cmd_entrypoint_${command}" "$@"