我有一个在raspberryPI上运行的nodeJS脚本,并将ip更新发送到ddns服务器。如果我以“ node ddnsupdater.js”之类的bash执行它,它将运行良好。但是,如果我将其安装为服务,则始终会一直使用多达99%的CPU(根据TOP),并且似乎根本不起作用(没有发送更新)。
ddnsupdater.js:
#!/usr/bin/env node
const https = require('https');
var minutes = 5, the_interval = minutes * 60 * 1000;
//Set up update timer
setInterval(function() {
console.log("I am doing my 5 minutes update");
updateIP();
}, the_interval);
function updateIP(){
const options = {
hostname: 'dynupdate.no-ip.com',
port: 443,
path: '/nic/update?hostname=' + hostname,
method: 'GET',
auth: username+':'+password
};
const req = https.request(options, (res) => {
console.log('statusCode:', res.statusCode);
res.on('data', (d) => {
console.log('Server response: ' + d);
});
});
req.on('error', (e) => {
console.error(e);
});
req.end();
}
//Run initial update
updateIP();
ddnsupdater.service:
[Unit]
Description=Dynamic DNS Updater Service
[Service]
ExecStart=/usr/local/ddnsupdater/ddnsupdater.js
Restart=always
User=nobody
# Note RHEL/Fedora uses 'nobody', Debian/Ubuntu uses 'nogroup'
Group=nogroup
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
WorkingDirectory=/usr/local/ddnsupdater
[Install]
WantedBy=multi-user.target