fix(xo-server-recover-account): connect Redis client (#6398)
This commit is contained in:
parent
62591e1f6f
commit
8c14906a60
@ -30,20 +30,41 @@ export default class Hooks extends EventEmitter {
|
||||
// Run *start* async listeners.
|
||||
//
|
||||
// They initialize the application.
|
||||
//
|
||||
// *startCore* is automatically called if necessary.
|
||||
async start() {
|
||||
assert.strictEqual(this._status, 'stopped')
|
||||
if (this._status === 'stopped') {
|
||||
await this.startCore()
|
||||
} else {
|
||||
assert.strictEqual(this._status, 'core started')
|
||||
}
|
||||
this._status = 'starting'
|
||||
await runHook(this, 'start')
|
||||
this.emit((this._status = 'started'))
|
||||
}
|
||||
|
||||
// Run *stop* async listeners.
|
||||
// Run *start core* async listeners.
|
||||
//
|
||||
// They initialize core features of the application (connect to databases,
|
||||
// etc.) and should be fast and side-effects free.
|
||||
async startCore() {
|
||||
assert.strictEqual(this._status, 'stopped')
|
||||
this._status = 'starting core'
|
||||
await runHook(this, 'start core')
|
||||
this.emit((this._status = 'core started'))
|
||||
}
|
||||
|
||||
// Run *stop* async listeners if necessary and *stop core* listeners.
|
||||
//
|
||||
// They close connections, unmount file systems, save states, etc.
|
||||
async stop() {
|
||||
assert.strictEqual(this._status, 'started')
|
||||
this._status = 'stopping'
|
||||
await runHook(this, 'stop')
|
||||
if (this._status !== 'core started') {
|
||||
assert.strictEqual(this._status, 'started')
|
||||
this._status = 'stopping'
|
||||
await runHook(this, 'stop')
|
||||
this._status = 'core started'
|
||||
}
|
||||
await runHook(this, 'stop core')
|
||||
this.emit((this._status = 'stopped'))
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,7 @@
|
||||
<!--packages-start-->
|
||||
|
||||
- @xen-orchestra/fs minor
|
||||
- @xen-orchestra/mixins minor
|
||||
- vhd-lib patch
|
||||
- xo-server minor
|
||||
- xo-web minor
|
||||
|
@ -34,6 +34,8 @@ xo-server-recover-account <user name or email>
|
||||
}),
|
||||
})
|
||||
|
||||
await xo.hooks.startCore()
|
||||
|
||||
const user = await xo.getUserByName(name, true)
|
||||
if (user !== null) {
|
||||
await xo.updateUser(user.id, {
|
||||
@ -46,4 +48,6 @@ xo-server-recover-account <user name or email>
|
||||
await xo.createUser({ name, password, permission: 'admin' })
|
||||
console.log(`user ${name} has been successfully created`)
|
||||
}
|
||||
|
||||
await xo.hooks.stop()
|
||||
})
|
||||
|
@ -47,8 +47,8 @@ export default class Xo extends EventEmitter {
|
||||
const redis = createRedisClient({ path, url })
|
||||
|
||||
this._redis = redis
|
||||
this.hooks.on('start', () => redis.connect())
|
||||
this.hooks.on('stop', () => redis.quit())
|
||||
this.hooks.on('start core', () => redis.connect())
|
||||
this.hooks.on('stop core', () => redis.quit())
|
||||
}
|
||||
|
||||
this.hooks.on('start', () => this._watchObjects())
|
||||
|
Loading…
Reference in New Issue
Block a user