maestro/app/classes/state/os/ServiceStoppedState.js
2020-04-15 09:11:10 -05:00

38 lines
1.3 KiB
JavaScript

const State = require('../State')
class ServiceStoppedState extends State {
constructor(host, config) {
if ( !host.services ) {
throw new Error(`Cannot apply service stopped state to host ${host.name}: missing service manager API.`)
}
super(host, config)
}
async reverse() {
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.some(x => x.status === 'running')
}
async apply() {
const services = Array.isArray(this._config.service) ? this._config.service : [this._config.service]
return this._host.services.stop(...services)
}
failure_message() {
return `Unable to stop service "${this._config.service}" on host "${this._host.name}."`
}
check_message() {
return `The service "${this._config.service}" on host "${this._host.name}" has not been stopped.`
}
}
module.exports = exports = ServiceStoppedState