@medplum/agent 2.1.11 → 2.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/installer.nsi CHANGED
@@ -39,7 +39,8 @@ Var agentId
39
39
  # The onInit handler is called when the installer is nearly finished initializing.
40
40
  # See: https://nsis.sourceforge.io/Reference/.onInit
41
41
  Function .onInit
42
- ${If} ${FileExists} "$INSTDIR\winsw.xml"
42
+ ReadRegStr $0 HKLM "SYSTEM\CurrentControlSet\Services\${SERVICE_NAME}" "ImagePath"
43
+ ${If} $0 != ""
43
44
  StrCpy $alreadyInstalled 1
44
45
  ${EndIf}
45
46
  FunctionEnd
@@ -124,8 +125,8 @@ Function UpgradeApp
124
125
 
125
126
  # Stop the service
126
127
  DetailPrint "Stopping service..."
127
- ExecWait "winsw.exe stop --force" $1
128
- DetailPrint "Stop service returned $1"
128
+ ExecWait "sc.exe stop ${SERVICE_NAME}" $1
129
+ DetailPrint "Exit code $1"
129
130
 
130
131
  # Sleep for 3 seconds to let the service fully stop
131
132
  # We cannot write the new version of the exe while the process is running
@@ -138,7 +139,7 @@ Function UpgradeApp
138
139
 
139
140
  # Start the service
140
141
  DetailPrint "Starting service..."
141
- ExecWait "winsw.exe start" $1
142
+ ExecWait "sc.exe start ${SERVICE_NAME}" $1
142
143
  DetailPrint "Start service returned $1"
143
144
 
144
145
  FunctionEnd
@@ -154,32 +155,25 @@ Function InstallApp
154
155
  DetailPrint "Agent ID: $agentId"
155
156
 
156
157
  # Copy the service files to the root directory
157
- File ..\..\node_modules\node-windows\bin\winsw\winsw.exe
158
+ File ..\..\node_modules\node-shawl\bin\shawl-v1.3.0-legal.txt
159
+ File ..\..\node_modules\node-shawl\bin\shawl-v1.3.0-win64.exe
158
160
  File dist\medplum-agent-win-x64.exe
159
161
  File README.md
160
162
 
161
- # Create the winsw.xml config file
162
- # See config file format: https://github.com/winsw/winsw/blob/v3/docs/xml-config-file.md
163
- FileOpen $9 winsw.xml w
164
- FileWrite $9 "<service>$\r$\n"
165
- FileWrite $9 "<id>${SERVICE_NAME}</id>$\r$\n"
166
- FileWrite $9 "<name>${APP_NAME}</name>$\r$\n"
167
- FileWrite $9 "<description>Securely connects local devices to ${COMPANY_NAME} cloud</description>$\r$\n"
168
- FileWrite $9 "<executable>$INSTDIR\medplum-agent-win-x64.exe</executable>$\r$\n"
169
- FileWrite $9 "<arguments>$\"$baseUrl$\" $\"$clientId$\" $\"$clientSecret$\" $\"$agentId$\"</arguments>$\r$\n"
170
- FileWrite $9 "<startmode>Automatic</startmode>$\r$\n"
171
- FileWrite $9 "</service>$\r$\n"
172
- FileClose $9
173
-
174
- # Install the service
175
- DetailPrint "Installing service..."
176
- ExecWait "winsw.exe install" $1
177
- DetailPrint "Install returned $1"
163
+ # Create the service
164
+ DetailPrint "Creating service..."
165
+ ExecWait "shawl-v1.3.0-win64.exe add --name $\"${SERVICE_NAME}$\" -- $\"$INSTDIR\medplum-agent-win-x64.exe$\" $\"$baseUrl$\" $\"$clientId$\" $\"$clientSecret$\" $\"$agentId$\"" $1
166
+ DetailPrint "Exit code $1"
167
+
168
+ # Set service description
169
+ DetailPrint "Setting service description..."
170
+ ExecWait "sc.exe description $\"${SERVICE_NAME}$\" $\"Securely connects local devices to ${COMPANY_NAME} cloud$\"" $1
171
+ DetailPrint "Exit code $1"
178
172
 
179
173
  # Start the service
180
174
  DetailPrint "Starting service..."
181
- ExecWait "winsw.exe start" $1
182
- DetailPrint "Start service returned $1"
175
+ ExecWait "sc.exe start $\"${SERVICE_NAME}$\"" $1
176
+ DetailPrint "Exit code $1"
183
177
 
184
178
  # Create the uninstaller
185
179
  DetailPrint "Creating the uninstaller..."
@@ -203,11 +197,20 @@ FunctionEnd
203
197
  # Start the uninstaller
204
198
  Section Uninstall
205
199
 
206
- # Uninstall the service
207
- DetailPrint "Uninstalling service..."
208
- SetOutPath "$INSTDIR"
209
- ExecWait "winsw.exe uninstall" $1
210
- DetailPrint "Uninstall returned $1"
200
+ # Stop the service
201
+ DetailPrint "Stopping service..."
202
+ ExecWait "sc.exe stop ${SERVICE_NAME}" $1
203
+ DetailPrint "Exit code $1"
204
+
205
+ # Sleep for 3 seconds to let the service fully stop
206
+ # We cannot delete the file until the service is fully stopped
207
+ DetailPrint "Sleeping..."
208
+ Sleep 3000
209
+
210
+ # Deleting the service
211
+ DetailPrint "Deleting service..."
212
+ ExecWait "sc.exe delete ${SERVICE_NAME}" $1
213
+ DetailPrint "Exit code $1"
211
214
 
212
215
  # Get out of the service directory so we can delete it
213
216
  SetOutPath "$PROGRAMFILES64"
@@ -219,6 +222,7 @@ Section Uninstall
219
222
  RMDir /r /REBOOTOK "$INSTDIR"
220
223
 
221
224
  # Unregister the program
225
+ DeleteRegKey HKLM "SYSTEM\CurrentControlSet\Services\${SERVICE_NAME}"
222
226
  DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${SERVICE_NAME}"
223
227
 
224
228
  SectionEnd
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medplum/agent",
3
- "version": "2.1.11",
3
+ "version": "2.1.13",
4
4
  "description": "Medplum Agent",
5
5
  "homepage": "https://www.medplum.com/",
6
6
  "repository": {
@@ -13,22 +13,24 @@
13
13
  "scripts": {
14
14
  "agent": "ts-node src/main.ts",
15
15
  "build": "npm run clean && tsc && node esbuild.mjs",
16
+ "build:exe": "pkg ./dist/cjs/index.cjs --targets node18-win-x64 --output dist/medplum-agent-win-x64.exe --options no-warnings",
17
+ "build:installer": "makensis installer.nsi",
18
+ "build:all": "npm run build && npm run build:exe && npm run build:installer",
16
19
  "clean": "rimraf dist",
17
- "installer": "makensis installer.nsi",
18
- "package": "pkg ./dist/cjs/index.cjs --targets node18-win-x64 --output dist/medplum-agent-win-x64.exe --options no-warnings",
19
20
  "test": "jest"
20
21
  },
21
22
  "dependencies": {
22
23
  "@medplum/core": "*",
23
24
  "@medplum/hl7": "*",
25
+ "node-shawl": "1.3.0",
24
26
  "node-windows": "1.0.0-beta.8",
25
27
  "ws": "8.14.2"
26
28
  },
27
29
  "devDependencies": {
28
30
  "@medplum/fhirtypes": "*",
29
31
  "@medplum/mock": "*",
30
- "@types/node-windows": "0.1.4",
31
- "@types/ws": "8.5.7",
32
+ "@types/node-windows": "0.1.6",
33
+ "@types/ws": "8.5.9",
32
34
  "mock-socket": "9.3.1",
33
35
  "pkg": "5.8.1"
34
36
  },
package/src/main.ts CHANGED
@@ -219,16 +219,26 @@ export class AgentHl7ChannelConnection {
219
219
  }
220
220
  }
221
221
 
222
- if (typeof require !== 'undefined' && require.main === module) {
223
- if (process.argv.length < 6) {
222
+ async function main(argv: string[]): Promise<void> {
223
+ if (argv.length < 6) {
224
224
  console.log('Usage: node medplum-agent.js <baseUrl> <clientId> <clientSecret> <agentId>');
225
225
  process.exit(1);
226
226
  }
227
+ const [_node, _script, baseUrl, clientId, clientSecret, agentId] = argv;
227
228
 
228
- const [_node, _script, baseUrl, clientId, clientSecret, agentId] = process.argv;
229
229
  const medplum = new MedplumClient({ baseUrl, clientId });
230
- medplum
231
- .startClientLogin(clientId, clientSecret)
232
- .then(() => new App(medplum, agentId).start())
233
- .catch(console.error);
230
+ await medplum.startClientLogin(clientId, clientSecret);
231
+
232
+ const app = new App(medplum, agentId);
233
+ await app.start();
234
+
235
+ process.on('SIGINT', () => {
236
+ console.log('\ngracefully shutting down from SIGINT (Crtl-C)');
237
+ app.stop();
238
+ process.exit();
239
+ });
240
+ }
241
+
242
+ if (typeof require !== 'undefined' && require.main === module) {
243
+ main(process.argv).catch(console.error);
234
244
  }