on master help sign in
LXC: add /.lxcenv

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>

commitd2cfe9ce5bb409472f10590aa1ae069b2a971a49 authorMarkus Heiser <markus.heiser@darmarit.de> dateWed 18 Mar 2020, 15:34 (7 years ago) parent86e7948
3 files changed+23−7
utils/lib.sh+18−5 utils/lxc-searx.env+1 utils/lxc.sh+4−2
utils/lib.sh+18−5
@@ -1065,18 +1065,31 @@ EOF
10651065in_container() {
10661066 # Test if shell runs in a container.
10671067 #
1068− # hint: Reads init process environment, therefore root access is required!
1069− #
10701068 # usage: in_container && echo "process running inside a LXC container"
10711069 # in_container || echo "process is not running inside a LXC container"
10721070 #
1073−
1074− sudo_or_exit
1071+ # sudo_or_exit
1072+ # hint: Reads init process environment, therefore root access is required!
10751073 # to be safe, take a look at the environment of process 1 (/sbin/init)
1076− grep -qa 'container=lxc' /proc/1/environ
1074+ # grep -qa 'container=lxc' /proc/1/environ
1075+
1076+ # see lxc_init_container
1077+ [[ -f /.lxcenv ]]
10771078}
10781079
1080+lxc_init_container() {
10791081
1082+ # Create a /.lxcenv file in the root folder. Call this once after container
1083+ # is inital started.
1084+
1085+ # usage: lxc_create_root_dot_lxcenv <name>
1086+
1087+ info_msg "create /.lxcenv in container $1"
1088+ cat <<EOF | lxc exec "${1}" -- bash | prefix_stdout "[${_BBlue}${1}${_creset}] "
1089+touch "/.lxcenv"
1090+ls -l "/.lxcenv"
1091+EOF
1092+}
10801093lxc_exists(){
10811094
10821095 # usage: lxc_exists <name> || echo "container <name> does not exists"
utils/lxc-searx.env+1
@@ -51,6 +51,7 @@ lxc_suite_prepare_buildhost() {
5151 (
5252 lxc_set_suite_env
5353 export FORCE_TIMEOUT=0
54+ # "${LXC_REPO_ROOT}/utils/searx.sh* install packages
5455 "${LXC_REPO_ROOT}/utils/searx.sh" install buildhost
5556 rst_title "buildhost installation finished ($(hostname))" part
5657 echo
utils/lxc.sh+4−2
@@ -82,7 +82,7 @@ usage::
8282 $_cmd [start|stop] [containers|<name>]
8383 $_cmd show [info|config|suite|images]
8484 $_cmd cmd [--|<name>] '...'
85− $_cmd install [suite]
85+ $_cmd install [suite|buildhost]
8686
8787build
8888 :containers: build & launch all LXC containers of the suite
@@ -443,10 +443,12 @@ lxc_boilerplate_containers() {
443443 boilerplate_script="${image_name}_boilerplate"
444444 boilerplate_script="${!boilerplate_script}"
445445
446− info_msg "[${_BBlue}${container_name}${_creset}] install /.lxcenv.mk .."
446+ info_msg "[${_BBlue}${container_name}${_creset}] init .."
447447 if lxc start -q "${container_name}" &>/dev/null; then
448448 sleep 5 # guest needs some time to come up and get an IP
449449 fi
450+ lxc_init_container "${container_name}"
451+ info_msg "[${_BBlue}${container_name}${_creset}] install /.lxcenv.mk .."
450452 cat <<EOF | lxc exec "${container_name}" -- bash | prefix_stdout "[${_BBlue}${container_name}${_creset}] "
451453rm -f "/.lxcenv.mk"
452454ln -s "${LXC_REPO_ROOT}/utils/makefile.lxc" "/.lxcenv.mk"