From 54368eb25ab0fc9d3bc84e0b54d010677b48af03 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 9 May 2017 11:47:16 +0200 Subject: [PATCH] deploy log management --- lib/api/source/deploy.php | 46 ++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/lib/api/source/deploy.php b/lib/api/source/deploy.php index 7ff7ddf..bb847c6 100755 --- a/lib/api/source/deploy.php +++ b/lib/api/source/deploy.php @@ -10,22 +10,28 @@ $file_r = @file_get_contents(TMP_DIR.'/api.response'); /* (2) Check response */ - if( $file_r === false ) + if( $file_r === false ){ + slog('Cannot find api.response file', 'api:deploy', 'update'); return 127; + } /* (3) Try to parse response */ $arr_r = json_decode($file_r, true); /* (4) Check parse error */ - if( is_null($arr_r) ) + if( is_null($arr_r) ){ + slog('Cannot parse api.response file', 'api:deploy', 'update'); return 127; + } /* [2] Get system states (global_state) =========================================================*/ /* (1) Check data */ - if( !isset($arr_r['states']) || !is_array($arr_r['states']) ) + if( !isset($arr_r['states']) || !is_array($arr_r['states']) ){ + slog('No \'states\' found in api.response file', 'api:deploy', 'update'); return 127; + } /* (2) Reset file */ file_put_contents(STATES_CONF, ''); @@ -47,8 +53,10 @@ /* [3] Get chip list (chips) =========================================================*/ /* (1) Check data */ - if( !isset($arr_r['chips']) || !is_array($arr_r['chips']) ) + if( !isset($arr_r['chips']) || !is_array($arr_r['chips']) ){ + slog('No \'chips\' found in api.response file', 'api:deploy', 'update'); return 127; + } /* (2) Reset file */ file_put_contents(CHIPS_CONF, ''); @@ -71,8 +79,10 @@ /* [4] Get auth list (permissions) =========================================================*/ /* (1) Check data */ - if( !isset($arr_r['permissions']) || !is_array($arr_r['permissions']) ) + if( !isset($arr_r['permissions']) || !is_array($arr_r['permissions']) ){ + slog('No \'permissions\' found in api.response file', 'api:deploy', 'update'); return 127; + } /* (2) Reset file */ file_put_contents(AUTH_CONF, ''); @@ -95,8 +105,10 @@ /* [5] Get action list (with timeout) =========================================================*/ /* (1) Check data */ - if( !isset($arr_r['actions']) || !is_array($arr_r['actions']) ) + if( !isset($arr_r['actions']) || !is_array($arr_r['actions']) ){ + slog('No \'actions\' found in api.response file', 'api:deploy', 'update'); return 127; + } /* (2) Reset file */ file_put_contents(ACTIONS_CONF, ''); @@ -122,16 +134,22 @@ /* [6] Remove history entries =========================================================*/ /* (0) We are done if @init */ - if( $init ) + if( $init ){ + slog('Post-init deployment -> no history truncate', 'api:deploy', 'update'); return 0; + } /* (1) Check history entries count */ - if( !isset($arr_r['saved']) || !is_array($arr_r['saved']) ) + if( !isset($arr_r['saved']) || !is_array($arr_r['saved']) ){ + slog('No \'saved\' found in api.response file', 'api:deploy', 'update'); return 127; + } /* (2) Check history count */ - if( !isset($arr_r['saved']['history']) || !is_numeric($arr_r['saved']['history']) ) + if( !isset($arr_r['saved']['history']) || !is_numeric($arr_r['saved']['history']) ){ + slog('No \'actions\'.\'history\' found in api.response file', 'api:deploy', 'update'); return 127; + } /* (3) Fetch number of entries */ $saved = intval($arr_r['saved']['history']); @@ -142,10 +160,13 @@ $truncated = syscall(SOURCE_DIR."/lib/file/truncate mfrc522 {$saved}"); /* (5) Manage error */ - if( $truncated === false ) + if( $truncated === false ){ + slog('History Succesfully truncated', 'api:deploy', 'update'); return 127; + } + slog('History Succesfully truncated', 'api:deploy', 'update'); return 0; } @@ -157,6 +178,11 @@ $exec = api_deploy($is_init); + if( $exec == 0 ) + slog('Deployment successfully achieved', 'main', 'update'); + else + slog('Deployment failed', 'main', 'update'); + echo $exec; die($exec);