fwrite( $etree.PHP_EOL ); $f = null; /* [3] Get the list of daemons (features) =========================================================*/ $feature = []; $f = new SplFileObject(ETREE_CONF, 'r'); while( !$f->eof() ){ /* (1) Try to parse each line */ $etree = trim($f->fgets(), "\n"); /* (2) Manage error */ if( is_null($etree) || strlen($etree) == 0 ) continue; /* (3) Add entry to log */ $feature[] = $etree; } $f = null; /* [4] Remove features' entries =========================================================*/ /* (0) We are done if @sync */ if( $sync ){ slog('Post-sync deployment -> no history truncate', "$FEATURE:deploy", 'update'); return 0; } if( isset($arr_r['saved']) && is_array($arr_r['saved']) ){ foreach($arr_r['saved'] as $feat_name=>$count){ /* (2) Check history count */ if( !is_numeric($count) ){ slog("No \'history\' found for '$feat_name' in response file", "$FEATURE:deploy", 'update'); return 127; } /* (3) Fetch number of entries */ $saved = intval($count); $saved = $saved < 0 ? 0 : $saved; // prevent negative /* (4) Truncate the log file */ $truncated = syscall(SOURCE_DIR."/lib/file/truncate $feat_name {$saved}"); /* (5) Manage error */ if( $truncated === false ){ slog('History cannot be truncated', "$FEATURE:deploy", 'update'); return 127; } slog("History '$feat_name' succesfully truncated", "$FEATURE:deploy", 'update'); } } /* [5] Launch deploy script for each feature =========================================================*/ /* (1) For each feature */ foreach($feature as $feat_name){ /* (2) Check if specific data in response */ if( !isset($arr_r['feature'][$feat_name]) ) continue; /* (3) Check for feature deploy script */ if( !file_exists(SOURCE_DIR."/feature/$feat_name/deploy") ) continue; /* (4) Write useful exclusive data to tmp file */ file_put_contents(TMP_DIR."/$feat_name", json_encode($arr_r['feature'][$feat_name])); /* (4) Execute deploy script */ $sync_suffix = $sync ? ' sync' : ''; syscall(SOURCE_DIR."/feature/$feat_name/deploy$sync"); } return 0; } /* Manage sync vs. sync */ $is_sync = false; if( $argc > 1 && $argv[1] == 'sync' ) $is_sync = true; $exec = api_deploy($is_sync); if( $exec == 0 ) slog('Success', 'api:deploy', 'update'); else slog('Failure', 'api:deploy', 'update'); echo $exec; die($exec); ?>