| 1 | <?php
|
|---|
| 2 |
|
|---|
| 3 | // class to control vps server
|
|---|
| 4 | // Date: 2012-06-23
|
|---|
| 5 |
|
|---|
| 6 | /*
|
|---|
| 7 | vzctl [flags] create CTID --parameter value [...]
|
|---|
| 8 | vzctl [flags] start CTID [--wait] [--force]
|
|---|
| 9 | vzctl [flags] stop CTID [--fast]
|
|---|
| 10 | vzctl [flags] restart CTID [--wait] [--force] [--fast]
|
|---|
| 11 | vzctl [flags] chkpnt | restore [--dumpfile name]
|
|---|
| 12 | vzctl [flags] snapshot [--id uuid] [--name name] [--description desc] [--skip-suspend]
|
|---|
| 13 | vzctl [flags] snapshot-switch | snapshot-delete --id uuid
|
|---|
| 14 | vzctl [flags] snapshot-list
|
|---|
| 15 | vzctl [flags] set CTID --parameter value [...] [--save] [--force] [--reset_ub] [--setmode restart|ignore]
|
|---|
| 16 | vzctl [flags] destroy | delete | mount | umount | status | quotaon | quotaoff | quotainit CTID
|
|---|
| 17 | vzctl [flags] console CTID [ttynum]
|
|---|
| 18 | vzctl [flags] convert CTID [--layout ploop[:{expanded|plain|raw}]]
|
|---|
| 19 | vzctl [flags] exec | exec2 CTID command [arg ...]
|
|---|
| 20 | vzctl [flags] enter CTID [--exec command [arg ...]]
|
|---|
| 21 | vzctl [flags] runscript CTID script
|
|---|
| 22 | vzctl --help | --version
|
|---|
| 23 | */
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 | class Server
|
|---|
| 29 | {
|
|---|
| 30 | protected $Id = -1;
|
|---|
| 31 | public $LastReturn = -1;
|
|---|
| 32 | private $LogFile = '/var/log/'; //vps.ID.log
|
|---|
| 33 |
|
|---|
| 34 | function __construct($Id)
|
|---|
| 35 | {
|
|---|
| 36 | $this->Id = $Id;
|
|---|
| 37 | $this->LogFile = $this->LogFile.'.'.$this->Id.'.log';
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | function create()
|
|---|
| 41 | {
|
|---|
| 42 | exec('vzctl create '.$this->Id.' 1> '.$this->LogFile,$output,$this->LastReturn);
|
|---|
| 43 | return $this->LastReturn;
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | function start()
|
|---|
| 47 | {
|
|---|
| 48 | exec('vzctl start '.$this->Id.' 1> '.$this->LogFile,$output,$this->LastReturn);
|
|---|
| 49 | return $this->LastReturn;
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | function stop()
|
|---|
| 53 | {
|
|---|
| 54 | exec('vzctl stop '.$this->Id.' 1> '.$this->LogFile,$output,$this->LastReturn);
|
|---|
| 55 | return $this->LastReturn;
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | function restart()
|
|---|
| 59 | {
|
|---|
| 60 | exec('vzctl restart '.$this->Id.' 1> '.$this->LogFile,$output,$this->LastReturn);
|
|---|
| 61 | return $this->LastReturn;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | function destroy()
|
|---|
| 65 | {
|
|---|
| 66 | exec('vzctl destroy '.$this->Id.' 1> '.$this->LogFile,$output,$this->LastReturn);
|
|---|
| 67 | return $this->LastReturn;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 | function exec($command)
|
|---|
| 72 | {
|
|---|
| 73 | exec('vzctl create '.$this->Id.' '.$command.' 1> '.$this->LogFile,$output,$this->LastReturn);
|
|---|
| 74 | return $this->LastReturn;
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | function GetId()
|
|---|
| 78 | {
|
|---|
| 79 | return $this->Id;
|
|---|
| 80 | }
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | ?>
|
|---|