fix: ensure UI server remains active at simulator stop
[e-mobility-charging-stations-simulator.git] / src / charging-station / Bootstrap.ts
index 6620764559974d12e6ca8a89cf7ccae497937e22..503dfb0b7301f3f9e553e21c2a03a3f0ed34ad73 100644 (file)
@@ -195,7 +195,6 @@ export class Bootstrap extends EventEmitter {
         await this.workerImplementation?.stop();
         delete this.workerImplementation;
         this.removeAllListeners();
-        this.uiServer?.stop();
         await this.storage?.close();
         delete this.storage;
         this.resetCounters();
@@ -212,6 +211,8 @@ export class Bootstrap extends EventEmitter {
 
   public async restart(stopChargingStations?: boolean): Promise<void> {
     await this.stop(stopChargingStations);
+    Configuration.getConfigurationSection<UIServerConfiguration>(ConfigurationSection.uiServer)
+      .enabled === false && this.uiServer?.stop();
     await this.start();
   }
 
@@ -407,6 +408,7 @@ export class Bootstrap extends EventEmitter {
     this.stop()
       .then(() => {
         console.info(`${chalk.green('Graceful shutdown')}`);
+        this.uiServer?.stop();
         // stop() asks for charging stations to stop by default
         this.waitChargingStationsStopped()
           .then(() => {