public function main() { // load the interval we want to scan the directory $interval = $this->getInterval(); // load the deployment directory $directory = $this->getDirectory(); // log the configured deployment directory $this->getSystemLogger()->debug(sprintf('Start watching directory %s', $directory)); // load the deployment flag $deploymentFlag = $this->getDeploymentFlag(); // wait until the server has been successfully started at least once while ($this->getLastSuccessfullyDeployment($deploymentFlag) === 0) { $this->getSystemLogger()->debug(sprintf('%s is waiting for first successful deployment ...', __CLASS__)); sleep($interval); } // load the initial hash value of the deployment directory $oldHash = $this->getDirectoryHash($directory); // watch the deployment directory while (true) { // load the actual hash value for the deployment directory $newHash = $this->getDirectoryHash($directory); // log the found directory hash value $this->getSystemLogger()->debug(sprintf("Comparing directory hash %s (previous) : %s (actual)", $oldHash, $newHash)); // compare the hash values, if not equal restart the appserver if ($oldHash !== $newHash) { // log that changes have been found $this->getSystemLogger()->debug(sprintf('Found changes in directory %s', $directory)); // log the UNIX timestamp of the last successful deployment $lastSuccessfullDeployment = $this->getLastSuccessfullyDeployment($deploymentFlag); // restart the appserver $this->restart(); // wait until deployment has been finished while ($lastSuccessfullDeployment == $this->getLastSuccessfullyDeployment($deploymentFlag)) { sleep($interval); } // set the directory new hash value after successful deployment $oldHash = $this->getDirectoryHash($directory); // log that the appserver has been restarted successful $this->getSystemLogger()->debug('appserver has successfully been restarted'); } else { // if no changes has been found, wait a second sleep($interval); } } }