Skip to content

Commit

Permalink
add PROGRAM parameter to eve-enter-container
Browse files Browse the repository at this point in the history
The script eve-enter-container calls internally nsenter, which Defaults
to calling $(SHELL) if no PROGRAM parameter is provided. And since the
shim VM is built from alpine image, the default shell is /bin/ash.
So unless the container running in the shim VM is also based on alpine,
it won't have /bin/ash and the script will fail.

This commit adds a PROGRAM parameter to the script, so that the user can
specify the shell (or another program) to be used when entering the
container. If the parameter is not provided, the default is /bin/sh.

Signed-off-by: Paul Gaiduk <paulg@zededa.com>
  • Loading branch information
europaul authored and milan-zededa committed Aug 26, 2024
1 parent 09aeedf commit 8c5b27a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/DEBUGGING.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ In order to attach to the console of the hosting Vm of the Container application

The `prime-cons` console exists only for the Container applications and is always reachable for executing commands on the Vm which hosts corresponding container.

Once terminal responds on the `prime-cons` console it is possible to enter container by executing the `eve-enter-container` command:
Once terminal responds on the `prime-cons` console it is possible to enter container by executing the `eve-enter-container` command. The script takes an optional argument with the path to the program to run in the container (the path is relative to the root of the container filesystem). If no argument is provided, the script will try to call the shell (`/bin/sh`) in the container:

```bash
~ # eve-enter-container
Expand Down
10 changes: 9 additions & 1 deletion pkg/xen-tools/initrd/eve-enter-container
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ if [ ! -f "$PID_FILE" ]; then
fi

PID=$(cat "$PID_FILE")
nsenter -t "$PID" -m -u -i -n -p -r/mnt/rootfs -w/mnt/rootfs

# Check if the first argument is provided, otherwise use /bin/sh as the default
PROGRAM=${1:-/bin/sh}

# Shift arguments if a program is provided, so "$@" contains the rest of the command-line arguments
shift

# Enter the namespaces and execute the specified program with its arguments
nsenter -t "$PID" -m -u -i -n -p -r/mnt/rootfs -w/mnt/rootfs "$PROGRAM" "$@"

0 comments on commit 8c5b27a

Please sign in to comment.