| 
						
						
						
					 | 
					@ -1,15 +1,11 @@ | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					<?php | 
					 | 
					 | 
					<?php | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					$version = 'dev'; | 
					 | 
					 | 
					$version = 'v1.2.0-rc2'; | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					require_once './src/Daemon.php'; | 
					 | 
					 | 
					require_once './src/Daemon.php'; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					require_once './src/Logger.php'; | 
					 | 
					 | 
					require_once './src/Logger.php'; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					require_once './src/Process.php'; | 
					 | 
					 | 
					require_once './src/Process.php'; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					if (in_array('--debug', $argv)) { // debug mode | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    logging::$logLevel = logging::DEBUG; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					} | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					$nginx = array( | 
					 | 
					 | 
					$nginx = array( | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    'name' => 'nginx', | 
					 | 
					 | 
					    'name' => 'nginx', | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    'command' => ['/usr/sbin/nginx'], | 
					 | 
					 | 
					    'command' => ['/usr/sbin/nginx'], | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -28,13 +24,26 @@ $vlmcsd = array( | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    'pidFile' => '/run/vlmcsd.pid', | 
					 | 
					 | 
					    'pidFile' => '/run/vlmcsd.pid', | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					); | 
					 | 
					 | 
					); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					logging::info('Loading kms-server (' . $version . ')'); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					declare(ticks = 1); | 
					 | 
					 | 
					declare(ticks = 1); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					pcntl_signal(SIGCHLD, function() { // receive SIGCHLD signal | 
					 | 
					 | 
					pcntl_signal(SIGCHLD, function() { // receive SIGCHLD signal | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    pcntl_wait($status, WNOHANG); // avoid zombie process | 
					 | 
					 | 
					    pcntl_wait($status, WNOHANG); // avoid zombie process | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					}); | 
					 | 
					 | 
					}); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					pcntl_signal(SIGTERM, function() { // receive SIGTERM signal | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					    global $nginx, $phpFpm, $vlmcsd; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					    logging::info('Get SIGTERM -> exit'); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					    subExit($nginx['pidFile'], $phpFpm['pidFile'], $vlmcsd['pidFile']); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					}); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					pcntl_signal(SIGINT, function() { // receive SIGINT signal | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					    global $nginx, $phpFpm, $vlmcsd; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					    logging::info('Get SIGINT -> exit'); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					    subExit($nginx['pidFile'], $phpFpm['pidFile'], $vlmcsd['pidFile']); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					}); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					if (in_array('--debug', $argv)) { // enter debug mode | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					    logging::$logLevel = logging::DEBUG; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					} | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					logging::info('Loading kms-server (' . $version . ')'); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					new Process($nginx['command']); | 
					 | 
					 | 
					new Process($nginx['command']); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					logging::info('Start nginx server...OK'); | 
					 | 
					 | 
					logging::info('Start nginx server...OK'); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					new Process($phpFpm['command']); | 
					 | 
					 | 
					new Process($phpFpm['command']); | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -42,9 +51,11 @@ logging::info('Start php-fpm server...OK'); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					new Process($vlmcsd['command']); | 
					 | 
					 | 
					new Process($vlmcsd['command']); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					logging::info('Start vlmcsd server...OK'); | 
					 | 
					 | 
					logging::info('Start vlmcsd server...OK'); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					logging::info('Enter the daemon process'); | 
					 | 
					 | 
					logging::info('Enter daemon process'); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					while (true) { | 
					 | 
					 | 
					while (true) { // start daemon | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					    msSleep(5000); // sleep 5s | 
					 | 
					 | 
					    for ($i = 0; $i < 500; $i++) { // sleep 5s | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        msDelay(10); // return main loop every 10ms | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    daemon($nginx); | 
					 | 
					 | 
					    daemon($nginx); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    daemon($phpFpm); | 
					 | 
					 | 
					    daemon($phpFpm); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    daemon($vlmcsd); | 
					 | 
					 | 
					    daemon($vlmcsd); | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					
  |