argument 4. The <filename>LXC_ROOTFS_MOUNT</filename> environment variable gives
the path under which the container's root filesystem is mounted. The
configuration file pathname is stored in <filename>LXC_CONFIG_FILE</filename>, the
- container name in <filename>LXC_NAME</filename>, and the path or device on which
+ new container name in <filename>LXC_NAME</filename>, the old container name in
+ <filename>LXC_SRC_NAME</filename>, and the path or device on which
the rootfs is located is in <filename>LXC_ROOTFS_PATH</filename>.
</para>
</refsect1>
hooksdir=@LXCHOOKDIR@
hooks_SCRIPTS = \
+ clonehostname \
mountcgroups \
mountecryptfsroot
--- /dev/null
+#!/bin/sh
+#
+# Update the hostname in the cloned container's scripts
+#
+# Copyright © 2013 Oracle.
+#
+# This library is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2, as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+# Note that /etc/hostname is updated by lxc itself
+for file in \
+ $LXC_ROOTFS_PATH/etc/sysconfig/network \
+ $LXC_ROOTFS_PATH/etc/sysconfig/network-scripts/ifcfg-* ;
+do
+ if [ -f $file ]; then
+ sed -i "s|$LXC_SRC_NAME|$LXC_NAME|" $file
+ fi
+done
+exit 0
return 0;
}
-static int clone_update_rootfs(struct lxc_container *c, int flags, char **hookargs)
+static int clone_update_rootfs(struct lxc_container *c0,
+ struct lxc_container *c, int flags,
+ char **hookargs)
{
int ret = -1;
char path[MAXPATHLEN];
if (!lxc_list_empty(&conf->hooks[LXCHOOK_CLONE])) {
/* Start of environment variable setup for hooks */
+ if (setenv("LXC_SRC_NAME", c0->name, 1)) {
+ SYSERROR("failed to set environment variable for source container name");
+ }
if (setenv("LXC_NAME", c->name, 1)) {
SYSERROR("failed to set environment variable for container name");
}
if (!c2->save_config(c2, NULL))
goto out;
- if (clone_update_rootfs(c2, flags, hookargs) < 0)
+ if (clone_update_rootfs(c, c2, flags, hookargs) < 0)
goto out;
// TODO: update c's lxc.snapshot = count