Commit 2da11ebc authored by Alan Garcia's avatar Alan Garcia

VM "expiré" sont arrété

parent 669dab29
......@@ -599,6 +599,7 @@ src/functions.sh -text
src/functions_dns.sh -text
src/functions_hosting.sh -text
src/inotify_update_domains.sh -text
src/lxc_stopexpired.php -text
src/mail_dodelete.php -text
src/mem_add -text
src/mem_del -text
......
......@@ -14,6 +14,7 @@ class m_lxc implements vm
$this->IP = variable_get('lxc_ip', '', "IP address of the Alternc's LXC server. If empty, no LXC server.");
$this->PORT = variable_get('lxc_port', '6504', "Port of the Alternc's LXC server");
$this->KEY = variable_get('lxc_key', '', "Shared key with the Alternc's LXC server");
$this->maxtime = variable_get('lxc_maxtime', '4', "How many hours do we allow to have a server before shutting it down");
}
......@@ -37,6 +38,29 @@ class m_lxc implements vm
return true;
}
// Stop VMs running since more than MAXTIME hours
function stop_expired($force=false) {
global $mem,$err;
# Need to be distinct of $db (calling subfunctions)
$db2 = new DB_system();
if (! $mem->checkright() ) {
$err->raise("lxc",_("-- Only administrators can do that! --"));
return false;
}
# If force, maxtime = 0
$time = ($force?0:$this->maxtime);
$db2->query("select * from vm_history where date_end is null and date_start < subdate( now() , interval $time hour);");
while ($db2->next_record()) {
$mem->su($db2->Record['uid']);
$this->stop();
$mem->unsu();
}
}
private function sendMessage($params) {
$fp = fsockopen($this->IP, $this->PORT, $errno, $errstr, $this->TIMEOUT);
......@@ -121,20 +145,32 @@ class m_lxc implements vm
public function getvm()
{
global $db, $mem;
$uid = $mem->user['uid'];
$res = array();
global $db, $mem, $cuid;
$res = $db->query("SELECT * FROM vm_history WHERE date_end IS NULL AND uid= '$uid' ORDER BY id DESC LIMIT 1");
$db->query("SELECT * FROM vm_history WHERE date_end IS NULL AND uid= $cuid ORDER BY id DESC LIMIT 1");
if ($db->next_record())
{
if ($db->next_record()){
$db->Record['serialized_object'] = unserialize($db->Record['serialized_object']);
return $db->Record;
}
else
else {
return FALSE;
}
}
# Stop all VMs
public function stopall() {
global $mem, $db, $err;
if (! $mem->checkright() ) {
$err->raise("lxc",_("-- Only administrators can do that! --"));
return false;
}
if ($this->sendMessage(array('action' => 'stopall' )) === FALSE)
return FALSE;
return $db->query("UPDATE vm_history SET date_end = NOW() WHERE date_end is null;");
}
public function stop()
......
......@@ -26,3 +26,6 @@
# Every 30 minutes, do cron_users actions
00,30 * * * * alterncpanel /usr/lib/alternc/cron_users.sh
# Every hour, stop expired VMs
10 * * * * alterncpanel /usr/lib/alternc/lxc_stopexpired.php
......@@ -19,7 +19,7 @@
# ----------------------------------------------------------------------
# Purpose of file: Makefile des binaires de /usr/lib/alternc
# ----------------------------------------------------------------------
SCRIPTS=sqlbackup.sh quota_init quota_delete update_domains.sh slave_dns sendmail spoolsize.php fixperms.sh alternc-dboptimize export_account.php cron_users_doit.sh cron_users.sh compress_logs.sh delete_logs.sh quota-warning.sh update_mails.sh alternc_add_policy_dovecot rebuild_all_webconf.sh courier-dovecot-migrate.pl popimap-log-login.sh mem_add mem_del quota_edit quota_get du.pl update_quota_mail.sh inotify_update_domains.sh functions.sh functions_hosting.sh functions_dns.sh mail_dodelete.php procmail_to_sieve.php
SCRIPTS=sqlbackup.sh quota_init quota_delete update_domains.sh slave_dns sendmail spoolsize.php fixperms.sh alternc-dboptimize export_account.php cron_users_doit.sh cron_users.sh compress_logs.sh delete_logs.sh quota-warning.sh update_mails.sh alternc_add_policy_dovecot rebuild_all_webconf.sh courier-dovecot-migrate.pl popimap-log-login.sh mem_add mem_del quota_edit quota_get du.pl update_quota_mail.sh inotify_update_domains.sh functions.sh functions_hosting.sh functions_dns.sh mail_dodelete.php procmail_to_sieve.php lxc_stopexpired.php
BIN=$(DESTDIR)/usr/lib/alternc/
install:
......
#!/usr/bin/php -q
<?php
/*
$Id: do_actions.php,v 1.0 2013/04/19 13:40:32 axel Exp $
----------------------------------------------------------------------
AlternC - Web Hosting System
Copyright (C) 2002 by the AlternC Development Team.
http://alternc.org/
----------------------------------------------------------------------
Based on:
Valentin Lacambre's web hosting softwares: http://altern.org/
----------------------------------------------------------------------
LICENSE
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License (GPL)
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.
To read the license please visit http://www.gnu.org/copyleft/gpl.html
----------------------------------------------------------------------
Original Author of file: Alan Garcia
Purpose of file: Shutdown expired VMs
----------------------------------------------------------------------
*/
require_once("/usr/share/alternc/panel/class/config_nochk.php");
# Be super user
#$mem->setid(2000);
$admin->enabled=1;
# Stop expired vms
$lxc->stop_expired();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment