当Nodejs应用程序开始使用Systemd时,Nodejs App不会产生python子进程

时间:2017-04-28 14:33:47

标签: javascript python node.js raspberry-pi systemd

我想在启动时启动我的节点js应用程序。因此,我从Systemd开始提供服务:

train_sentence[0] = train_sentence[0].replace(BOM,'')

server.js如下所示:

[Unit]
Description=Node.js server
After=network.target

[Service]
ExecStart=/usr/bin/node /var/www/Raspberry-Pi-Status/js/server.js
Restart = always
RestartSec=10
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=nodejs-server
Environment=NODE_ENV=production PORT=8000
Environment=PYTHONPATH=/usr/bin/python

[INSTALL]
WantedBy=multi-user.target

node.js应用程序应该启动一个读取温度传感器的python脚本。当我通过控制台启动node.js时一切正常。但是,当我从Systemd启动时,不会生成python脚本。 有什么问题?我错过了什么吗?

提前致谢 亚历山大

1 个答案:

答案 0 :(得分:0)

当手动运行vs systemd时,问题可能是当前工作目录的差异。使用的spawn调用documented默认为继承当前工作目录。

当通过shell运行时,那将是你当前所在的目录。在man systemd.exec中,你会发现“WorkingDirectory =`指令,它记录了systemd的默认当前工作目录:”当默认为根目录时systemd作为系统实例运行“。

因此,如果您的temperature.py位于/var/www/Raspberry-Pi-Status,请设置:

  workingDirectory=/var/www/Raspberry-Pi-Status in your `[Service]` section.