/**
  * Get the environment modifier (if any) which helps to switch the configuration environment
  *
  * @param string $appBase The base of the application we are dealing with
  *
  * @return string
  *
  * @throws \AppserverIo\Properties\PropertyFileNotFoundException
  * @throws \AppserverIo\Properties\PropertyFileParseException
  */
 public static function getEnvironmentModifier($appBase)
 {
     // check if we got the properties cached already, if not load them anew
     $properties = null;
     if (!is_null(self::$cachedProperties)) {
         $properties = self::$cachedProperties;
     } else {
         // load the properties from file
         $propertiesFile = DirectoryKeys::realpath(sprintf('%s/%s', $appBase, self::CONFIGURATION_FILE));
         // load the properties from the configuration file
         if (file_exists($propertiesFile)) {
             $properties = Properties::create()->load($propertiesFile);
         }
     }
     // load the properties from the configuration file
     $result = '';
     // get the actual property if it exists
     if (!is_null($properties) && $properties->exists(ConfigurationKeys::APP_ENVIRONMENT)) {
         $result = $properties->get(ConfigurationKeys::APP_ENVIRONMENT);
     }
     // ENV variable always wins
     if (defined(ConfigurationKeys::APP_ENVIRONMENT)) {
         $result = getenv(ConfigurationKeys::APP_ENVIRONMENT);
     }
     return $result;
 }
 /**
  * Creates a new naming context and add's it to the passed manager.
  *
  * @param \AppserverIo\Psr\Application\ManagerInterface $manager The manager to add the naming context to
  *
  * @return void
  */
 public static function visit(ManagerSettingsAwareInterface $manager)
 {
     // load the path to the web application
     $application = $manager->getApplication();
     $webappPath = $application->getWebappPath();
     // initialize the variable for the properties
     $properties = null;
     // load the configuration base directory
     if ($baseDirectory = $manager->getManagerSettings()->getBaseDirectory()) {
         // look for naming context properties in the manager's base directory
         $propertiesFile = DirectoryKeys::realpath(sprintf('%s/%s/%s', $webappPath, $baseDirectory, NamingContextFactory::CONFIGURATION_FILE));
         // load the properties from the configuration file
         if (file_exists($propertiesFile)) {
             $properties = Properties::create()->load($propertiesFile);
         }
     }
     // create the initial context instance
     $initialContext = new InitialContext($properties);
     $initialContext->injectApplication($application);
     // set the initial context in the manager
     $manager->injectInitialContext($initialContext);
 }
Example #3
0
$namingDirectory->createSubdirectory('php:env');
$namingDirectory->createSubdirectory('php:env/args');
$namingDirectory->createSubdirectory('php:global');
$namingDirectory->createSubdirectory('php:global/log');
$namingDirectory->createSubdirectory('php:services');
// create the default subdirectories
foreach (array_keys(ApplicationServer::$runlevels) as $runlevel) {
    $namingDirectory->createSubdirectory(sprintf('php:services/%s', $runlevel));
}
// bind the command line arguments to the naming directory
foreach ($arguments as $name => $value) {
    $namingDirectory->bind(sprintf('php:env/args/%s', $name), empty($value) ? true : $value);
}
// bind the current user to the naming directory
$namingDirectory->bind('php:env/currentUser', isset($_SERVER['SUDO_USER']) ? $_SERVER['SUDO_USER'] : get_current_user());
// bind the path to the default configuration and bootstrap filenames
$namingDirectory->bind('php:env/configurationFilename', DirectoryKeys::realpath($filename));
$namingDirectory->bind('php:env/bootstrapConfigurationFilename', DirectoryKeys::realpath($bootstrapFilename));
// add the storeage containers for the runlevels
$runlevels = new GenericStackable();
foreach (ApplicationServer::$runlevels as $runlevel) {
    $runlevels[$runlevel] = new GenericStackable();
}
// initialize and start the application server
$applicationServer = ApplicationServer::singleton($namingDirectory, $runlevels);
// we've to wait for shutdown
while ($applicationServer->keepRunning()) {
    sleep(1);
}
// wait until all threads have been stopped
$applicationServer->join();
 /**
  * Prepares filesystem to be sure that everything is on place as expected
  *
  * @return void
  * @throws \Exception Is thrown if a server directory can't be created
  */
 public function prepareFileSystem()
 {
     // load the directories
     $directories = $this->getDirectories();
     // load user and group from system configuration
     $user = $this->getSystemConfiguration()->getUser();
     $group = $this->getSystemConfiguration()->getGroup();
     // check if the necessary directories already exists, if not, create them
     foreach (DirectoryKeys::getServerDirectoryKeysToBeCreated() as $directoryKey) {
         // prepare the path to the directory to be created
         $toBeCreated = $this->realpath($directories[$directoryKey]);
         // prepare the directory name and check if the directory already exists
         if (is_dir($toBeCreated) === false) {
             // if not, try to create it
             if (mkdir($toBeCreated, 0755, true) === false) {
                 throw new \Exception(sprintf('Can\'t create necessary directory %s while starting application server', $toBeCreated));
             }
             // set user/group specified from the system configuration
             if ($this->setUserRights(new \SplFileInfo($toBeCreated), $user, $group) === false) {
                 throw new \Exception(sprintf('Can\'t switch user/group to %s/% for directory %s while starting application server', $user, $group, $toBeCreated));
             }
         }
     }
     // check if specific directories has to be cleaned up on startup
     foreach (DirectoryKeys::getServerDirectoryKeysToBeCleanedUp() as $directoryKey) {
         // prepare the path to the directory to be cleaned up
         $toBeCleanedUp = $this->realpath($directories[$directoryKey]);
         // if the directory exists, clean it up
         if (is_dir($toBeCleanedUp)) {
             $this->cleanUpDir(new \SplFileInfo($toBeCleanedUp));
         }
     }
     // check if needed files do exist and have the correct user rights
     $files = $this->getFiles();
     foreach (FileKeys::getServerFileKeysToBeCreated() as $fileKeys) {
         // prepare the path to the file to be created
         $toBeCreated = $this->realpath($files[$fileKeys]);
         // touch the file (will lead to its creation if it does not exist by now)
         if (touch($toBeCreated) === false) {
             throw new \Exception(sprintf('Can\'t create necessary file %s while starting application server', $toBeCreated));
         } else {
             chmod($toBeCreated, 0755);
         }
         // set user/group specified from the system configuration
         if ($this->setUserRight(new \SplFileInfo($toBeCreated), $user, $group) === false) {
             throw new \Exception(sprintf('Can\'t switch user/group to %s/% for file %s while starting application server', $user, $group, $toBeCreated));
         }
     }
 }
 /**
  * Makes the path an absolute path or returns null if passed path is empty.
  *
  * @param string $path A path to absolute
  *
  * @return string The absolute path
  */
 protected function makePathAbsolute($path = '')
 {
     if (empty($path) === false) {
         return DIRECTORY_SEPARATOR . trim(DirectoryKeys::realpath($path), DIRECTORY_SEPARATOR);
     }
 }
Example #6
0
 /**
  * Return a new sender for the message queue with the passed lookup name.
  *
  * @param string $lookupName The lookup name of the queue to return a sender for
  * @param string $sessionId  The session-ID to be passed to the queue session
  *
  * @return \AppserverIo\Messaging\QueueSender The sender instance
  */
 public function createSenderForQueue($lookupName, $sessionId = null)
 {
     // load the application name
     $application = $this->getApplication();
     $applicationName = $application->getName();
     $webappPath = $application->getWebappPath();
     // initialize the variable for the properties
     $properties = null;
     // load the configuration base directory
     if ($baseDirectory = $this->getManagerSettings()->getBaseDirectory()) {
         // look for naming context properties in the manager's base directory
         $propertiesFile = DirectoryKeys::realpath(sprintf('%s/%s/%s', $webappPath, $baseDirectory, QueueManagerSettingsInterface::CONFIGURATION_FILE));
         // load the properties from the configuration file
         if (file_exists($propertiesFile)) {
             $properties = Properties::create()->load($propertiesFile);
         }
     }
     // initialize and return the sender
     $queue = \AppserverIo\Messaging\MessageQueue::createQueue($lookupName);
     $connection = \AppserverIo\Messaging\QueueConnectionFactory::createQueueConnection($applicationName, $properties);
     $session = $connection->createQueueSession();
     return $session->createSender($queue);
 }