- if (this.getEnableStatistics()) {
- this.performanceStatistics.start();
- }
- this.openWSConnection();
- // Monitor charging station template file
- this.templateFileWatcher = FileUtils.watchJsonFile(
- this.logPrefix(),
- FileType.ChargingStationTemplate,
- this.templateFile,
- null,
- (event, filename): void => {
- if (filename && event === 'change') {
- try {
- logger.debug(
- `${this.logPrefix()} ${FileType.ChargingStationTemplate} ${
- this.templateFile
- } file have changed, reload`
- );
- this.sharedLRUCache.deleteChargingStationTemplate(this.stationInfo?.templateHash);
- // Initialize
- this.initialize();
- // Restart the ATG
- this.stopAutomaticTransactionGenerator();
- if (this.getAutomaticTransactionGeneratorConfigurationFromTemplate()?.enable === true) {
- this.startAutomaticTransactionGenerator();
- }
- if (this.getEnableStatistics()) {
- this.performanceStatistics.restart();
- } else {
- this.performanceStatistics.stop();
+ if (this.started === false) {
+ if (this.starting === false) {
+ this.starting = true;
+ if (this.getEnableStatistics()) {
+ this.performanceStatistics.start();
+ }
+ this.openWSConnection();
+ // Monitor charging station template file
+ this.templateFileWatcher = FileUtils.watchJsonFile(
+ this.logPrefix(),
+ FileType.ChargingStationTemplate,
+ this.templateFile,
+ null,
+ (event, filename): void => {
+ if (filename && event === 'change') {
+ try {
+ logger.debug(
+ `${this.logPrefix()} ${FileType.ChargingStationTemplate} ${
+ this.templateFile
+ } file have changed, reload`
+ );
+ this.sharedLRUCache.deleteChargingStationTemplate(this.stationInfo?.templateHash);
+ // Initialize
+ this.initialize();
+ // Restart the ATG
+ this.stopAutomaticTransactionGenerator();
+ if (
+ this.getAutomaticTransactionGeneratorConfigurationFromTemplate()?.enable === true
+ ) {
+ this.startAutomaticTransactionGenerator();
+ }
+ if (this.getEnableStatistics()) {
+ this.performanceStatistics.restart();
+ } else {
+ this.performanceStatistics.stop();
+ }
+ // FIXME?: restart heartbeat and WebSocket ping when their interval values have changed
+ } catch (error) {
+ logger.error(
+ `${this.logPrefix()} ${FileType.ChargingStationTemplate} file monitoring error:`,
+ error
+ );
+ }