bugfixes and cleanup

This commit is contained in:
AJ ONeal 2018-06-28 01:53:03 -06:00
parent 4b168225f0
commit eb27cde8c0
2 changed files with 18 additions and 11 deletions

View File

@ -699,8 +699,10 @@ function sigHandler() {
if (tun) { if (tun) {
tun.end(); tun.end();
} }
if (controlServer) {
controlServer.close(); controlServer.close();
} }
}
// reverse 2FA otp // reverse 2FA otp
process.on('SIGINT', sigHandler); process.on('SIGINT', sigHandler);

View File

@ -28,7 +28,7 @@ Launcher.install = function (things, fn) {
, telebitUser: os.userInfo().username , telebitUser: os.userInfo().username
, telebitGroup: (/^darwin/i.test(os.platform()) ? 'staff' : os.userInfo().username) , telebitGroup: (/^darwin/i.test(os.platform()) ? 'staff' : os.userInfo().username)
, telebitRwDirs: [ , telebitRwDirs: [
path.resolve(__dirname, '../..') telebitRoot
, path.join(os.homedir(), '.config/telebit') , path.join(os.homedir(), '.config/telebit')
, path.join(os.homedir(), '.local/share/telebit') , path.join(os.homedir(), '.local/share/telebit')
] ]
@ -72,10 +72,11 @@ Launcher.install = function (things, fn) {
var stdout = fs.openSync(path.join(logpath, 'info.log'), 'a'); var stdout = fs.openSync(path.join(logpath, 'info.log'), 'a');
var stderr = fs.openSync(path.join(logpath, 'error.log'), 'a'); var stderr = fs.openSync(path.join(logpath, 'error.log'), 'a');
var killed = 0;
var err; var err;
var subprocess = spawn( var subprocess = spawn(
vars.telebitNode vars.telebitNode
, [ path.join(__dirname, '../../bin/telebitd.js') , [ path.join(telebitRoot, 'bin/telebitd.js')
, 'daemon' , 'daemon'
, '--config' , '--config'
, vars.telebitdConfig , vars.telebitdConfig
@ -87,16 +88,15 @@ Launcher.install = function (things, fn) {
subprocess.unref(); subprocess.unref();
subprocess.on('error', function (_err) { subprocess.on('error', function (_err) {
err = _err; err = _err;
killed += 1;
}); });
subprocess.on('exit', function (code, signal) { subprocess.on('exit', function (code, signal) {
if (!err) { err = new Error('' + code + ' ' + signal + ' failure to launch'); } if (!err) { err = new Error('' + code + ' ' + signal + ' failure to launch'); }
killed += 1;
}); });
setTimeout(function () { setTimeout(function () {
if (fn) { if (fn) { fn(null); return; }
fn(err);
return;
}
}, 1 * 1000); }, 1 * 1000);
return; return;
} }
@ -145,6 +145,7 @@ Launcher.install = function (things, fn) {
} }
, 'systemctl': function () { , 'systemctl': function () {
var launcher = path.join(os.homedir(), '.config/systemd/user/telebit.service'); var launcher = path.join(os.homedir(), '.config/systemd/user/telebit.service');
var launchername = 'telebit.service';
try { try {
mkdirp.sync(path.join(os.homedir(), '.config/systemd/user')); mkdirp.sync(path.join(os.homedir(), '.config/systemd/user'));
installLauncher({ installLauncher({
@ -154,16 +155,20 @@ Launcher.install = function (things, fn) {
} }
, vars: vars , vars: vars
}, function () { }, function () {
// IMPORTANT
// It's a dangerous to go alone, take this:
// SYSTEMD_LOG_LEVEL=debug journalctl -xef --user-unit=telebit
// (makes debugging systemd issues not "easy" per se, but possible)
var launcherstr = (vars.userspace ? "" : "sudo ") + "systemctl " + (vars.userspace ? "--user " : ""); var launcherstr = (vars.userspace ? "" : "sudo ") + "systemctl " + (vars.userspace ? "--user " : "");
exec(launcherstr + "daemon-reload", things._execOpts, function (err, stdout, stderr) { exec(launcherstr + "daemon-reload", things._execOpts, function (err, stdout, stderr) {
err = getError(err, stderr); err = getError(err, stderr);
if (err) { fn(err); return; } if (err) { fn(err); return; }
//console.log((stdout||'').trim()); //console.log((stdout||'').trim());
exec(launcherstr + "enable " + launcher, things._execOpts, function (err, stdout, stderr) { exec(launcherstr + "enable " + launchername, things._execOpts, function (err, stdout, stderr) {
err = getError(err, stderr); err = getError(err, stderr);
if (err) { fn(err); return; } if (err) { fn(err); return; }
//console.log((stdout||'').trim()); //console.log((stdout||'').trim());
exec(launcherstr + "restart " + launcher, things._execOpts, function (err, stdout, stderr) { exec(launcherstr + "restart " + launchername, things._execOpts, function (err, stdout, stderr) {
err = getError(err, stderr); err = getError(err, stderr);
if (err) { fn(err); return; } if (err) { fn(err); return; }
//console.log((stdout||'').trim()); //console.log((stdout||'').trim());
@ -235,12 +240,12 @@ Launcher.install = function (things, fn) {
// os.platform(), os.type() // os.platform(), os.type()
if (!/^win/i.test(os.platform())) { if (!/^win/i.test(os.platform())) {
if (/^darwin/i.test(os.platform())) { if (/^darwin/i.test(os.platform())) {
exec('type -p launchctl', things._execOpts, function (err, stdout, stderr) { exec('command -v launchctl', things._execOpts, function (err, stdout, stderr) {
err = getError(err, stderr); err = getError(err, stderr);
run(err, 'launchctl'); run(err, 'launchctl');
}); });
} else { } else {
exec('type -p systemctl', things._execOpts, function (err, stdout, stderr) { exec('command -v systemctl', things._execOpts, function (err, stdout, stderr) {
err = getError(err, stderr); err = getError(err, stderr);
run(err, 'systemctl'); run(err, 'systemctl');
}); });