diff --git a/classes/Jail.php b/classes/Jail.php index 47ff472..137bc21 100644 --- a/classes/Jail.php +++ b/classes/Jail.php @@ -311,11 +311,22 @@ public function Start() { exec("/usr/local/bin/sudo /bin/mkdir -p '{$this->path}/{$mount->target}'"); exec("{$command} {$mount->source} {$this->path}/{$mount->target}"); + + watchdog("jailadmin", "Mounted @mount in jail @jail", array( + "@mount" => $mount->target, + "@jail" => $this->name, + ), WATCHDOG_INFO); } - foreach ($this->services as $service) + foreach ($this->services as $service) { exec("/usr/local/bin/sudo /usr/sbin/jexec \"{$this->name}\" {$service->path} start"); + watchdog("jailadmin", "Service @service started in jail @jail", array( + "@service" => $service, + "@jail" => $this->name, + ), WATCHDOG_INFO); + } + exec("/usr/local/bin/sudo /usr/sbin/jexec \"{$this->name}\" /bin/sh /etc/rc"); foreach ($this->network as $n) @@ -324,6 +335,8 @@ public function Start() { exec("/usr/local/bin/sudo /usr/sbin/jexec \"{$this->name}\" /sbin/ifconfig lo0 inet 127.0.0.1"); + watchdog("jailadmin", "Jail @jail started", array("@jail" => $this->name), WATCHDOG_INFO); + return TRUE; } @@ -346,6 +359,8 @@ public function Stop() { foreach ($this->network as $n) $n->BringOffline(); + watchdog("jailadmin", "Jail @jail stopped", array("@jail" => $this->name), WATCHDOG_INFO); + return TRUE; } @@ -403,6 +418,11 @@ public function Snapshot($base = '') { exec("/usr/local/bin/sudo /sbin/zfs snapshot {$dataset}@{$date}"); + watchdog("jailadmin", "Jail @jail snapshotted (@snapshot)", array( + "@jail" => $this->name, + "@snapshot" => "{$dataset}@{$date}", + ), WATCHDOG_INFO); + return "{$dataset}@{$date}"; } @@ -424,7 +444,9 @@ public function UpgradeWorld() { if ($this->Snapshot() == FALSE) return FALSE; + watchdog("jailadmin", "Jail @jail world install started", array("@jail" => $this->name), WATCHDOG_INFO); exec("cd /usr/src; /usr/local/bin/sudo make installworld DESTDIR={$this->path} > \"/tmp/upgrade-{$this->name}-{$date}.log\" 2>&1"); + watchdog("jailadmin", "Jail @jail world install finished", array("@jail" => $this->name), WATCHDOG_INFO); return TRUE; } @@ -435,6 +457,11 @@ public function CreateNewBE($name, $base='') { exec("/usr/local/bin/sudo /sbin/zfs clone -o jailadmin:be_active=false {$snap} {$this->dataset}/ROOT/{$name}"); + watchdog("jailadmin", "Jail @jail BE @be created", array( + "@jail" => $this->name, + "@be" => $name + ), WATCHDOG_INFO); + return TRUE; } @@ -461,6 +488,11 @@ public function ActivateBE($name) { $this->load_boot_environments(); $this->path = $this->GetActiveBE()["mountpoint"]; + watchdog("jailadmin", "Jail @jail BE @be activated", array( + "@jail" => $this->name, + "@be" => $name, + ), WATCHDOG_INFO); + return TRUE; } @@ -486,6 +518,11 @@ public function DeactivateBE($name) { exec("/usr/local/bin/sudo /sbin/zfs set jailadmin:be_active=false {$this->dataset}/ROOT/{$name}"); + watchdog("jailadmin", "Jail @jail BE @be deactivated", array( + "@jail" => $this->name, + "@be" => $name, + ), WATCHDOG_INFO); + return TRUE; } @@ -498,6 +535,12 @@ public function DeleteBE($name) { } exec("/usr/local/bin/sudo /sbin/zfs destroy -r {$be["dataset"]}"); + + watchdog("jailadmin", "Jail @jail BE @be deleted", array( + "@jail" => $this->name, + "@be" => $name, + ), WATCHDOG_INFO); + return TRUE; } } @@ -535,6 +578,8 @@ public function Create($template='', $usebe=FALSE) { 'dataset' => $this->dataset, 'hostname' => $this->hostname, ))->execute(); + + watchdog("jailadmin", "Jail @jail created", array("@jail" => $this->name), WATCHDOG_INFO); } public function Delete($destroy) { @@ -560,6 +605,8 @@ public function Delete($destroy) { if ($destroy) exec("/usr/local/bin/sudo /sbin/zfs destroy -r {$this->dataset}"); + + watchdog("jailadmin", "Jail @jail deleted", array("@jail" => $this->name), WATCHDOG_INFO); } public function Persist() { diff --git a/classes/Network.php b/classes/Network.php index 42fe849..8d3243a 100644 --- a/classes/Network.php +++ b/classes/Network.php @@ -81,6 +81,8 @@ public function BringOnline() { foreach ($this->physicals as $physical) exec("/usr/local/bin/sudo /sbin/ifconfig {$this->device} addm {$physical}"); + watchdog("jailadmin", "Network @network online", array("@network" => $this->name), WATCHDOG_INFO); + return TRUE; } @@ -90,6 +92,8 @@ public function BringOffline() { exec("/usr/local/bin/sudo /sbin/ifconfig {$this->device} destroy"); + watchdog("jailadmin", "Network @network offline", array("@network" => $this->name), WATCHDOG_INFO); + return TRUE; } diff --git a/classes/NetworkDevice.php b/classes/NetworkDevice.php index cca5b1b..59f558d 100644 --- a/classes/NetworkDevice.php +++ b/classes/NetworkDevice.php @@ -48,6 +48,11 @@ public function BringHostOnline() { exec("/usr/local/bin/sudo /sbin/ifconfig {$this->device}a up"); + watchdog("jailadmin", "VNIC @vnic created on host for jail @jail", array( + "@vnic" => $this->device, + "@jail" => $this->jail->name, + ), WATCHDOG_INFO); + return TRUE; } @@ -70,6 +75,11 @@ public function BringGuestOnline() { if ($this->dhcp) exec("/usr/local/bin/sudo /usr/sbin/jexec \"{$this->jail->name}\" /sbin/dhclient {$this->device}b > /dev/null 2>&1 &"); + watchdog("jailadmin", "VNIC @vnic brought online on guest for jail @jail", array( + "@vnic" => $this->device, + "@jail" => $this->jail->name, + ), WATCHDOG_INFO); + return TRUE; } @@ -79,6 +89,8 @@ public function BringOffline() { exec("/usr/local/bin/sudo /sbin/ifconfig {$this->device}a destroy"); + watchdog("jailadmin", "VNIC @vnic brought offline", array("@vnic" => $this->device), WATCHDOG_INFO); + return TRUE; } @@ -171,6 +183,11 @@ public function Create() { 'dhcp' => ($this->dhcp) ? 1 : 0, ))->execute(); + watchdog("jailadmin", "VNIC @vnic assigned to jail @jail", array( + "@vnic" => $this->device, + "@jail" => $this->jail->name, + ), WATCHDOG_INFO); + return TRUE; } @@ -183,5 +200,10 @@ public function Delete() { db_delete('jailadmin_epair_aliases') ->condition('device', $this->device) ->execute(); + + watchdog("jailadmin", "VNIC @vnic (assigned to jail @jail) deleted", array( + "@vnic" => $this->name, + "@jail" => $this->jail->name, + ), WATCHDOG_INFO); } } diff --git a/jailadmin.drush.inc b/jailadmin.drush.inc index 80003a3..95479b4 100644 --- a/jailadmin.drush.inc +++ b/jailadmin.drush.inc @@ -8,6 +8,10 @@ require_once('classes/NetworkDevice.php'); require_once('classes/Jail.php'); function jailadmin_drush_command() { + global $user; + + $user = user_load(1); + return array( 'start' => array( 'description' => 'Boot up a jail',