Sample Header Ad - 728x90

NodeJS child_process.spawn() behaving different when run as systemd service on Debian 10

1 vote
0 answers
620 views
I am working on a NodeJS application, that runs expressJS and uses twinkle to dial a telephonenumber. Given the following function: export const call = (telNr: string, res: Response|undefined = undefined) => { const endOfLine = require("os").EOL; const process = spawn("/usr/bin/twinkle", ["-c"], {shell: true}); let registered = false; process.stdout.on("data", (data) => { if (/registration succeeded/.test(data.toString())) { if (!registered) { registered = true; process.stdin.write("call " + telNr + endOfLine); setTimeout(() => { try { process.stdin.write("bye" + endOfLine); process.stdin.write("exit" + endOfLine); } catch { // War schon zu } }, 10000); } // Else -> Scheint das zweite mal ausgegeben zu werden. } if (/486 Busy here/.test(data.toString())) { // Belegt process.stdin.write("exit" + endOfLine); } }); process.on("exit", (exit) => { if (res !== undefined) { res.json({code: exit}); } }); }; The function is for debugging purposes called via an url (that's why there's the optional res-parameter. ***now to the problem*** When I start the app as root with node index.js, and open the given URL the wanted SIP-Phone rings for 10 seconds. When the app is started as service via systemd, the childprocess is immediately closed with exitcode 134. systemd-unit: [Unit] Description=Besuchermanagement Server After=network.target [Service] Type=simple ExecStart=/usr/bin/node /srv/node/besuchermanagement/dist/index.js Restart=on-failure [Install] WantedBy=multi-user.target I hope this isn't offtopic, since I am not sure if this problem is related to my code, or a misconfiguration of my service in systemd. Thanks in advance!
Asked by Marcel Kohlmeyer (51 rep)
Jan 27, 2020, 09:24 AM
Last activity: Aug 2, 2022, 07:56 AM