예제 #1
0
 public function init()
 {
     $req = $this;
     $this->sleep(1, true);
     FS::readfile('/etc/filesystems', function ($file, $data) use($req) {
         $req->fileData = $data;
         $req->wakeup();
     });
 }
예제 #2
0
 /**
  * Called when worker is going to update configuration.
  * @return void
  */
 public function onConfigUpdated()
 {
     parent::onConfigUpdated();
     $app = $this;
     FS::readfile($this->config->file->value, function ($file, $data) use($app) {
         $app->policyData = $data;
         $app->enable();
     });
 }
예제 #3
0
 public function applyConfig()
 {
     parent::applyConfig();
     $pool = $this;
     if (!isset($this->preloading)) {
         $this->preloading = new ComplexJob();
     }
     $job = $this->preloading;
     $job->addJob('resolvfile', function ($jobname, $job) use($pool) {
         FS::readfile($pool->config->resolvfile->value, function ($file, $data) use($pool, $job, $jobname) {
             if ($file) {
                 preg_match_all('~nameserver ([^\\r\\n;]+)~', $data, $m);
                 foreach ($m[1] as $s) {
                     $pool->addServer($s);
                 }
             }
             $job->setResult($jobname);
         });
     });
     $job->addJob('hostsfile', function ($jobname, $job) use($pool) {
         FS::readfile($pool->config->hostsfile->value, function ($file, $data) use($pool, $job, $jobname) {
             if ($file) {
                 preg_match_all('~^(\\S+)\\s+([^\\r\\n]+)\\s*~m', $data, $m, PREG_SET_ORDER);
                 $pool->hosts = array();
                 foreach ($m as $h) {
                     $hosts = preg_split('~\\s+~', $h[2]);
                     $ip = $h[1];
                     foreach ($hosts as $host) {
                         $host = rtrim($host, '.') . '.';
                         $pool->hosts[$host] = $ip;
                     }
                 }
             }
             $job->setResult($jobname);
         });
     });
     $job();
 }