diff --git a/lib/instance.js b/lib/instance.js index 4bda3db52..477534d32 100644 --- a/lib/instance.js +++ b/lib/instance.js @@ -202,20 +202,26 @@ class Instance { if (!this._cliConfig.has('running')) { const currentEnvironment = this.system.development; - const envIsRunning = async (environment) => { + const envIsRunning = async (environment) => { if (!Config.exists(path.join(this.dir, `config.${environment}.json`))) { return false; } + // 1. Save original environment state + const originalEnv = this.system.environment; + this.system.setEnvironment(environment === 'development'); const running = await this.process.isRunning(this.dir); if (running) { this._cliConfig.set('running', environment).save(); } + // 2. Restore original environment state + this.system.setEnvironment(originalEnv === 'development'); + return running; }; - + const production = await envIsRunning('production'); if (production) { return true; @@ -386,7 +392,7 @@ class Instance { dir: this.dir.replace(os.homedir(), '~'), running: true, version: this.version, - mode: this.system.environment, + mode: this._cliConfig.get('running') || this.system.environment, url: this.config.get('url'), port: this.config.get('server.port'), process: this.process.name