Permalink
Browse files

Upgrade and some fix of pointingserver

  • Loading branch information...
casiez committed Nov 2, 2018
1 parent 517ec02 commit 1db8da7a3cd89ddedb96f1f7859b1d0acb3cc14d
Showing with 66 additions and 53 deletions.
  1. +52 −47 bindings/Node/server/main.js
  2. +14 −6 bindings/Node/server/package.json
@@ -2,58 +2,63 @@
if (process.argv.length < 3)
console.log("Usage: pointingserver [start | stop]");
else {
var arg = (process.argv.length > 2) ? process.argv[2] : 'start';
var pidPath = __dirname + '/pointing.pid';
const fs = require('fs');
const port = 3423;
var arg = (process.argv.length > 2) ? process.argv[2] : 'start';
var pidPath = __dirname + '/pointing.pid';
const fs = require('fs');
const port = 3423;
if (arg == 'start') {
const http = require('http');
var server = http.createServer();
if (arg == 'start') {
const http = require('http');
var server = http.createServer();
server.listen(port).on('error', function(err) {
if (err.code === 'EADDRINUSE') {
console.log("Port " + port + " is already in use.")
const execSync = require('child_process').execSync;
processId = parseInt(execSync('lsof -t -i:' + port).toString('utf8'));
console.log("Id of process using the port:", processId);
process.exit();
}
});
server.close();
fs.access(pidPath, fs.F_OK, function(err) {
if (!err) { // If file exists remove it
fs.unlinkSync(pidPath);
}
const spawn = require('child_process').spawn;
const stdout = fs.openSync(__dirname + '/pointing.log', 'a');
const stderr = fs.openSync(__dirname + '/pointing.log', 'a');
const child = spawn('nohup', ['node', __dirname + '/server.js', port, '&'], {
detached: true,
stdio: [ 'ignore', stdout, stderr ]
server.listen(port).on('error', function(err) {
if (err.code === 'EADDRINUSE') {
console.log("Port " + port + " is already in use.")
const execSync = require('child_process').execSync;
processId = parseInt(execSync('lsof -t -i:' + port).toString('utf8'));
console.log("Id of process using the port:", processId);
process.exit();
}
});
fs.writeFile(pidPath, child.pid);
child.unref();
console.log('PointingServer was started');
});
}
if (arg == 'stop') {
fs.access(pidPath, fs.F_OK, function(err) {
if (!err) {
var pid = parseInt(fs.readFileSync(pidPath, 'utf8'));
fs.unlinkSync(pidPath);
try {
process.kill(pid);
console.log('PointingServer was stopped');
server.close();
fs.access(pidPath, fs.F_OK, function(err) {
if (!err) { // If file exists remove it
fs.unlinkSync(pidPath);
}
catch (ex) {
if (ex.code == 'ESRCH') {
console.log('PointingServer is not running');
const spawn = require('child_process').spawn;
const stdout = fs.openSync(__dirname + '/pointing.log', 'a');
const stderr = fs.openSync(__dirname + '/pointing.log', 'a');
const child = spawn('nohup', ['node', __dirname + '/server.js', port, '&'], {
detached: true,
stdio: [ 'ignore', stdout, stderr ]
});
fs.writeFile(pidPath, child.pid, (err) => {
if (err) throw err;
});
child.unref();
console.log('PointingServer was started');
});
}
if (arg == 'stop') {
fs.access(pidPath, fs.F_OK, function(err) {
if (!err) {
var pid = parseInt(fs.readFileSync(pidPath, 'utf8'));
fs.unlinkSync(pidPath);
try {
process.kill(pid);
console.log('PointingServer was stopped');
}
catch (ex) {
if (ex.code == 'ESRCH') {
console.log('PointingServer is not running');
}
}
}
}
});
});
}
}
@@ -3,17 +3,25 @@
"name": "pointingserver",
"description": "Pointing Server",
"homepage": "http://libpointing.org",
"version": "0.2.7",
"keywords": [ "libpointing", "HID", "transfer function" ],
"version": "0.2.8",
"keywords": [
"libpointing",
"HID",
"transfer function"
],
"author": "Izzatbek Mukhanov",
"license": "GPL",
"license": "GPL-2.0-or-later",
"dependencies": {
"express": "^4.13.3",
"socket.io": "^1.3.7",
"libpointing": "~1.0.3"
"libpointing": "~1.0.3",
"socket.io": "^2.1.1"
},
"bin": {
"pointingserver": "./main.js"
},
"preferGlobal": "true"
"preferGlobal": "true",
"repository": {
"type": "git",
"url": "https://github.com/INRIA/libpointing.git"
}
}

0 comments on commit 1db8da7

Please sign in to comment.