@pixlcore/xyrun 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +7 -1
  2. package/main.js +28 -6
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -8,7 +8,7 @@ To use xyRun in a xyOps Event Plugin, make sure you set the Plugin's `runner` pr
8
8
 
9
9
  ## Features
10
10
 
11
- - Handles monitoring procesess, network connections, CPU and memory usage of remote jobs, and passing those metrics back to xyOps.
11
+ - Handles monitoring processes, network connections, CPU and memory usage of remote jobs, and passing those metrics back to xyOps.
12
12
  - Handles input files by creating a temporary directory for you job and pre-downloading all files from the xyOps master server.
13
13
  - Handles output files by intercepting the `files` message and uploading them directly to the xyOps master server.
14
14
 
@@ -53,6 +53,12 @@ Then wrap your remote command with a `xyrun` prefix:
53
53
  ssh user@target xyrun node /path/to/your-script.js
54
54
  ```
55
55
 
56
+ # Script Mode
57
+
58
+ When no sub-command is specified on the CLI, xyRun will look inside the job JSON data (passed in via STDIN) for a parameter named `script`. If this is found, it is quickly written out to a temp file, made executable (775), and that is what it launches. It is assumed that the provided `script` will contain a proper [Shebang](https://en.wikipedia.org/wiki/Shebang_%28Unix%29) line.
59
+
60
+ This allows xyRun to act as a "Remote Shell Plugin" for certain xyOps jobs that require it.
61
+
56
62
  # Development
57
63
 
58
64
  You can install the source code by using [Git](https://en.wikipedia.org/wiki/Git) ([Node.js](https://nodejs.org/) is also required):
package/main.js CHANGED
@@ -131,8 +131,26 @@ const app = {
131
131
  var child = null;
132
132
  var worker = {};
133
133
 
134
+ // setup environment for child
134
135
  var child_args = process.argv.slice(2);
135
136
  var child_cmd = child_args.shift();
137
+ var child_opts = {
138
+ env: Object.assign( {}, process.env )
139
+ };
140
+
141
+ if (!child_cmd && job.params && job.params.script) {
142
+ // no direct command specified, but user wants a "script" executed from the job params
143
+ var script_file = Path.join( job.cwd, 'xyops-script-temp-' + job.id + '.sh' );
144
+ child_cmd = Path.resolve(script_file);
145
+ child_args = [];
146
+
147
+ // quickly write out script file and make it executable
148
+ Tools.mkdirpSync( job.cwd, { mode: 0o777 } );
149
+ fs.writeFileSync( script_file, job.params.script.replace(/\r\n/g, "\n"), { mode: 0o775 } );
150
+
151
+ // set the cwd to the job cwd, as it's a more controlled environment
152
+ child_opts.cwd = job.cwd;
153
+ }
136
154
 
137
155
  if (!child_cmd) {
138
156
  // no command!
@@ -157,11 +175,6 @@ const app = {
157
175
 
158
176
  console.log( "Running command: " + child_cmd, child_args );
159
177
 
160
- // setup environment for child
161
- var child_opts = {
162
- env: Object.assign( {}, process.env )
163
- };
164
-
165
178
  // get uid / gid info for child env vars
166
179
  if (!this.platform.windows) {
167
180
  child_opts.uid = job.uid || process.getuid();
@@ -337,7 +350,7 @@ const app = {
337
350
  if (job.kill === 'none') {
338
351
  // kill none, just unref and finish
339
352
  worker.child.unref();
340
- this.shutdown();
353
+ this.finishJob();
341
354
  return;
342
355
  }
343
356
 
@@ -465,6 +478,15 @@ const app = {
465
478
 
466
479
  if (!job.files || !job.files.length || !Tools.isaArray(job.files)) return callback();
467
480
 
481
+ if (!job.base_url) {
482
+ console.error("Error: Cannot upload files: Missing 'base_url' property in job data.");
483
+ return callback();
484
+ }
485
+ if (!job.auth_token) {
486
+ console.error("Error: Cannot upload files: Missing 'auth_token' property in job data.");
487
+ return callback();
488
+ }
489
+
468
490
  async.eachSeries( job.files,
469
491
  function(file, callback) {
470
492
  var filename = Path.basename(file.filename || file.path).replace(/[^\w\-\+\.\,\s\(\)\[\]\{\}\'\"\!\&\^\%\$\#\@\*\?\~]+/g, '_');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pixlcore/xyrun",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Remote job runner script for xyOps.",
5
5
  "author": "Joseph Huckaby <jhuckaby@pixlcore.com>",
6
6
  "homepage": "https://github.com/pixlcore/xyrun",