- if (isMainThread && this.started === false) {
- this.initializeCounters();
- this.initializeWorkerImplementation();
- await this.workerImplementation?.start();
- await this.storage?.open();
- this.uiServer?.start();
- // Start ChargingStation object instance in worker thread
- for (const stationTemplateUrl of Configuration.getStationTemplateUrls()) {
- try {
- const nbStations = stationTemplateUrl.numberOfStations ?? 0;
- for (let index = 1; index <= nbStations; index++) {
- await this.startChargingStation(index, stationTemplateUrl);
+ if (this.started === false) {
+ if (this.starting === false) {
+ this.starting = true;
+ this.initializeCounters();
+ const workerConfiguration = Configuration.getConfigurationSection<WorkerConfiguration>(
+ ConfigurationSection.worker,
+ );
+ this.initializeWorkerImplementation(workerConfiguration);
+ await this.workerImplementation?.start();
+ await this.storage?.open();
+ Configuration.getConfigurationSection<UIServerConfiguration>(ConfigurationSection.uiServer)
+ .enabled === true && this.uiServer?.start();
+ // Start ChargingStation object instance in worker thread
+ for (const stationTemplateUrl of Configuration.getStationTemplateUrls()!) {
+ try {
+ const nbStations = stationTemplateUrl.numberOfStations ?? 0;
+ for (let index = 1; index <= nbStations; index++) {
+ await this.startChargingStation(index, stationTemplateUrl);
+ }
+ } catch (error) {
+ console.error(
+ chalk.red(
+ `Error at starting charging station with template file ${stationTemplateUrl.file}: `,
+ ),
+ error,
+ );