How to use readPid method in devicefarmer-stf

Best JavaScript code snippet using devicefarmer-stf

index.js

Source:index.js Github

copy

Full Screen

1const async = require('async');2const debug = require('debug')('ngineer');3const fs = require('fs');4const path = require('path');5const EventEmitter = require('events').EventEmitter;6const util = require('util');7const procinfo = require('procinfo');8const exec = require('child_process').exec;9const createLocation = require('./sections/location');10module.exports = function(basePath, opts) {11 const nginx = new EventEmitter();12 const pidLocation = path.resolve(basePath, (opts || {}).pidFile || 'logs/nginx.pid');13 let online = false;14 let pid;15 function monitorProcess(targetPid) {16 debug(`looking up process information for process: ${targetPid}`);17 procinfo(targetPid, function(err, processData) {18 pid = processData && processData.pids[0];19 nginx.online = !err;20 if (pid) {21 setTimeout(function() {22 monitorProcess(targetPid)23 }, 500);24 }25 });26 }27 function readPID() {28 // open the pid file29 debug(`looking for pid file: ${pidLocation}`);30 fs.readFile(pidLocation, 'utf8', function(err, data) {31 let watchTarget = pidLocation;32 // if we hit an error opening the file, then the pid file does not exist33 // therefore we will assume that nginx is not running34 if (err) {35 // if we are currently online, then flag then update the flag and trigger the offline event36 if (nginx.online) {37 nginx.online = false;38 }39 } else {40 const filePid = parseInt(data, 10);41 // file exists but pid is not yet valid42 if (isNaN(filePid)) {43 return process.nextTick(readPID);44 }45 // otherwise, read the file and check on the process status46 return monitorProcess(filePid);47 }48 // work up parent folders until we find a valid location49 while (!fs.existsSync(watchTarget)) {50 watchTarget = path.dirname(watchTarget);51 }52 // if the pid file has since been created read it again53 if (watchTarget === pidLocation) {54 return process.nextTick(readPID);55 }56 // check that we can read the file (avoid potential race condition with scaffolding)57 try {58 fs.accessSync(watchTarget, fs.constants.R_OK);59 } catch (e) {60 debug(`no read access to ${watchTarget}, sleeping 500ms`);61 setTimeout(readPID, 500);62 return;63 }64 // watch the appropriate location and trigger a reread when something changes65 debug(`watching: ${watchTarget}`);66 const watcher = fs.watch(watchTarget, { persistent: false });67 watcher.once('change', () => {68 debug(`target "${watchTarget}" changed`);69 watcher.close();70 readPID();71 });72 });73 }74 /**75 #### location(pattern) => NginxLocation76 Create a new location directive for the nginx configuration77 **/78 nginx.location = pattern => createLocation(nginx, basePath, {79 ...opts,80 pattern,81 });82 /**83 #### reload()84 The reload method sends the reload configuration (HUP) signal to the nginx process.85 **/86 nginx.reload = require('./reload')(nginx, basePath, opts);87 /**88 #### reset()89 The reset function cleans out the config directory and stops the nginx running if90 is running.91 **/92 nginx.reset = require('./reset')(nginx, basePath, opts);93 /**94 #### scaffold(callback)95 Scaffold an nginx configuration directory based on a known default96 configuration.97 **/98 nginx.scaffold = require('./scaffold')(nginx, basePath, opts);99 /**100 #### start(callback)101 Attempt to start nginx by using a few well known nginx binary locations.102 **/103 nginx.start = require('./start')(nginx, basePath, opts);104 /**105 #### stop(callback)106 Stop the nginx process107 **/108 nginx.stop = require('./stop')(nginx, basePath, opts);109 nginx.stopOnExit = require('./stop-on-exit')(nginx);110 Object.defineProperty(nginx, 'online', {111 get: function() {112 return online;113 },114 set: function(value) {115 // only update if we are toggling the state116 if (value !== online) {117 online = value;118 nginx.emit(value ? 'online' : 'offline');119 // if we have gone offline start looking for the pid again120 if (! value) {121 process.nextTick(readPID);122 }123 }124 }125 });126 Object.defineProperty(nginx, 'pid', {127 get: function() {128 return pid;129 }130 });131 nginx.basePath = basePath;132 readPID();133 return nginx;...

Full Screen

Full Screen

nginx_reload.js

Source:nginx_reload.js Github

copy

Full Screen

1/**2 * Sevice class to handle nginx process reload3 * Created by API Defender on 30/03/164 * @version 1.05 */6// Dependencies7var fs = require('fs')8var path = require('path')9var procinfo = require('procinfo')10var exec = require('child_process').exec11module.exports = Reloader12// Function to set nginx reload option and reload the nginx13function Reloader(opts, onChange) {14 if (!(this instanceof Reloader)) return new Reloader(opts, onChange)15 if (typeof opts === 'string') opts = {pidLocation: opts}16 if (!opts) opts = {}17 this.pidLocation = opts.pidLocation || '/run/nginx.pid'18 this.sudo = opts.sudo ? 'sudo ' : ''19 this.onChange = onChange || function noop(){}20 this.online = undefined21 this.pid = undefined22 this.readPID()23}24//25// watch the appropriate location26//27Reloader.prototype.end = function() {28 if (this.watcher) this.watcher.close()29}30// Function to send the reload configuration (HUP) signal to the nginx process.31Reloader.prototype.reload = function(cb) {32 exec(this.sudo + 'service nginx reload', function(err, stdout, stderr) {33 if (cb) cb(err, stdout, stderr)34 })35}36//37// Function to start nginx process38//39Reloader.prototype.start = function(cb) {40 exec(this.sudo + 'service nginx start', function(err, stdout, stderr) {41 if (cb) cb(err, stdout, stderr)42 })43}44//45// Function to stop nginx process46//47Reloader.prototype.stop = function(cb) {48 exec(this.sudo + 'service nginx stop', function(err, stdout, stderr) {49 if (cb) cb(err, stdout, stderr)50 })51}52//53// Function to read nginx pid file54//55Reloader.prototype.readPID = function() {56 var self = this57 var pidLocation = this.pidLocation58 var onChange = this.onChange59 // open the pid file60 fs.readFile(pidLocation, 'utf8', function(err, data) {61 var watchTarget = err ? path.dirname(pidLocation) : pidLocation62 // if we hit an error opening the file, then the pid file does not exist63 // therefore we will assume that nginx is not running64 if (err) {65 // if we are currently online, then update flag66 if (typeof self.online === 'undefined' || self.online) {67 self.online = false68 onChange(self.online)69 }70 }71 // otherwise, read the file and check on the process status72 else {73 procinfo(parseInt(data, 10), function(err, processData) {74 self.pid = processData.pids[0]75 var status = self.online76 self.online = !err77 if (status !== self.online) onChange(self.online)78 })79 }80 // watch the appropriate location and trigger a reread when something changes81 self.watcher = fs.watch(watchTarget, function(evt, filename) {82 this.close()83 self.readPID()84 })85 })...

Full Screen

Full Screen

extension.ts

Source:extension.ts Github

copy

Full Screen

1import * as vscode from 'vscode';2const child_process = require('child_process');3export function activate(context: vscode.ExtensionContext) {4 context.subscriptions.push(vscode.commands.registerCommand('ReadPid', readPid));5 async function readPid() {6 const asd = vscode.workspace.getConfiguration().get('ReadPid.AppName');7 let pid = child_process.execSync(`pidof ${asd} ;`);8 var str = pid.toString();9 vscode.window.showInformationMessage(`pidof ${asd} = ` + str);10 var pids = str.split(' ');11 var selectedValue = "";12 if (pids.length > 1) {13 await vscode.window.showQuickPick(pids).then(value => {14 if (!value) return;15 selectedValue = value;16 });17 return selectedValue;18 }19 else {...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const utils = require('devicefarmer-stf-utils');2const pid = utils.readPid();3console.log(pid);4{5 "scripts": {6 },7 "dependencies": {8 }9}10Copyright (c) 2017 DeviceFarmer

Full Screen

Using AI Code Generation

copy

Full Screen

1var devicefarmer = require('devicefarmer-stf');2var df = new devicefarmer.DeviceFarmer();3df.readPid(function(err, pid) {4 if (err) {5 console.log("Error: " + err);6 } else {7 console.log("Pid: " + pid);8 }9});

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf');2var pid = stf.readPid();3console.log("pid: " + pid);4var stf = require('devicefarmer-stf');5var pid = stf.killPid();6console.log("pid: " + pid);7var stf = require('devicefarmer-stf');8var pid = stf.start();9console.log("pid: " + pid);10var stf = require('devicefarmer-stf');11var pid = stf.stop();12console.log("pid: " + pid);13var stf = require('devicefarmer-stf');14var pid = stf.restart();15console.log("pid: " + pid);16var stf = require('devicefarmer-stf');17var devices = stf.getDevices();18console.log("devices: " + devices);19var stf = require('devicefarmer-stf');20var device = stf.getDevice("deviceSerial");21console.log("device: " + device);22var stf = require('devicefarmer-stf');23var device = stf.getDevice("deviceSerial");24console.log("device: " + device);25var stf = require('devicefarmer-stf');26var device = stf.getDevice("deviceSerial");27console.log("device: " + device);28var stf = require('devicefarmer-stf');29var device = stf.getDevice("deviceSerial");30console.log("device: " + device);31var stf = require('devicefarmer-stf');32var device = stf.getDevice("deviceSerial");33console.log("device: " + device);

Full Screen

Using AI Code Generation

copy

Full Screen

1var df_stf = require('devicefarmer-stf');2var stf = new df_stf();3var pid = stf.readPid();4console.log(pid);5var df_stf = require('devicefarmer-stf');6var stf = new df_stf();7var pid = stf.readPid();8console.log(pid);9var df_stf = require('devicefarmer-stf');10var stf = new df_stf();11var pid = stf.readPid();12console.log(pid);13var df_stf = require('devicefarmer-stf');14var stf = new df_stf();15var pid = stf.readPid();16console.log(pid);17var df_stf = require('devicefarmer-stf');18var stf = new df_stf();19var pid = stf.readPid();20console.log(pid);21var df_stf = require('devicefarmer-stf');22var stf = new df_stf();23var pid = stf.readPid();24console.log(pid);25var df_stf = require('devicefarmer-stf');26var stf = new df_stf();27var pid = stf.readPid();28console.log(pid);29var df_stf = require('devicefarmer-stf');30var stf = new df_stf();31var pid = stf.readPid();32console.log(pid);33var df_stf = require('devicefarmer-stf');34var stf = new df_stf();35var pid = stf.readPid();36console.log(pid);37var df_stf = require('devicefarmer-stf');38var stf = new df_stf();39var pid = stf.readPid();40console.log(pid);41var df_stf = require('

Full Screen

Using AI Code Generation

copy

Full Screen

1var devicefarmer = require('devicefarmer-stf');2devicefarmer.readPid('pidfile', function (err, pid) {3if (err) {4console.log('Error: ' + err);5} else {6console.log('Pid: ' + pid);7}8});9var devicefarmer = require('devicefarmer-stf');10devicefarmer.getPid('pidfile', function (err, pid) {11if (err) {12console.log('Error: ' + err);13} else {14console.log('Pid: ' + pid);15}16});17var devicefarmer = require('devicefarmer-stf');18devicefarmer.killPid('pidfile', function (err, pid) {19if (err) {20console.log('Error: ' + err);21} else {22console.log('Pid: ' + pid);23}24});25var devicefarmer = require('devicefarmer-stf');26devicefarmer.writePid('pidfile', function (err, pid) {27if (err) {28console.log('Error: ' + err);29} else {30console.log('Pid: ' + pid);31}32});33var devicefarmer = require('devicefarmer-stf');34devicefarmer.getPort('portfile', function (err, pid) {35if (err) {36console.log('Error: ' + err);37} else {38console.log('Pid: ' + pid);39}40});41var devicefarmer = require('devicefarmer-stf');42devicefarmer.writePort('portfile', function (err, pid) {43if (err) {44console.log('Error: ' + err);45} else {46console.log('Pid: ' + pid);47}48});49var devicefarmer = require('devicefarmer-stf');50devicefarmer.getDeviceId('deviceidfile', function (err, pid

Full Screen

Using AI Code Generation

copy

Full Screen

1var utils = require('devicefarmer-stf-utils');2var pid = utils.readPid();3console.log('PID is ' + pid);4var utils = require('devicefarmer-stf-utils');5var pid = utils.readPid();6console.log('PID is ' + pid);

Full Screen

Using AI Code Generation

copy

Full Screen

1var readPid = require('devicefarmer-stf-provider').readPid;2readPid('path/to/pidfile', function(err, pid) {3 if (err) {4 console.log('Error reading pid file: ' + err);5 } else {6 console.log('pid is: ' + pid);7 }8});9var writePid = require('devicefarmer-stf-provider').writePid;10writePid('path/to/pidfile', function(err) {11 if (err) {12 console.log('Error writing pid file: ' + err);13 } else {14 console.log('pid file written successfully');15 }16});17var killProcess = require('devicefarmer-stf-provider').killProcess;18killProcess('path/to/pidfile', function(err) {19 if (err) {20 console.log('Error killing process: ' + err);21 } else {22 console.log('Process killed successfully');23 }24});25var isProcessAlive = require('devicefarmer-stf-provider').isProcessAlive;26isProcessAlive('path/to/pidfile', function(err, alive) {27 if (err) {28 console.log('Error checking if process is alive: ' + err);29 } else {30 console.log('Process is alive: ' + alive);31 }32});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run devicefarmer-stf automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful