iocage icon indicating copy to clipboard operation
iocage copied to clipboard

Get iocage jail info inside pre-start/stop hooks

Open Marsel-marsel opened this issue 5 years ago • 0 comments

Hello, I want to add span interface into iocage jail via post-start hook. Before jail starts I want to create epair interfaces on host machine and add one of them into the jail using ifconfig epairXb vnet <jail_id> in post-start hook.sh. It will be nice if iocage initialize environment variables for hook.sh so I am able to get jail_id from there.

Versions of OS and iocage:

uname -a
FreeBSD my_host 12.0-RELEASE FreeBSD 12.0-RELEASE r341666 GENERIC  amd64
iocage --version
Version 1.2

Commands used, along with any steps to recreate it:

  1. Create hook.sh
cat /tmp/hook.sh
#!/bin/sh
echo args: $0 $@ >> /tmp/hook.out    # print arguments passed into hook.sh
echo env: `env`  >> /tmp/hook.out      # print env variables
  1. Set hook.sh as post-start hook for my_jail: iocage set exec_poststart=/tmp/hook.sh my_jail

  2. Start my_jail: iocage start my_jail

  3. Hook is executed, so I am able to look at its output:

cat /tmp/hook.out
args: /tmp/hook.sh
env: LANG=XXX PATH=YYY HOME=ZZZ ...   # no info about my_jail

On step 4 I expect to see variables related to jail:

env: LANG=XXX PATH=YYY HOME=ZZZ IOCAGE_JAIL_ID=888 IOCAGE_JAIL_UID=...

I am using the newest version of iocage so issue has not already been fixed on master if using a stable release.

Marsel-marsel avatar Apr 27 '20 14:04 Marsel-marsel