@@ -19,24 +19,29 @@ var promise_utils = require('../util/promise_utils');
19
19
var os_utils = require ( '../util/os_util' ) ;
20
20
var config = require ( '../../config.js' ) ;
21
21
22
- var TMP_WORK_DIR = '/tmp/diag' ;
22
+ var is_windows = ( process . platform === "win32" ) ;
23
+
24
+ var TMP_WORK_DIR = is_windows ? process . env . ProgramData + '/diag' : '/tmp/diag' ;
23
25
24
26
function collect_basic_diagnostics ( limit_logs_size ) {
25
27
return P . fcall ( function ( ) {
26
- return promise_utils . promised_spawn ( 'rm' , [ '-rf' , TMP_WORK_DIR ] , process . cwd ( ) , true ) ;
28
+ return promise_utils . folder_delete ( TMP_WORK_DIR ) ;
29
+ //return promise_utils.promised_spawn('rm', ['-rf', TMP_WORK_DIR], process.cwd(), true);
27
30
} )
28
31
. then ( function ( ) {
29
- return promise_utils . promised_spawn ( 'rm' , [ '-rf' , process . cwd ( ) + '/build/public/diagnose.tgz' ] , process . cwd ( ) , true ) ;
32
+ return promise_utils . file_delete ( process . cwd ( ) + '/build/public/diagnose.tgz' ) ;
33
+ //return promise_utils.promised_spawn('rm', ['-rf', process.cwd() + '/build/public/diagnose.tgz'], process.cwd(), true);
30
34
} )
31
35
. then ( function ( ) {
36
+ console . log ( 'creating ' , TMP_WORK_DIR ) ;
32
37
return mkdirp . sync ( TMP_WORK_DIR ) ;
33
38
} )
34
39
. then ( function ( ) {
35
40
if ( fs . existsSync ( process . cwd ( ) + '/logs' ) ) {
36
- if ( limit_logs_size ) {
41
+ if ( limit_logs_size ) {
37
42
//will take only noobaa.log and the first 9 zipped logs
38
- return promise_utils . full_dir_copy ( process . cwd ( ) + '/logs' , TMP_WORK_DIR , 'noobaa?[1-9][0-9].log.gz' ) ;
39
- } else {
43
+ return promise_utils . full_dir_copy ( process . cwd ( ) + '/logs' , TMP_WORK_DIR , 'noobaa?[1-9][0-9].log.gz' ) ;
44
+ } else {
40
45
return promise_utils . full_dir_copy ( process . cwd ( ) + '/logs' , TMP_WORK_DIR ) ;
41
46
}
42
47
} else {
@@ -45,13 +50,15 @@ function collect_basic_diagnostics(limit_logs_size) {
45
50
} )
46
51
. then ( function ( ) {
47
52
if ( fs . existsSync ( '/var/log/noobaa_local_service.log' ) ) {
48
- return promise_utils . promised_spawn ( 'cp' , [ '-f' , '/var/log/noobaa_local_service.log' , TMP_WORK_DIR ] , process . cwd ( ) ) ;
53
+ return promise_utils . file_copy ( '/var/log/noobaa_local_service.log' , TMP_WORK_DIR ) ;
54
+ //return promise_utils.promised_spawn('cp', ['-f', '/var/log/noobaa_local_service.log', TMP_WORK_DIR], process.cwd());
49
55
} else {
50
56
return ;
51
57
}
52
58
} )
53
59
. then ( function ( ) {
54
- return promise_utils . promised_spawn ( 'cp' , [ '-f' , process . cwd ( ) + '/package.json' , TMP_WORK_DIR ] , process . cwd ( ) ) ;
60
+ return promise_utils . file_copy ( process . cwd ( ) + '/package.json' , TMP_WORK_DIR ) ;
61
+ //return promise_utils.promised_spawn('cp', ['-f', process.cwd() + '/package.json', TMP_WORK_DIR], process.cwd());
55
62
} )
56
63
. then ( function ( ) {
57
64
return os_utils . netstat_single ( TMP_WORK_DIR + '/netstat.out' ) ;
@@ -71,7 +78,11 @@ function write_agent_diag_file(data) {
71
78
72
79
function pack_diagnostics ( dst ) {
73
80
return P . fcall ( function ( ) {
74
- return promise_utils . promised_exec ( 'tar -zcvf ' + dst + ' ' + TMP_WORK_DIR + '/*' ) ;
81
+ return promise_utils . file_delete ( dst ) ;
82
+ } ) . then ( function ( ) {
83
+ console . log ( 'pack - ' , dst ) ;
84
+ return promise_utils . pack ( dst , TMP_WORK_DIR ) ;
85
+ // return promise_utils.promised_exec('tar -zcvf ' + dst + ' ' + TMP_WORK_DIR + '/*');
75
86
} )
76
87
. then ( function ( ) {
77
88
return archive_diagnostics_pack ( dst ) ;
@@ -80,7 +91,8 @@ function pack_diagnostics(dst) {
80
91
//The reason is that every distribution has its own issues.
81
92
//We had a case where it failed due to file change during the file.
82
93
//This flag can help, but not all the distributions support it
83
- console . error ( "failed to tar, an attempt to ignore file changes" ) ;
94
+ //This is not valid for windows where we have our own executable
95
+ console . error ( "failed to tar, an attempt to ignore file changes" , err ) ;
84
96
return P . fcall ( function ( ) {
85
97
return promise_utils . promised_exec ( 'tar --warning=no-file-changed -zcvf ' + dst + ' ' + TMP_WORK_DIR + '/*' ) ;
86
98
} )
@@ -101,27 +113,37 @@ function pack_diagnostics(dst) {
101
113
//Archive the current diagnostics pack, save to
102
114
function archive_diagnostics_pack ( dst ) {
103
115
return P . fcall ( function ( ) {
116
+ console . log ( 'archive_diagnostics_pack1' ) ;
104
117
return mkdirp . sync ( config . central_stats . previous_diag_packs_dir ) ;
105
118
} )
106
119
. then ( function ( ) {
120
+ console . log ( 'archive_diagnostics_pack2' ) ;
107
121
return P . nfcall ( fs . readdir , config . central_stats . previous_diag_packs_dir ) ;
108
122
} )
109
123
. then ( function ( files ) {
124
+ console . log ( 'archive_diagnostics_pack3' ) ;
125
+
110
126
//Check if current number of archived packs exceeds the max
111
127
if ( files . length === config . central_stats . previous_diag_packs_count ) {
112
128
//Delete the oldest pack
129
+ console . log ( 'archive_diagnostics_pack4' ) ;
130
+
113
131
var sorted_files = _ . orderBy ( files ) ;
114
132
return P . nfcall ( fs . unlink , config . central_stats . previous_diag_packs_dir + '/' + sorted_files [ 0 ] ) ;
115
133
} else {
134
+ console . log ( 'archive_diagnostics_pack5' ) ;
135
+
116
136
return ;
117
137
}
118
138
} )
119
139
. then ( function ( ) {
140
+ console . log ( 'archive_diagnostics_pack6' ) ;
141
+
120
142
//Archive the current pack
121
143
var now = new Date ( ) ;
122
144
var tail = now . getDate ( ) + '-' + ( now . getMonth ( ) + 1 ) + '_' + now . getHours ( ) + '-' + now . getMinutes ( ) ;
123
-
124
- return promise_utils . promised_exec ( 'cp ' + dst + ' ' + config . central_stats . previous_diag_packs_dir + '/DiagPack_' + tail + '.tgz' ) ;
145
+ return promise_utils . file_copy ( dst , config . central_stats . previous_diag_packs_dir + '/DiagPack_' + tail + '.tgz' ) ;
146
+ // return promise_utils.file_copy ('cp ' + dst + ' ' + config.central_stats.previous_diag_packs_dir + '/DiagPack_' + tail + '.tgz');
125
147
} )
126
148
. then ( null , function ( err ) {
127
149
console . error ( 'Error in archive_diagnostics_pack' , err , err . stack ) ;
0 commit comments