Changeset 35


Ignore:
Timestamp:
Jun 15, 2009, 10:19:02 AM (15 years ago)
Author:
george
Message:
  • Upraveno: Zamykání a odemykání prostředků přímo z příkazů úloh. Zamykání serverů, emulátorů a záloh.
  • Upraveno: Možnost volat shell.php z relativní cestou. Skript global.php si nastaví sám aktuální cestu.
  • Opraveno: Zobrazovat sprváně trvání aktuálně běžící úlohy.
Location:
trunk/www
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/backup.php

    r31 r35  
    2020    $ServerId = $this->Backup['Server'];
    2121    $this->Task->Add('Obnovení databáze', array(
     22      'php www/shell.php ServerLock '.$ServerId,
    2223      'mysql --silent --skip-column-names -u server'.$ServerId.' -pserver'.$ServerId.' server'.$ServerId.'_mangos -e "show tables" | gawk \'{print "drop table " $1 ";"}\' | mysql -u server'.$ServerId.' -pserver'.$ServerId.' server'.$ServerId.'_mangos',
    2324      'mysql --silent --skip-column-names -u server'.$ServerId.' -pserver'.$ServerId.' server'.$ServerId.'_characters -e "show tables" | gawk \'{print "drop table " $1 ";"}\' | mysql -u server'.$ServerId.' -pserver'.$ServerId.' server'.$ServerId.'_characters',
     
    3132      'mysql --user=server'.$ServerId.' --password=server'.$ServerId.' server'.$ServerId.'_scriptdev2 < temp/wowhosting/scriptdev2.sql',
    3233      'rm -rf temp/wowhosting',
     34      'php www/shell.php ServerUnLock '.$ServerId,     
    3335    ));
    3436    return('Úloha obnovení databáze ze zálohy zařazena do fronty.');
     
    3941    $Server = new Server($this->Database, $ServerId);
    4042    $Description = 'MaNGOS r'.$Server->Server['Database']['Emulator']['Revision'].', UDB r'.$Server->Server['Database']['Revision'].', SD2 r'.$Server->Server['Database']['ScriptDev2Revision'].', Client '.$Server->Server['Database']['Emulator']['Client']['Version'];
    41     $this->Database->insert('Backup', array('Server' => $ServerId, 'Time' => 'NOW()', 'Description' => $Description));
     43    $this->Database->insert('Backup', array('Server' => $ServerId, 'Time' => 'NOW()', 'Description' => $Description, 'Lock' => 1));
    4244    $this->Id = $this->Database->insert_id;
    4345    $this->Task->Add('Záloha databáze serveru', array(
     46      'php www/shell.php ServerLock '.$ServerId,
    4447      'mkdir temp/wowhosting',
    4548      'mysqldump --user=server'.$ServerId.' --password=server'.$ServerId.' --opt server'.$ServerId.'_characters > temp/wowhosting/characters.sql',
     
    5053      'tar -c -j wowhosting > ../backup/wowhosting-'.$this->Id.'.tar.bz2',
    5154      'rm -rf wowhosting',
     55      'php www/shell.php BackupUnLock '.$this->Id,
     56      'php www/shell.php ServerUnLock '.$ServerId,
    5257    ));
    5358    return('Úloha zálohování byla zařazena do fronty.');
    5459  } 
     60 
     61  function Lock()
     62  {
     63    $this->Database->update('Backup', 'Id='.$this->Id, array('Lock' => 1));
     64  }
     65 
     66  function UnLock()
     67  {
     68    $this->Database->update('Backup', 'Id='.$this->Id, array('Lock' => 0));
     69  }
    5570}
    5671
  • trunk/www/emulator.php

    r34 r35  
    3737    $this->Lock();
    3838    $this->Task->Add('Stažení emulátoru', array(
     39      'php www/shell.php EmulatorLock '.$this->Id,
    3940      'mkdir '.$Config['BaseDir'].'emulator/'.$this->Id.'/',
    4041      'cd '.$Config['BaseDir'].'emulator/'.$this->Id.'/',
     
    4546      'svn checkout -r '.$this->Emulator['ScriptDev2Revision'].' https://scriptdev2.svn.sourceforge.net/svnroot/scriptdev2/ src/bindings/ScriptDev2',
    4647      'git apply src/bindings/ScriptDev2/patches/'.$this->Emulator['ScriptDev2PatchFileName'],
     48      'php www/shell.php EmulatorUnLock '.$this->Id,
    4749    ));
    4850  }
     
    5456    $this->Lock();
    5557    $this->Task->Add('Překlad emulátoru', array(
     58      'php www/shell.php EmulatorLock '.$this->Id,
    5659      'cd '.$Config['BaseDir'].'emulator/'.$this->Id.'/source',
    5760      'autoreconf -ifv',
     
    6366      'make',
    6467      'make install',
     68      'php www/shell.php EmulatorUnLock '.$this->Id,
    6569    ));
    6670  }
     
    7074    $this->Lock();
    7175    $this->Task->Add('Vygenerování souborů map', array(
     76      'php www/shell.php EmulatorLock '.$this->Id,
    7277      'cd wowclient/'.$this->Emulator['Client']['Version'].'/client',
    7378      'wine emulator/'.$this->Id.'/source/contrib/extractor/ad.exe',
    7479      'mv wowclient/'.$this->Emulator['Client']['Version'].'/client/dbc wowclient/'.$this->Emulator['Client']['Version'].'/',
    7580      'mv wowclient/'.$this->Emulator['Client']['Version'].'/client/maps wowclient/'.$this->Emulator['Client']['Version'].'/',
     81      'php www/shell.php EmulatorUnLock '.$this->Id,     
    7682    ));
    7783    return('Požadavek na vygenerování map zařazen.');
    7884  }
    79  
    8085 
    8186  function Lock()
  • trunk/www/global.php

    r34 r35  
    11<?php
     2
     3chdir(substr($_SERVER['SCRIPT_FILENAME'], 0, strrpos($_SERVER['SCRIPT_FILENAME'], '/')));
    24
    35$ScriptTimeStart = GetMicrotime();
  • trunk/www/index.php

    r34 r35  
    113113        foreach($Table->Values as $Index => $Item)
    114114        {
    115           $Table->Values[$Index]['Actions'] = '<a href="?Action=EmulatorShow&amp;Id='.$Item['Id'].'">Podprobnosti</a>';
     115          $Table->Values[$Index]['Actions'] = '<a href="?Action=EmulatorShow&amp;Id='.$Item['Id'].'">Podrobnosti</a>';
    116116          if($Server->Server['Lock'] == 0) $Table->Values[$Index]['Actions'] .= ' <a href="?Action=Update&amp;Server='.$ServerId.'&amp;Update='.$Item['Id'].'">Aktualizovat</a>';
    117117          unset($Table->Values[$Index]['Id']);
     
    161161        $Table->Table = '(SELECT * FROM `Backup` WHERE `Server` = '.$ServerId.')';
    162162        $Table->Definition['Items']['Id'] = array('Type' => 'Hidden', 'Caption' => 'Id', 'Default' => '');
     163        $Table->Definition['Items']['Lock'] = array('Type' => 'Hidden', 'Caption' => 'Zámek', 'Default' => '');
    163164        $Table->LoadValuesFromDatabase($this->Database);
    164165        $Table->Definition['Items']['Actions'] = array('Type' => 'String', 'Caption' => '', 'Default' => '');
    165166        foreach($Table->Values as $Index => $Value)
    166167        {
    167           $Table->Values[$Index]['Actions'] = '<a href="?Action=BackupDownload&amp;Id='.$Value['Id'].'">Stáhnout</a>';
    168           if($Server->Server['Lock'] == 0) $Table->Values[$Index]['Actions'] .= ' <a href="?Action=BackupRestore&amp;Id='.$Value['Id'].'">Obnovit</a>';
     168          if($Value['Lock'] == 0) $Table->Values[$Index]['Actions'] = '<a href="?Action=BackupDownload&amp;Id='.$Value['Id'].'">Stáhnout</a>';
     169          if(($Server->Server['Lock'] == 0) and ($Value['Lock'] == 0)) $Table->Values[$Index]['Actions'] .= ' <a href="?Action=BackupRestore&amp;Id='.$Value['Id'].'">Obnovit</a>';
    169170          unset($Table->Values[$Index]['Id']);
     171          unset($Table->Values[$Index]['Lock']);
    170172        }
    171173        $Output .= $Table->Show();
     
    216218      $Table = new Table('TaskList');
    217219      $Table->OnRow = array($this, 'ShowTaskListOnRow');
    218       $Table->Definition['Table'] = '(SELECT (UNIX_TIMESTAMP(TimeEnd) - UNIX_TIMESTAMP(TimeStart)) AS Duration, TimeCreate, Title, State FROM Task WHERE User='.$this->System->Modules['User']->User['Id'].' ORDER BY Id DESC)';
     220      $Table->Definition['Table'] = '(SELECT (COALESCE(UNIX_TIMESTAMP(TimeEnd), UNIX_TIMESTAMP(NOW())) - UNIX_TIMESTAMP(TimeStart)) AS Duration, TimeCreate, Title, State FROM Task WHERE User='.$this->System->Modules['User']->User['Id'].' ORDER BY Id DESC)';
    219221      $Table->LoadValuesFromDatabase($this->Database);
    220222      $Output .= $Table->Show();
     
    481483            $Form = new Form('NewServer', array());
    482484            $Form->LoadValuesFromForm();
    483             $this->Database->insert('Server', array('Name' => $Form->Values['Name'], 'Description' => $Form->Values['Description'], 'User' => $this->System->Modules['User']->User['Id'], 'Motd' => $Form->Values['Motd'], 'Homepage' => $Form->Values['Homepage'], 'Type' => $Form->Values['Type'], 'Database' => 1, 'NetworkPortWorldd' => $NewPortWorldd, 'NetworkPortRealmd' => $NewPortRealmd));
     485            $this->Database->insert('Server', array('Name' => $Form->Values['Name'], 'Description' => $Form->Values['Description'], 'User' => $this->System->Modules['User']->User['Id'], 'Motd' => $Form->Values['Motd'], 'Homepage' => $Form->Values['Homepage'], 'Type' => $Form->Values['Type'], 'Database' => 1, 'NetworkPortWorldd' => $NewPortWorldd, 'NetworkPortRealmd' => $NewPortRealmd, 'Lock' => 1));
    484486            $LastInsertId = $this->Database->insert_id;
    485487            $Server = new Server($this->Database, $LastInsertId);
    486             $Server->CreateDatabase();
    487             $Server->ImportDatabase(true);
    488             $Output .= $this->SystemMessage('Vytvoření serveru', 'Úloha načtení nové databáze zařazena do fronty');
     488            $Server->CreateDatabase();           
     489            $Output .= $this->SystemMessage('Vytvoření serveru', $Server->ImportDatabase(true));
    489490            $Output .= $this->ShowTaskList();
    490491            //$UserOptions->LoadValuesFromDatabase($this->System->Modules['User']->User['Id']);
  • trunk/www/server.php

    r34 r35  
    5858    $this->Lock();
    5959    $CommandList = array(
     60      'php www/shell.php ServerLock '.$this->Id,
     61    );
     62    if($Delete == true)
     63    {
     64      $CommandList = array_merge($CommandList, array(
     65        'mysql --silent --skip-column-names -u server'.$this->Id.' -pserver'.$this->Id.' server'.$this->Id.'_mangos -e "show tables" | gawk \'{print "drop table " $1 ";"}\' | mysql -u server'.$this->Id.' -pserver'.$this->Id.' server'.$this->Id.'_mangos',
     66        'mysql --silent --skip-column-names -u server'.$this->Id.' -pserver'.$this->Id.' server'.$this->Id.'_characters -e "show tables" | gawk \'{print "drop table " $1 ";"}\' | mysql -u server'.$this->Id.' -pserver'.$this->Id.' server'.$this->Id.'_characters',
     67      'mysql --silent --skip-column-names -u server'.$this->Id.' -pserver'.$this->Id.' server'.$this->Id.'_realmd -e "show tables" | gawk \'{print "drop table " $1 ";"}\' | mysql -u server'.$this->Id.' -pserver'.$this->Id.' server'.$this->Id.'_realmd',
     68      'mysql --silent --skip-column-names -u server'.$this->Id.' -pserver'.$this->Id.' server'.$this->Id.'_scriptdev2 -e "show tables" | gawk \'{print "drop table " $1 ";"}\' | mysql -u server'.$this->Id.' -pserver'.$this->Id.' server'.$this->Id.'_scriptdev2',
     69      ));
     70    }
     71    $CommandList = array_merge($CommandList, array(
    6072      'mysql --user=server'.$this->Id.' --password=server'.$this->Id.' server'.$this->Id.'_mangos < database/'.$this->Server['Database']['Id'].'/'.$this->Server['Database']['SourceFileName'],
    6173      'mysql --user=server'.$this->Id.' --password=server'.$this->Id.' server'.$this->Id.'_scriptdev2 < emulator/'.$this->Server['Database']['Emulator']['Id'].'/source/src/bindings/ScriptDev2/sql/scriptdev2_create_structure.sql',
     
    6476      'mysql --user=server'.$this->Id.' --password=server'.$this->Id.' server'.$this->Id.'_realmd < emulator/'.$this->Server['Database']['Emulator']['Id'].'/share/mangos/sql/realmd.sql',
    6577      'mysql --user=server'.$this->Id.' --password=server'.$this->Id.' server'.$this->Id.'_characters < emulator/'.$this->Server['Database']['Emulator']['Id'].'/share/mangos/sql/characters.sql',
    66     );
    67     if($Delete == true)
    68     {
    69       array_unshift($CommandList, 'mysql --silent --skip-column-names -u server'.$this->Id.' -pserver'.$this->Id.' server'.$this->Id.'_mangos -e "show tables" | gawk \'{print "drop table " $1 ";"}\' | mysql -u server'.$this->Id.' -pserver'.$this->Id.' server'.$this->Id.'_mangos');
    70       array_unshift($CommandList, 'mysql --silent --skip-column-names -u server'.$this->Id.' -pserver'.$this->Id.' server'.$this->Id.'_characters -e "show tables" | gawk \'{print "drop table " $1 ";"}\' | mysql -u server'.$this->Id.' -pserver'.$this->Id.' server'.$this->Id.'_characters');
    71       array_unshift($CommandList, 'mysql --silent --skip-column-names -u server'.$this->Id.' -pserver'.$this->Id.' server'.$this->Id.'_realmd -e "show tables" | gawk \'{print "drop table " $1 ";"}\' | mysql -u server'.$this->Id.' -pserver'.$this->Id.' server'.$this->Id.'_realmd');
    72       array_unshift($CommandList, 'mysql --silent --skip-column-names -u server'.$this->Id.' -pserver'.$this->Id.' server'.$this->Id.'_scriptdev2 -e "show tables" | gawk \'{print "drop table " $1 ";"}\' | mysql -u server'.$this->Id.' -pserver'.$this->Id.' server'.$this->Id.'_scriptdev2');
    73     }
     78      'php www/shell.php ServerDatabaseChange '.$this->Server['Database']['Id'],
     79      'php www/shell.php ServerUnLock '.$thisr->Id,
     80    ));   
    7481    $this->Task->Add('Inicializace databáze', $CommandList);
     82    return('Úloha načtení nové databáze zařazena do fronty.');
    7583  }
    7684 
     
    7987    $this->Lock();
    8088    $this->Task->Add('Start emulátoru', array(
     89      'php www/shell.php ServerLock '.$this->Id,
    8190      'screen -A -m -d -S server'.$this->Id.'-realmd emulator/'.$this->Server['Database']['Emulator']['Id'].'/bin/mangos-realmd -c server/'.$this->Id.'/etc/realmd.conf',
    8291      'screen -A -m -d -S server'.$this->Id.'-worldd server/'.$this->Id.'/bin/start.sh',
     92      'php www/shell.php ServerUnLock '.$this->Id,
    8393    ));
    8494    return('Požadavek na start serveru zařazen.');
     
    8999    $this->Lock();
    90100    $this->Task->Add('Zastavení emulátoru', array(
     101      'php www/shell.php ServerLock '.$this->Id,
    91102      'server/'.$this->Id.'/bin/stop.sh',
     103      'php www/shell.php ServerUnLock '.$this->Id,
    92104    ));
    93105    return('Požadavek na zastavení serveru zařazen.');
     
    283295   
    284296    // Do update
    285     $Commands = array();
     297    $Commands = array(
     298     'php www/shell.php ServerLock '.$this->Id,
     299    );
    286300    $DbResult = $this->Database->query('SELECT `Revision` FROM `Database` WHERE `Id` = '.$this->Server['Database']['Id']);
    287301    $DbRow = $DbResult->fetch_assoc();
     
    302316      }     
    303317    }
     318    $Commands = array_merge($Commands, array(
     319      'php www/shell.php ServerDatabaseChange '.$DatabaseId,
     320      'php www/shell.php ServerUnLock '.$this->Id,
     321    ));
     322
    304323    $this->Task->Add('Aktualizace databáze', $Commands);
    305324    $Output .= '<br />Úloha aktualizace serveru byla přidána do fronty.';
     
    316335    $this->Database->update('Server', 'Id='.$this->Id, array('Lock' => 0));
    317336  }
     337 
     338  function ChangeDatabaseId($Id)
     339  {
     340    $this->Database->update('Server', 'Id='.$this->Id, array('Database' => $Id));
     341    $this->SaveConfiguration();
     342  }
    318343}
    319344
  • trunk/www/shell.php

    r34 r35  
    33include('global.php');
    44
     5$Output = '';
    56if(count($_SERVER['argv']) > 1)
    67{
     
    1819    if((count($_SERVER['argv']) > 2) and is_numeric($_SERVER['argv'][2]))
    1920    {
    20       $Server = new Server($_SERVER['argv'][2]);
     21      $Server = new Server($Database, $_SERVER['argv'][2]);
    2122      $Server->Lock();
    2223    } else $Output = 'Jako druhý parameter je nutno zadat Id serveru.';
     
    2627    if((count($_SERVER['argv']) > 2) and is_numeric($_SERVER['argv'][2]))
    2728    {
    28       $Server = new Server($_SERVER['argv'][2]);
     29      $Server = new Server($Database, $_SERVER['argv'][2]);
    2930      $Server->UnLock();
    3031    } else $Output = 'Jako druhý parameter je nutno zadat Id serveru.';
     32  } else
     33  if($Command == 'EmulatorLock')
     34  {
     35    if((count($_SERVER['argv']) > 2) and is_numeric($_SERVER['argv'][2]))
     36    {
     37      $Emulator = new Emulator($Database, $_SERVER['argv'][2]);
     38      $Emulator->Lock();
     39    } else $Output = 'Jako druhý parameter je nutno zadat Id emulátoru.';
     40  } else
     41  if($Command == 'EmulatorUnLock')
     42  {
     43    if((count($_SERVER['argv']) > 2) and is_numeric($_SERVER['argv'][2]))
     44    {
     45      $Emulator = new Emulator($Database, $_SERVER['argv'][2]);
     46      $Emulator->UnLock();
     47    } else $Output = 'Jako druhý parameter je nutno zadat Id emulátoru.';
     48  } else
     49  if($Command == 'BackupLock')
     50  {
     51    if((count($_SERVER['argv']) > 2) and is_numeric($_SERVER['argv'][2]))
     52    {
     53      $Backup = new Backup($Database, $_SERVER['argv'][2]);
     54      $Backup->Lock();
     55    } else $Output = 'Jako druhý parameter je nutno zadat Id zálohy.';
     56  } else
     57  if($Command == 'BackupUnLock')
     58  {
     59    if((count($_SERVER['argv']) > 2) and is_numeric($_SERVER['argv'][2]))
     60    {
     61      $Backup = new Backup($Database, $_SERVER['argv'][2]);
     62      $Backup->UnLock();
     63    } else $Output = 'Jako druhý parameter je nutno zadat Id zálohy.';
    3164  } else
    3265  if($Command == 'TaskProcess')
    3366  {
    3467    $Task = new Task($Database);
    35     while(1)
     68    $Task->ProcessAllCycle();
     69  } else
     70  if($Command == 'ServerDatabaseChange')
     71  {
     72    if((count($_SERVER['argv']) > 2) and is_numeric($_SERVER['argv'][2]))
    3673    {
    37       $Task->ProcessAll();
    38       sleep(1);
    39     }  
     74      $Server = new Server($Database, $_SERVER['argv'][2]);
     75      $Server->ChangeDatabaseId($_SERVER['argv'][2]);
     76    } else $Output = 'Jako druhý parameter je nutno zadat Id serveru.';
    4077  } else
    4178    $Output = 'Neznámý příkaz '.$Command;
    42 } else $Output = 'Jako první parameter je nutno zadar povel.';
     79} else $Output = 'Jako první parameter je nutno zadat povel.';
    4380echo($Output);
    4481
  • trunk/www/task.php

    r34 r35  
    4040    }
    4141  }
     42 
     43  function ProcessAllCycle()
     44  {
     45    while(1)
     46    {
     47      $this->ProcessAll();
     48      sleep(1);
     49    } 
     50  }
    4251   
    4352  function Abort($Id)
Note: See TracChangeset for help on using the changeset viewer.