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

38 lines
1.0 KiB
JavaScript

const State = require('../State')
class ServiceRestartState extends State {
static get services() {
return [...super.services, 'output']
}
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.restart(...services)
}
async check() {
return false
}
async reverse() {
this.output.warn(`Service restart state does not currently support reversal. (Host: ${this._host.name})`)
}
failure_message() {
return `Unable to restart 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 restarted.`
}
}
module.exports = exports = ServiceRestartState