'nodejs client application does not give response when running as a service

I have a client.js application that calls a bash script with the child process. And i have no problem with that, everything is working like a charm.

const io = require("socket.io-client")
const { exec } = require('child_process')
const args = process.argv.slice(2)
var json = require('../cfg.json');
var server_url = json.server_url;

console.log(server_url);
ioClient = io.connect(server_url);

ioClient.emit('register_me', {type: "camera"});

ioClient.on("start_stream", (arg) => {
    console.log("postime", arg.postime); // world
    const { exec } = require('child_process');
    var yourscript = exec('bash sendjob.sh --postime 500', {shell: "/bin/bash"},
        (error, stdout, stderr) => {
    //  detached:true;
            console.log(stdout);
            console.log(stderr);
            if (error !== null) {
              //  console.log(`exec error: ${error}`);
            }
        });
});

So next step run this script as a service, and:

   [Unit]
    Description=NodeJs

    [Service]
    ExecStart=/usr/bin/node /home/gumball/Softwares/client/client.js
    StandardOutput=syslog
    StandardError=syslog

    [Install]
    WantedBy=multi-user.target

It's also working. now, on my server-side, I see that connected client, but when I trigger to start_stream function from the server-side, i can't see anything. I mean it should call a bash script on the client-side but it's not working, I thought that problem is related to file permissions but chmod +x is not working as well.

thanks in advence.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source