Skip to content

Commit

Permalink
Merge pull request lxcenter#7 from shazarlx/master
Browse files Browse the repository at this point in the history
Fixed set internal param for Fedora 16 (#764)
  • Loading branch information
shazarlx committed Jan 22, 2012
2 parents b88fc0c + 83566c4 commit f5a43ca
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 33 deletions.
28 changes: 28 additions & 0 deletions hypervm/bin/xen-dists/fedora-16.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (C) 2000-2006 SWsoft. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# This configuration file is meant to be used with
# the Fedora distribution kit.
#

ADD_IP=redhat-add_ip.sh
DEL_IP=redhat-del_ip.sh
SET_HOSTNAME=redhat-set_hostname.sh
SET_DNS=set_dns.sh
SET_USERPASS=set_userpass.sh
SET_UGID_QUOTA=set_ugid_quota.sh
POST_CREATE=postcreate.sh
STARTUP_SCRIPT=systemd
101 changes: 68 additions & 33 deletions hypervm/httpdocs/lib/vps/driver/vps__xenlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1646,53 +1646,88 @@ function setInternalParam($mountpoint)
$setuserpass = $result['SET_USERPASS'];
$ipdel = $result['DEL_IP'];

$name = createTempDir("$mountpoint/tmp", "xen-scripts");
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/functions", $name);
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/$ipadd", $name);
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/$sethostname", $name);
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/$setuserpass", $name);
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/$ipdel", $name);
if ($this->main->networkgateway) {
$gw = $this->main->networkgateway;
} else {
$gw = os_get_network_gateway();
}

$gwn = strtil($gw, '.') . '.0';

$basepath = strfrom($name, $mountpoint);
lfile_put_contents("$name/tmpfile.sh", "source /$basepath/functions\nsource /$basepath/$ipdel\n");
$delipstring = "IPDELALL=yes chroot $mountpoint bash /$basepath/tmpfile.sh";
$hostname = $this->main->hostname;
if (!$hostname) { $hostname = os_get_hostname(); }

if ($this->main->networkgateway) {
$gw = $this->main->networkgateway;
} else {
$gw = os_get_network_gateway();
}
if ($result['STARTUP_SCRIPT'] != 'systemd'){
$name = createTempDir("$mountpoint/tmp", 'xen-scripts');
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/functions", $name);
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/$ipadd", $name);
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/$sethostname", $name);
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/$setuserpass", $name);
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/$ipdel", $name);

log_shell($delipstring);
system($delipstring);
$basepath = strfrom($name, $mountpoint);
lfile_put_contents("$name/tmpfile.sh", "source /$basepath/functions\nsource /$basepath/$ipdel\n");
$delipstring = "IPDELALL=yes chroot $mountpoint bash /$basepath/tmpfile.sh";

$gwn = strtil($gw, ".") . ".0";
putenv("VE_STATE=stopped");
lfile_put_contents("$name/tmpfile.sh", "source /$basepath/functions\n source /$basepath/$ipadd\n");
$string = "IPDELALL=yes MAIN_NETMASK=$main_netmask MAIN_IP_ADDRESS=$main_ip IP_ADDR=\"$iplist\" NETWORK_GATEWAY=$gw NETWORK_GATEWAY_NET=$gwn chroot $mountpoint bash /$basepath/tmpfile.sh";
log_shell($delipstring);
log_shell(system($delipstring,$ret1) . ":return $ret1");

log_shell($string);
system($string);
putenv("VE_STATE=stopped");
lfile_put_contents("$name/tmpfile.sh", "source /$basepath/functions\n source /$basepath/$ipadd\n");
$string = "IPDELALL=yes MAIN_NETMASK=$main_netmask MAIN_IP_ADDRESS=$main_ip IP_ADDR=\"$iplist\" NETWORK_GATEWAY=$gw NETWORK_GATEWAY_NET=$gwn chroot $mountpoint bash /$basepath/tmpfile.sh";

$hostname = $this->main->hostname;
if (!$hostname) { $hostname = os_get_hostname(); }
log_shell($string);
log_shell(system($string, $ret1) . ":return $ret1");

lfile_put_contents("$name/tmpfile.sh", "source /$basepath/functions\n source /$basepath/$sethostname\n");
$string = "HOSTNM=$hostname chroot $mountpoint bash /$basepath/tmpfile.sh";
log_shell($string);
system($string);
lfile_put_contents("$name/tmpfile.sh", "source /$basepath/functions\n source /$basepath/$sethostname\n");
$string = "HOSTNM=$hostname chroot $mountpoint bash /$basepath/tmpfile.sh";
log_shell($string);
log_shell(system($string,$ret1).":return $ret1");

if (($this->main->subaction === 'rebuild') || ($this->main->dbaction === 'add') || ($this->main->isOn('__var_rootpassword_changed') && $this->main->rootpassword)) {
if (($this->main->subaction === 'rebuild') || ($this->main->dbaction === 'add') || ($this->main->isOn('__var_rootpassword_changed') && $this->main->rootpassword)) {
$rootpass = "root:{$this->main->rootpassword}";
lfile_put_contents("$name/tmpfile.sh", "source /$basepath/functions\n source /$basepath/$setuserpass\n");
$string = "USERPW=$rootpass chroot $mountpoint bash /$basepath/tmpfile.sh";
log_shell($string);
system($string);
}

log_shell(system($string));
}

lxfile_rm_rec($name);
}
else if ($result['STARTUP_SCRIPT'] == 'systemd'){
$script_dir = createTempDir("$mountpoint", "hypervm-runonce");
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/functions", $script_dir);
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/$ipadd", $script_dir);
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/$sethostname", $script_dir);
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/$setuserpass", $script_dir);
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/$ipdel", $script_dir);
$basepath = strfrom($script_dir, $mountpoint);
$startupdir = 'lib/systemd/system';
$startupscript = 'fedora-startup.service';

$setrootpass = '';
if (($this->main->subaction === 'rebuild') || ($this->main->dbaction === 'add') || ($this->main->isOn('__var_rootpassword_changed') && $this->main->rootpassword)) {
$rootpass = "root:{$this->main->rootpassword}";
$setrootpass = " & USERPW=$rootpass source $basepath/$setuserpass";
}

lxfile_rm_rec($name);
$run_once_script = "#!/bin/bash\n" .
"source $basepath/functions\n" .
'(' .
"IPDELALL=yes source $basepath/$ipdel" .
" & IPDELALL=yes VE_STATE=stopped MAIN_NETMASK=$main_netmask MAIN_IP_ADDRESS=$main_ip IP_ADDR=\"$iplist\" NETWORK_GATEWAY=$gw NETWORK_GATEWAY_NET=$gwn source $basepath/$ipadd" .
" & HOSTNM=$hostname source $basepath/$sethostname" .
"$setrootpass)\n" .
"service fedora-startup disable\nrm -f /$startupdir/$startupscript\nrm -rf $basepath";
lfile_put_contents("$script_dir/hypervm-runonce.sh", $run_once_script);

lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/$startupscript", "$mountpoint/$startupdir");
lfile_put_contents("$mountpoint/$startupdir/$startupscript",
lfile_get_contents("$mountpoint/$startupdir/$startupscript") .
"ExecStart=$basepath/hypervm-runonce.sh\n");
system("ln -s /lib/systemd/system/fedora-startup.service $mountpoint/etc/systemd/system/multi-user.target.wants/fedora-startup.service");
system("chmod 755 $script_dir/hypervm-runonce.sh");
}

if ($this->main->nameserver) {
$nlist = explode(" ", $this->main->nameserver);
Expand Down

0 comments on commit f5a43ca

Please sign in to comment.