You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
maestro/app/classes/state/os/ServiceState.js

43 lines
1.4 KiB

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)
}
failure_message() {
const services = Array.isArray(this._config.service) ? this._config.service : [this._config.service]
return `The service(s) ${services.join(', ')} do not all exist on the host "${this._host.name}."`
}
check_message() {
return this.failure_message()
}
display() {
return `Ensure that the ${this._config.service} service is running...`
}
}
module.exports = exports = ServiceState