Add support for running routines via command line
This commit is contained in:
@@ -27,6 +27,10 @@ class State extends Injectable {
|
||||
check_message() {
|
||||
throw new ImplementationError()
|
||||
}
|
||||
|
||||
display() {
|
||||
return this.constructor.name
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = State
|
||||
|
||||
@@ -34,6 +34,10 @@ class DirectoryState extends State {
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
|
||||
display() {
|
||||
return `Ensure that the directory ${this._config.path} exists...`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = DirectoryState
|
||||
|
||||
@@ -54,6 +54,10 @@ class DownloadState extends State {
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
|
||||
display() {
|
||||
return `Ensure that the file ${this._config.path} is downloaded from ${this._config.source}...`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = DownloadState
|
||||
|
||||
@@ -39,6 +39,10 @@ class FileState extends State {
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
|
||||
display() {
|
||||
return `Ensure that the file ${this._config.path} exists...`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = FileState
|
||||
|
||||
@@ -46,6 +46,10 @@ class OwnerState extends State {
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
|
||||
display() {
|
||||
return `Set filesystem owner of resource ${this._config.path}...`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = OwnerState
|
||||
|
||||
@@ -63,6 +63,10 @@ class PackState extends State {
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
|
||||
display() {
|
||||
return `Archive the contents of ${this._config.path} to ${this._config.destination}...`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = PackState
|
||||
|
||||
@@ -42,6 +42,10 @@ class PermissionState extends State {
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
|
||||
display() {
|
||||
return `Set filesystem permissions of resource ${this._config.path}...`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = PermissionState
|
||||
|
||||
@@ -66,6 +66,10 @@ class UnpackState extends State {
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
|
||||
display() {
|
||||
return `Un-archive the contents of ${this._config.path} to ${this._config.destination}...`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = UnpackState
|
||||
|
||||
@@ -40,6 +40,10 @@ class CheckoutState extends AbstractGitState {
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
|
||||
display() {
|
||||
return `Check out ref ${this._config.target} in repo ${this._config.path}...`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = CheckoutState
|
||||
|
||||
@@ -30,6 +30,10 @@ class CloneState extends AbstractGitState {
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
|
||||
display() {
|
||||
return `Clone repo at ${this._config.source} to ${this._config.path}...`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = CloneState
|
||||
|
||||
36
app/classes/state/git/PullState.js
Normal file
36
app/classes/state/git/PullState.js
Normal file
@@ -0,0 +1,36 @@
|
||||
const AbstractGitState = require('./AbstractGitState')
|
||||
|
||||
class PullState extends AbstractGitState {
|
||||
static get services() {
|
||||
return [...super.services, 'output']
|
||||
}
|
||||
|
||||
async apply() {
|
||||
if ( !(await this.check()) ) {
|
||||
const repo = await this._repo()
|
||||
await repo.pull(this._config.target)
|
||||
}
|
||||
}
|
||||
|
||||
async check() {
|
||||
return true // TODO support a better check here
|
||||
}
|
||||
|
||||
async reverse() {
|
||||
this.output.warn('Pull state does not currently support automatic reversal.')
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
return `The Git repo at "${this._config.path}" on host "${this._host.name}" will be pulled.`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
|
||||
display() {
|
||||
return `Pull refs in repo ${this._config.path}...`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = PullState
|
||||
@@ -33,6 +33,10 @@ class TagState extends AbstractGitState {
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
|
||||
display() {
|
||||
return `Create tag ${this._config.tag} in repo ${this._config.path}...`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = TagState
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
const State = require('../State')
|
||||
|
||||
class CommandState extends State {
|
||||
#ran_once = false
|
||||
|
||||
static get services() {
|
||||
return [...super.services, 'output']
|
||||
}
|
||||
|
||||
async apply() {
|
||||
const cmd = `${this._config.cmd}`
|
||||
await this._host.run(cmd)
|
||||
const result = await this._host.run(cmd)
|
||||
this.#ran_once = true
|
||||
}
|
||||
|
||||
async check() {
|
||||
return false
|
||||
return this.#ran_once
|
||||
}
|
||||
|
||||
async reverse() {
|
||||
@@ -30,6 +33,10 @@ class CommandState extends State {
|
||||
check_message() {
|
||||
return `The command check was not successful.`
|
||||
}
|
||||
|
||||
display() {
|
||||
return `Run the command: ${this._config.cmd}`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = CommandState
|
||||
|
||||
@@ -20,6 +20,10 @@ class IsAliveState extends State {
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
|
||||
display() {
|
||||
return `Ensure that the host is alive...`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = IsAliveState
|
||||
|
||||
@@ -27,6 +27,10 @@ class PackageAbsentState extends State {
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
|
||||
display() {
|
||||
return `Ensure that the package ${this._config.package} is not installed...`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = PackageAbsentState
|
||||
|
||||
@@ -31,6 +31,10 @@ class PackageCacheClearedState extends State {
|
||||
check_message() {
|
||||
return `The package cache on host "${this._host.name}" has not been cleared.`
|
||||
}
|
||||
|
||||
display() {
|
||||
return `Ensure that the package cache is cleared...`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = PackageCacheClearedState
|
||||
|
||||
@@ -27,6 +27,10 @@ class PackageState extends State {
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
|
||||
display() {
|
||||
return `Ensure that the package ${this._config.package} is installed...`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = PackageState
|
||||
|
||||
@@ -31,6 +31,10 @@ class ServiceDaemonReloadState extends State {
|
||||
check_message() {
|
||||
return `The service daemon on host "${this._host.name}" has not been reloaded.`
|
||||
}
|
||||
|
||||
display() {
|
||||
return `Reload the service daemon...`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = ServiceDaemonReloadState
|
||||
|
||||
@@ -32,6 +32,10 @@ class ServiceRestartState extends State {
|
||||
check_message() {
|
||||
return `The service "${this._config.service}" on host "${this._host.name}" has not been restarted.`
|
||||
}
|
||||
|
||||
display() {
|
||||
return `Restart the ${this._config.service} service...`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = ServiceRestartState
|
||||
|
||||
@@ -33,6 +33,10 @@ class ServiceState extends State {
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
|
||||
display() {
|
||||
return `Ensure that the ${this._config.service} service is running...`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = ServiceState
|
||||
|
||||
@@ -32,6 +32,10 @@ class ServiceStoppedState extends State {
|
||||
check_message() {
|
||||
return `The service "${this._config.service}" on host "${this._host.name}" has not been stopped.`
|
||||
}
|
||||
|
||||
display() {
|
||||
return `Ensure that the ${this._config.service} service is not running...`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = ServiceStoppedState
|
||||
|
||||
@@ -32,6 +32,10 @@ class UpdateState extends State {
|
||||
check_message() {
|
||||
return `There are package updates pending on the host "${this._host.name}."`
|
||||
}
|
||||
|
||||
display() {
|
||||
return `Ensure that all packages are up to date...`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = UpdateState
|
||||
|
||||
Reference in New Issue
Block a user