How to use the child_process.SpawnTypes function in child_process

To help you get started, we’ve selected a few child_process examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Ylianst / MeshCentral / agents / modules_meshcmd / service-manager.js View on Github external
this._update.stdin.write('exit\n');
                    //update-rc.d meshagent defaults # creates symlinks for rc.d
                    //service meshagent start

                    this._update.waitExit();

                    break;
                case 'systemd':
                    var serviceDescription = options.description ? options.description : 'MeshCentral Agent';
                    if (!require('fs').existsSync('/usr/local/mesh')) { require('fs').mkdirSync('/usr/local/mesh'); }
                    require('fs').copyFileSync(options.servicePath, '/usr/local/mesh/' + options.name);
                    var m = require('fs').statSync('/usr/local/mesh/' + options.name).mode;
                    m |= (require('fs').CHMOD_MODES.S_IXUSR | require('fs').CHMOD_MODES.S_IXGRP);
                    require('fs').chmodSync('/usr/local/mesh/' + options.name, m);
                    require('fs').writeFileSync('/lib/systemd/system/' + options.name + '.service', '[Unit]\nDescription=' + serviceDescription + '\n[Service]\nExecStart=/usr/local/mesh/' + options.name + '\nStandardOutput=null\nRestart=always\nRestartSec=3\n[Install]\nWantedBy=multi-user.target\nAlias=' + options.name + '.service\n', { flags: 'w' });
                    this._update = require('child_process').execFile('/bin/sh', ['sh'], { type: require('child_process').SpawnTypes.TERM });
                    this._update._moduleName = options.name;
                    this._update.stdout.on('data', function (chunk) { });
                    this._update.stdin.write('systemctl enable ' + options.name + '.service\n');
                    this._update.stdin.write('exit\n');
                    this._update.waitExit();
                    break;
                default: // unknown platform service type
                    break;
            }
        }
        if(process.platform == 'darwin')
        {
            if (!this.isAdmin()) { throw ('Installing as Service, requires root'); }

            // Mac OS
            var stdoutpath = (options.stdout ? ('StandardOutPath\n' + options.stdout + '') : '');
github Ylianst / MeshAgent / modules / message-box.js View on Github external
this.client.uninstall = function ()
        {
            // Need to uninstall ourselves
            var child = require('child_process').execFile(process.execPath, [process.execPath.split('/').pop(), '-exec', "var s=require('service-manager').manager.getLaunchAgent('" + this._options.service + "', " + this._options.uid + "); s.unload(); require('fs').unlinkSync(s.plist);process.exit();"], { detached: true, type: require('child_process').SpawnTypes.DETACHED });
            child.waitExit();
        };
        return (this.client);
github Ylianst / MeshCentral / agents / modules_meshcmd / service-host.js View on Github external
}
                if (pid == null) {
                    try {
                        pid = parseInt(require('fs').readFileSync('.' + moduleName + '.pid', { flags: 'r' }));
                    }
                    catch (e) {
                    }
                }

                if (pid != null && pid == process.pid) {
                    this.emit('serviceStart');
                }
                else {
                    // Now we need to check if we were started with systemd
                    if (require('process-manager').getProcessInfo(1).Name == 'systemd') {
                        this._checkpid = require('child_process').execFile('/bin/sh', ['sh'], { type: require('child_process').SpawnTypes.TERM });
                        this._checkpid.result = '';
                        this._checkpid.parent = this;
                        this._checkpid.on('exit', function onCheckPIDExit() {
                            var lines = this.result.split('\r\n');
                            for (i in lines) {
                                if (lines[i].startsWith(' Main PID:')) {
                                    var tokens = lines[i].split(' ');
                                    if (parseInt(tokens[3]) == process.pid) {
                                        this.parent.emit('serviceStart');
                                    }
                                    else {
                                        this.parent.emit('normalStart');
                                    }
                                    delete this.parent._checkpid;
                                    return;
                                }
github Ylianst / MeshCentral / agents / modules_meshcore / toaster.js View on Github external
value: require('user-sessions').Current(function onCurrentSession(sessions)
                {
                    this._cchild = require('child_process').execFile('/usr/bin/whoami', ['whoami'], { type: require('child_process').SpawnTypes.TERM });
                    this._cchild.stdout.on('data', function (chunk)
                    {
                        if (chunk.toString().split('\r\n')[0] == 'root')
                        {
                            if (sessions[':0'].State != 'Connected' && sessions[':0'].State != 'Active')
                            {
                                // No logged in user owns the display
                                this.parent.parent.Parent.emit('Dismissed');
                                return;
                            }

                            // We root, so we need to direct to DISPLAY=:0
                            this.parent.parent._notify = require('child_process').execFile('/bin/sh', ['sh'], { type: require('child_process').SpawnTypes.TERM });
                            this.parent.parent._notify.stdin.write('su - ' + sessions[':0'].Username + ' -c "DISPLAY=:0 notify-send \'' + this.parent.parent.Parent.title + '\' \'' + this.parent.parent.Parent.caption + '\'"\n');
                            this.parent.parent._notify.stdin.write('exit\n');
                            this.parent.parent._notify.stdout.on('data', function (chunk) { });
github Ylianst / MeshCentral / agents / modules_meshcore / linux-dbus.js View on Github external
function dbus(address, uid)
{
    this._ObjectID = 'linux-dbus';
    require('events').EventEmitter.call(this, true)
        .createEvent('signal');
    Object.defineProperty(this, "uid", { value: uid });
    this._child = require('child_process').execFile("/bin/sh", ["sh"], { type: require('child_process').SpawnTypes.TERM, uid: uid == null ? -1 : uid });
    this._child.stdin.write('dbus-monitor --session "type=\'signal\', interface=\'' + address + '\'" | ( while read X; do echo "$X"; done )\n');
    this._child.stdout.dbus = this;
    this._child.stdout.on('data', function (chunk)
    {
        // Parse DBUS Data
        if (!this.ready) { this.ready = true; return; }

        var lines = [];
        var tokens = chunk.toString().split('\r\n');
        for (var i in tokens)
        {
            if (tokens[i] == '')
            {
                // End of record
                this.dbus.preParseRecords(lines);
                lines = [];
github Ylianst / MeshAgent / modules / linux-dbus.js View on Github external
function dbus(address, uid)
{
    this._ObjectID = 'linux-dbus';
    require('events').EventEmitter.call(this, true)
        .createEvent('signal');
    Object.defineProperty(this, "uid", { value: uid });
    this._child = require('child_process').execFile("/bin/sh", ["sh"], { type: require('child_process').SpawnTypes.TERM, uid: uid == null ? -1 : uid });
    this._child.stdin.write('dbus-monitor --session "type=\'signal\', interface=\'' + address + '\'" | ( while read X; do echo "$X"; done )\n');
    this._child.stdout.dbus = this;
    this._child.stdout.on('data', function (chunk)
    {
        // Parse DBUS Data
        if (!this.ready) { this.ready = true; return; }

        var lines = [];
        var tokens = chunk.toString().split('\r\n');
        for (var i in tokens)
        {
            if (tokens[i] == '')
            {
                // End of record
                this.dbus.preParseRecords(lines);
                lines = [];
github Ylianst / MeshCentral / agents / meshcore.js View on Github external
}
                    };

                    // Remote terminal using native pipes
                    if (process.platform == "win32") {
                        if ((this.httprequest.protocol == 6) && (require('win-terminal').PowerShellCapable() == true)) {
                            this.httprequest._term = require('win-terminal').StartPowerShell(80, 25);
                        } else {
                            this.httprequest._term = require('win-terminal').Start(80, 25);
                        }
                        this.httprequest._term.pipe(this, { dataTypeSkip: 1 });
                        this.pipe(this.httprequest._term, { dataTypeSkip: 1, end: false });
                        this.prependListener('end', function () { this.httprequest._term.end(function () { console.log('Terminal was closed'); }); });
                    } else {
                        if (fs.existsSync("/bin/bash")) {
                            this.httprequest.process = childProcess.execFile("/bin/bash", ["bash", "-i"], { type: childProcess.SpawnTypes.TERM });
                            if (process.platform == 'linux') { this.httprequest.process.stdin.write("alias ls='ls --color=auto'\nclear\n"); }
                        } else {
                            this.httprequest.process = childProcess.execFile("/bin/sh", ["sh"], { type: childProcess.SpawnTypes.TERM });
                            if (process.platform == 'linux') { this.httprequest.process.stdin.write("stty erase ^H\nalias ls='ls --color=auto'\nPS1='\\u@\\h:\\w\\$ '\nclear\n"); }
                        }
                        this.httprequest.process.tunnel = this;
                        this.httprequest.process.on('exit', function (ecode, sig) { this.tunnel.end(); });
                        this.httprequest.process.stderr.on('data', function (chunk) { this.parent.tunnel.write(chunk); });
                        this.httprequest.process.stdout.pipe(this, { dataTypeSkip: 1 }); // 0 = Binary, 1 = Text.
                        this.pipe(this.httprequest.process.stdin, { dataTypeSkip: 1, end: false }); // 0 = Binary, 1 = Text.
                        this.prependListener('end', function () { this.httprequest.process.kill(); });
                    }

                    // Perform notification if needed. Toast messages may not be supported on all platforms.
                    if (this.httprequest.consent && (this.httprequest.consent & 16)) {
                        // User Consent Prompt is required
github Ylianst / MeshCentral / agents / modules_meshcmd / service-host.js View on Github external
if (retVal.Val == 0)
                {
                    this.parent.emit('normalStart');
                }
            });
            return;
        }
        else if (process.platform == 'linux')
        {
            var moduleName = this._ServiceOptions ? this._ServiceOptions.name : process.execPath.substring(1 + process.execPath.lastIndexOf('/'));

            for (var i = 0; i < process.argv.length; ++i) {
                switch (process.argv[i]) {
                    case 'start':
                    case '-d':
                        var child = require('child_process').execFile(process.execPath, [moduleName], { type: require('child_process').SpawnTypes.DETACHED });
                        var pstream = null;
                        try {
                            pstream = require('fs').createWriteStream('/var/run/' + moduleName + '.pid', { flags: 'w' });
                        }
                        catch (e) {
                        }
                        if (pstream == null) {
                            pstream = require('fs').createWriteStream('.' + moduleName + '.pid', { flags: 'w' });
                        }
                        pstream.end(child.pid.toString());

                        console.log(moduleName + ' started!');
                        process.exit();
                        break;
                    case 'stop':
                    case '-s':
github Ylianst / MeshCentral / agents / modules_meshcore / x / service-manager.js View on Github external
catch(e)
                    {
                    }
                }
            }
            else
            {
                throw ('Cannot uninstall service: ' + name + ', because it is: ' + service.status.state);
            }
        }
        else if(process.platform == 'linux')
        {
            switch (this.getServiceType())
            {
                case 'init':
                    this._update = require('child_process').execFile('/bin/sh', ['sh'], { type: require('child_process').SpawnTypes.TERM });
                    this._update.stdout.on('data', function (chunk) { });
                    this._update.stdin.write('service ' + name + ' stop\n');
                    this._update.stdin.write('update-rc.d -f ' + name + ' remove\n');
                    this._update.stdin.write('exit\n');
                    this._update.waitExit();
                    try
                    {
                        require('fs').unlinkSync('/etc/init.d/' + name);
                        console.log(name + ' uninstalled');

                    }
                    catch (e)
                    {
                        console.log(name + ' could not be uninstalled', e)
                    }
                    break;
github Ylianst / MeshCentral / agents / meshcore-OldTerminal.js View on Github external
function openUserDesktopUrl(url) {
        var child = null;
        try {
            switch (process.platform) {
                case 'win32':
                    child = require('child_process').execFile(process.env['windir'] + '\\system32\\cmd.exe', ["/c", "start", url], { type: childProcess.SpawnTypes.USER });
                    break;
                case 'linux':
                    child = require('child_process').execFile('/usr/bin/xdg-open', ['xdg-open', url], { type: require('child_process').SpawnTypes.DETACHED, uid: require('user-sessions').consoleUid() });
                    break;
                case 'darwin':
                    child = require('child_process').execFile('/usr/bin/open', ['open', url], { uid: require('user-sessions').consoleUid() });
                    break;
            }
        } catch (ex) { }
        return child;
    }

child_process

This package name is not currently in use, but was formerly occupied by another package. To avoid malicious use, npm is hanging on to the package name, but loosely, and we'll probably give it to you if you want it.

ISC
Latest version published 8 years ago

Package Health Score

65 / 100
Full package analysis