1
1
import path from "path" ;
2
- import { window } from "vscode" ;
2
+ import { commands , window } from "vscode" ;
3
3
4
4
import { instance } from "../../instantiate" ;
5
+ import { t } from "../../locale" ;
5
6
import IBMi from "../IBMi" ;
6
7
import IBMiContent from "../IBMiContent" ;
7
8
import { Tools } from "../Tools" ;
@@ -11,15 +12,19 @@ const serverDirectory = `/QIBM/ProdData/IBMiDebugService/bin/`;
11
12
const MY_JAVA_HOME = `MY_JAVA_HOME="/QOpenSys/QIBM/ProdData/JavaVM/jdk80/64bit"` ;
12
13
13
14
export type DebugJob = {
14
- job : string
15
+ name : string
15
16
port : number
16
17
}
17
18
18
- export async function startup ( connection : IBMi ) {
19
+ export async function startService ( connection : IBMi ) {
19
20
const host = connection . currentHost ;
20
21
21
22
const encryptResult = await connection . sendCommand ( {
22
- command : `${ MY_JAVA_HOME } DEBUG_SERVICE_KEYSTORE_PASSWORD="${ host } " ${ path . posix . join ( serverDirectory , `encryptKeystorePassword.sh` ) } | /usr/bin/tail -n 1`
23
+ command : `${ path . posix . join ( serverDirectory , `encryptKeystorePassword.sh` ) } | /usr/bin/tail -n 1` ,
24
+ env : {
25
+ DEBUG_SERVICE_KEYSTORE_PASSWORD : host ,
26
+ MY_JAVA_HOME : "/QOpenSys/QIBM/ProdData/JavaVM/jdk80/64bit"
27
+ }
23
28
} ) ;
24
29
25
30
if ( ( encryptResult . code || 0 ) >= 1 ) {
@@ -34,26 +39,44 @@ export async function startup(connection: IBMi) {
34
39
35
40
const keystorePath = certificates . getRemoteServerCertificatePath ( connection ) ;
36
41
42
+ let didNotStart = false ;
37
43
connection . sendCommand ( {
38
44
command : `${ MY_JAVA_HOME } DEBUG_SERVICE_KEYSTORE_PASSWORD="${ password } " DEBUG_SERVICE_KEYSTORE_FILE="${ keystorePath } " /QOpenSys/usr/bin/nohup "${ path . posix . join ( serverDirectory , `startDebugService.sh` ) } "`
39
45
} ) . then ( startResult => {
40
- if ( ( startResult . code || 0 ) >= 1 ) {
41
- window . showErrorMessage ( startResult . stdout || startResult . stderr ) ;
46
+ if ( startResult . code ) {
47
+ window . showErrorMessage ( t ( "start.debug.service.failed" , startResult . stdout || startResult . stderr ) ) ;
48
+ didNotStart = true ;
42
49
}
43
50
} ) ;
44
51
45
- return ;
52
+ let tries = 0 ;
53
+ while ( ! didNotStart && tries < 20 ) {
54
+ if ( await getDebugServiceJob ( ) ) {
55
+ window . showInformationMessage ( t ( "start.debug.service.succeeded" ) ) ;
56
+ commands . executeCommand ( "code-for-ibmi.updateConnectedBar" ) ;
57
+ return true ;
58
+ }
59
+ else {
60
+ await Tools . sleep ( 500 ) ;
61
+ tries ++ ;
62
+ }
63
+ }
64
+
65
+ return false ;
46
66
}
47
67
48
- export async function stop ( connection : IBMi ) {
68
+ export async function stopService ( connection : IBMi ) {
49
69
const endResult = await connection . sendCommand ( {
50
- command : `${ path . posix . join ( serverDirectory , `stopDebugService.sh` ) } `
70
+ command : `${ MY_JAVA_HOME } ${ path . posix . join ( serverDirectory , `stopDebugService.sh` ) } `
51
71
} ) ;
52
72
53
- if ( endResult . code === 0 ) {
54
- window . showInformationMessage ( `Ended Debug Service.` ) ;
73
+ if ( ! endResult . code ) {
74
+ window . showInformationMessage ( t ( "stop.debug.service.succeeded" ) ) ;
75
+ commands . executeCommand ( "code-for-ibmi.updateConnectedBar" ) ;
76
+ return true ;
55
77
} else {
56
- window . showErrorMessage ( endResult . stdout || endResult . stderr ) ;
78
+ window . showErrorMessage ( t ( "stop.debug.service.failed" , endResult . stdout || endResult . stderr ) ) ;
79
+ return false ;
57
80
}
58
81
}
59
82
@@ -76,17 +99,7 @@ export async function getDebugServerJob() {
76
99
}
77
100
78
101
function rowToDebugJob ( row ?: Tools . DB2Row ) : DebugJob | undefined {
79
- return row ?. JOB_NAME ? { job : String ( row . JOB_NAME ) , port : Number ( row . LOCAL_PORT ) } : undefined ;
80
- }
81
-
82
- export async function end ( connection : IBMi ) : Promise < void > {
83
- const endResult = await connection . sendCommand ( {
84
- command : `${ MY_JAVA_HOME } ${ path . posix . join ( serverDirectory , `stopDebugService.sh` ) } `
85
- } ) ;
86
-
87
- if ( endResult . code && endResult . code >= 0 ) {
88
- throw new Error ( endResult . stdout || endResult . stderr ) ;
89
- }
102
+ return row ?. JOB_NAME ? { name : String ( row . JOB_NAME ) , port : Number ( row . LOCAL_PORT ) } : undefined ;
90
103
}
91
104
92
105
/**
@@ -113,4 +126,34 @@ export function endJobs(jobIds: string[], connection: IBMi) {
113
126
114
127
export async function isDebugEngineRunning ( ) {
115
128
return Boolean ( await getDebugServerJob ( ) ) && Boolean ( await getDebugServiceJob ( ) ) ;
129
+ }
130
+
131
+ export async function startServer ( ) {
132
+ const result = await instance . getConnection ( ) ?. runCommand ( { command : "STRDBGSVR" , noLibList : true } ) ;
133
+ if ( result ) {
134
+ if ( result . code ) {
135
+ window . showErrorMessage ( t ( "strdbgsvr.failed" ) , result . stderr ) ;
136
+ return false ;
137
+ }
138
+ else {
139
+ commands . executeCommand ( "code-for-ibmi.updateConnectedBar" ) ;
140
+ window . showInformationMessage ( t ( "strdbgsvr.succeeded" ) ) ;
141
+ }
142
+ }
143
+ return true ;
144
+ }
145
+
146
+ export async function stopServer ( ) {
147
+ const result = await instance . getConnection ( ) ?. runCommand ( { command : "ENDDBGSVR" , noLibList : true } ) ;
148
+ if ( result ) {
149
+ if ( result . code ) {
150
+ window . showErrorMessage ( t ( "enddbgsvr.failed" ) , result . stderr ) ;
151
+ return false ;
152
+ }
153
+ else {
154
+ commands . executeCommand ( "code-for-ibmi.updateConnectedBar" ) ;
155
+ window . showInformationMessage ( t ( "enddbgsvr.succeeded" ) ) ;
156
+ }
157
+ }
158
+ return true ;
116
159
}
0 commit comments