updated documentation, made minor changes to the config
This commit is contained in:
parent
daeb9d004e
commit
7dc504171b
5 changed files with 69 additions and 15 deletions
23
README.md
23
README.md
|
@ -1,3 +1,24 @@
|
|||
# remex
|
||||
|
||||
execute local commands remotely via http requests
|
||||
execute local commands remotely via http requests
|
||||
|
||||
## configuration
|
||||
|
||||
configuration is done entirely within the file `config.json`.
|
||||
|
||||
### server: [*object*]
|
||||
- listen: [*string*] listen address
|
||||
- port: [*number*] port to listen on
|
||||
|
||||
### log: [*object*]
|
||||
- level: [*string*] verbosity of the log; either `debug`, `info`, `warning` or `error`
|
||||
- timestamp: [*string*] format string for the timestamp; review [moment.js](https://momentjs.com/docs/#/displaying/format/) for further information
|
||||
|
||||
### api: [*object-array*]
|
||||
- url: [*string*] endpoint url; example: `/example`
|
||||
- method: [*string*] http request method
|
||||
- command: [*string*] command to execute
|
||||
- args: [*string-array*] arguments to pass to the executed command
|
||||
- options: [*object*]
|
||||
- detach [*boolean*] detach from the executed command / do not wait for the command to finish
|
||||
- unique [*boolean* or *string*] if set to `true` the command can not be executed again until it has finished; if set to `restart` the command will be killed (if active) and started again; if set to `toggle` the command will either be killed if active or started if not active
|
||||
|
|
30
config.json
30
config.json
|
@ -18,8 +18,7 @@
|
|||
],
|
||||
"options": {
|
||||
"detach": true,
|
||||
"unique": true,
|
||||
"restart": true
|
||||
"unique": "toggle"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -27,6 +26,33 @@
|
|||
"method": "get",
|
||||
"command": "uptime",
|
||||
"args": []
|
||||
},
|
||||
{
|
||||
"url": "/systemctl/docker",
|
||||
"method": "get",
|
||||
"command": "systemctl",
|
||||
"args": [
|
||||
"is-active",
|
||||
"code-server@velvettear"
|
||||
]
|
||||
},
|
||||
{
|
||||
"url": "/systemctl/docker/start",
|
||||
"method": "post",
|
||||
"command": "systemctl",
|
||||
"args": [
|
||||
"start",
|
||||
"code-server@velvettear"
|
||||
]
|
||||
},
|
||||
{
|
||||
"url": "/systemctl/docker/stop",
|
||||
"method": "post",
|
||||
"command": "systemctl",
|
||||
"args": [
|
||||
"stop",
|
||||
"code-server@velvettear"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
|
@ -7,13 +7,21 @@ async function execute(endpoint) {
|
|||
if (endpoint === undefined) {
|
||||
return;
|
||||
}
|
||||
if (endpoint.options?.unique && isCommandActive(endpoint)) {
|
||||
if (!endpoint.options?.restart) {
|
||||
logger.info('not executing unique command \'' + endpoint.command + '\' (args: \'' + endpoint.args + '\') because it is already active');
|
||||
throw new Error('command is already active');
|
||||
let unique = endpoint.options?.unique;
|
||||
if (unique !== undefined && isCommandActive(endpoint)) {
|
||||
unique = unique.toLowerCase();
|
||||
switch (unique.toLowerCase()) {
|
||||
case 'true':
|
||||
logger.info('not executing unique command \'' + endpoint.command + '\' (args: \'' + endpoint.args + '\') because it is already active');
|
||||
throw new Error('command is already active');
|
||||
case 'restart':
|
||||
logger.info('killing and restarting unique command \'' + endpoint.command + '\' (args: \'' + endpoint.args + '\')');
|
||||
await killCommand(endpoint);
|
||||
break;
|
||||
case 'toggle':
|
||||
logger.info('stopping unique command \'' + endpoint.command + '\' (args: \'' + endpoint.args + '\')');
|
||||
return await killCommand(endpoint);
|
||||
}
|
||||
logger.info('killing and restarting unique command \'' + endpoint.command + '\' (args: \'' + endpoint.args + '\')');
|
||||
await killCommand(endpoint);
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
logger.info('executing command \'' + endpoint.command + '\' (args: \'' + endpoint.args + '\')...');
|
||||
|
@ -91,8 +99,8 @@ async function killCommand(endpoint) {
|
|||
return;
|
||||
}
|
||||
process.kill(command.pid, 'SIGINT');
|
||||
while(isCommandActive(endpoint)) {
|
||||
await sleep(100);
|
||||
while (isCommandActive(endpoint)) {
|
||||
await sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
"version": "0.0.1",
|
||||
"description": "execute local commands remotely via http requests",
|
||||
"main": "remex.js",
|
||||
"scripts": {
|
||||
},
|
||||
"scripts": {},
|
||||
"keywords": [
|
||||
"scripts",
|
||||
"commands",
|
||||
|
@ -20,4 +19,4 @@
|
|||
"dependencies": {
|
||||
"moment": "^2.29.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
2
remex.js
2
remex.js
|
@ -8,7 +8,7 @@ const INTERRUPTS = ['beforeExit', 'SIGINT', 'SIGTERM'];
|
|||
main();
|
||||
|
||||
async function main() {
|
||||
let configPath = path.resolve('./config.json');
|
||||
let configPath = path.resolve(__dirname + '/config.json');
|
||||
try {
|
||||
global.config = require(configPath);
|
||||
} catch (err) {
|
||||
|
|
Loading…
Reference in a new issue