@@ -783,65 +783,85 @@ return baseclass.extend({
783783 const logFile = log ; // file for reading: '/tmp/zapret_pkg_install.log'
784784 const rcFile = logFile + '.rc' ;
785785 try {
786- await fs . exec ( '/bin/busybox' , [ 'rm' , '-f' , logFile + '*' ] , null ) ;
787- appendLog ( 'Output file cleared!' ) ;
786+ await fs . exec ( '/bin/busybox' , [ 'rm' , '-f' , logFile ] , null ) ;
787+ await fs . exec ( '/bin/busybox' , [ 'rm' , '-f' , rcFile ] , null ) ;
788+ //appendLog('Output file cleared!');
788789 } catch ( e ) {
789790 return callback . call ( ctx , 500 , 'ERROR: Failed to clear output file' ) ;
790791 }
791- let processStarted = false ;
792+ let execRetCode = - 1 ;
792793 let opt_list = [ logFile ] ;
793794 try {
794795 opt_list . push ( ...cmd ) ;
795796 //console.log('script-exec.sh ... '+JSON.stringify(opt_list));
796- let proc = new Promise ( ( resolve ) => {
797- fs . exec ( this . appDir + '/script-exec.sh' , opt_list , null )
798- . then ( ( ) => { resolve ( ) ; } )
799- . catch ( ( ) => { resolve ( ) ; } ) ;
797+ fs . exec ( this . appDir + '/script-exec.sh' , opt_list , null )
798+ . then ( ( res ) => {
799+ if ( execRetCode < 0 ) {
800+ execRetCode = res . code ;
801+ fixLogEnd ( ) ;
802+ if ( res . code == 0 ) {
803+ appendLog ( 'Process started....' ) ;
804+ } else {
805+ if ( res . stdout ) appendLog ( res . stdout ) ;
806+ appendLog ( 'ERROR: process not executed! ret_code = ' + res . code ) ;
807+ }
808+ }
809+ } ) . catch ( ( e ) => {
810+ console . log ( 'ERROR: execAndRead: process not exec: ' + e . message ) ;
811+ execRetCode = - 100 ;
800812 } ) ;
801813 } catch ( e ) {
802814 return callback . call ( ctx , 520 , 'ERROR: Failed on execute process: ' + e . message ) ;
803815 }
804816 let lastLen = 0 ;
805- let retCode = - 1 ;
817+ let retCode = - 2 ; // rc file not found
806818 return await new Promise ( async ( resolve , reject ) => {
807819 let ticks = 0 ;
808820 async function epoll ( )
809821 {
810822 ticks += 1 ;
811823 try {
824+ if ( retCode < 0 ) {
825+ let rc = await fs . exec ( '/bin/cat' , [ rcFile ] , null ) ;
826+ if ( rc . code != 0 ) {
827+ if ( ticks >= 2 ) {
828+ console . log ( 'ERROR: execAndRead: ' + JSON . stringify ( opt_list ) ) ;
829+ fixLogEnd ( ) ;
830+ resolve ( callback . call ( ctx , 542 , 'ERROR: Failed on read process rc-file: code = ' + rc . code ) ) ;
831+ return ;
832+ }
833+ console . log ( 'WARN: execAndRead: read rc-file res.code = ' + rc . code ) ;
834+ }
835+ if ( rc . code == 0 ) {
836+ if ( rc . stdout ) {
837+ retCode = parseInt ( rc . stdout . trim ( ) , 10 ) ;
838+ } else {
839+ retCode = - 1 ; // rc file exists, but empty
840+ }
841+ }
842+ if ( retCode <= - 2 ) {
843+ setTimeout ( epoll , 500 ) ;
844+ return ; // skip first step with error
845+ }
846+ }
812847 let res = await fs . exec ( '/bin/cat' , [ logFile ] , null ) ;
813848 if ( res . code != 0 ) {
814- if ( ticks > 1 ) {
815- console . log ( 'ERROR: execAndRead: ' + JSON . stringify ( opt_list ) ) ;
816- resolve ( callback . call ( ctx , 541 , 'ERROR: Failed on read process log: code = ' + res . code ) ) ;
817- return ;
818- }
819- setTimeout ( epoll , 500 ) ;
820- return ; // skip first step with error
849+ fixLogEnd ( ) ;
850+ resolve ( callback . call ( ctx , 546 , 'ERROR: Failed on read process log: code = ' + res . code ) ) ;
851+ return ;
821852 }
822- if ( ! processStarted ) {
853+ if ( execRetCode < 0 ) {
854+ execRetCode = 9999 ;
823855 appendLog ( 'Process started...' ) ;
824- processStarted = true ;
825856 }
826- if ( res . stdout && res . stdout . length > lastLen ) {
857+ if ( res . code == 0 && res . stdout && res . stdout . length > lastLen ) {
827858 let log = res . stdout . slice ( lastLen ) ;
828859 hide_rows . forEach ( re => {
829860 log = log . replace ( re , '' ) ;
830861 } ) ;
831862 appendLog ( log , '' ) ;
832863 lastLen = res . stdout . length ;
833864 }
834- if ( retCode < 0 ) {
835- let rc = await fs . exec ( '/bin/cat' , [ rcFile ] , null ) ;
836- if ( rc . code != 0 ) {
837- fixLogEnd ( ) ;
838- resolve ( callback . call ( ctx , 545 , 'ERROR: cannot read file "' + rcFile + '"' ) ) ;
839- return ;
840- }
841- if ( rc . stdout ) {
842- retCode = parseInt ( rc . stdout . trim ( ) , 10 ) ;
843- }
844- }
845865 if ( retCode >= 0 ) {
846866 fixLogEnd ( ) ;
847867 if ( retCode == 0 && res . stdout ) {
0 commit comments