[Lxc-users] lxc-clone
Serge Hallyn
serge.hallyn at canonical.com
Tue Jun 21 17:58:03 UTC 2011
Hi Daniel,
Quoting Daniel Lezcano (daniel.lezcano at free.fr):
> >>>+echo "Tweaking configuration"
> >>>+cp $lxc_path/$lxc_orig/config $lxc_path/$lxc_new/config
> >>>+sed -i '/lxc.utsname/d' $lxc_path/$lxc_new/config
> >>>+echo "lxc.utsname = $hostname">> $lxc_path/$lxc_new/config
> >>We should not assume lxc.utsname is in the configuration file in
> >>order to not write a hostname in all the cases.
> >>The user may want to let the container to setup itself the hostname.
> >What do you think is the best way to do this? We could allow the user
> >to specify a 'firstboot' script, which gets copied into root directory
> >of the container. Maybe boot the container when it's done, run
> >/firstboot.sh, and shut down. Or just let that happen when the user
> >first boots. We could use a /etc/init.d/lxc-firstboot script, but
> >that will only work if the container's init system actually looks at
> >sysvinit scripts. Obviously sysvinit and upstart do, and I must
> >assume that systemd does. lxc-init I assume doesn't.
>
> Mmh, that's look a bit complicate for the user. I was thinking about
> something simpler like:
>
> grep -q "lxc.utsname" $lxc_path/$lxc_new/config
> if [ $? == 0 ]; then
> sed -e "s/lxc.utsname/lxc.utsname=$hostname" $lxc_path/$lxc_new/config
> else
> echo "lxc.utsname = $hostname">> $lxc_path/$lxc_new/config
> fi
I started changing my code to this, but now am wondering how this
differs from what I was doing, which was:
sed -i '/lxc.utsname/d' $lxc_path/$lxc_new/config
echo "lxc.utsname = $hostname" >> $lxc_path/$lxc_new/config
The only difference is that in mine, if the original config had a
hostname at top of file, it'll now be at bottom of file. But with
both your snippets and mine, the 'lxc.utsname = new_hostname' will
be the one and only utsname in the config.
If you still think it's worth changing I'll do so, but I like that
mine is shorter.
-serge
More information about the lxc-users
mailing list