30 lines
1.0 KiB
JavaScript
30 lines
1.0 KiB
JavaScript
const State = require('../State')
|
|
|
|
class ServiceState extends State {
|
|
constructor(host, config) {
|
|
if ( !host.services ) {
|
|
throw new Error(`Cannot apply service state to host ${host.name}: missing service manager API.`)
|
|
}
|
|
super(host, config)
|
|
}
|
|
|
|
async apply() {
|
|
const services = Array.isArray(this._config.service) ? this._config.service : [this._config.service]
|
|
return this._host.services.start(...services)
|
|
}
|
|
|
|
async check() {
|
|
const services = Array.isArray(this._config.service) ? this._config.service : [this._config.service]
|
|
let states = await this._host.services.status(...services)
|
|
if ( !Array.isArray(states) ) states = [states]
|
|
return states.every(x => x.status === 'running')
|
|
}
|
|
|
|
async reverse() {
|
|
const services = Array.isArray(this._config.service) ? this._config.service : [this._config.service]
|
|
return this._host.services.stop(...services)
|
|
}
|
|
}
|
|
|
|
module.exports = exports = ServiceState
|