Skip to content

Instantly share code, notes, and snippets.

@beatgammit
Created September 12, 2011 16:43
Show Gist options
  • Save beatgammit/1211730 to your computer and use it in GitHub Desktop.
Save beatgammit/1211730 to your computer and use it in GitHub Desktop.
NPM bug when using outdated function as systemd service
#!/usr/bin/env node
(function () {
'use strict';
var npm = require('npm'),
fs = require('fs'),
updateTimeout,
seconds = 10;
function update(fd) {
updateTimeout = null;
console.log('Checking for updates');
fs.writeSync(fd, 'Checking for updates\n');
npm.commands.outdated(['bad-value'], function (err, data) {
if (err) {
console.log('err:', err);
fs.writeSync(fd, 'err: ' + err.toString());
}
if (updateTimeout) {
console.log('updateTimeout is non-null');
fs.writeSync(fd, 'updateTimeout is non-null\n');
return;
}
console.log('Calling recursively in ' + seconds + ' seconds');
updateTimeout = setTimeout(function () {
update(fd);
}, 1000 * seconds);
});
}
console.log('Create log file at "/dev/shm/npmbug.log"');
fs.open('/dev/shm/npmbug.log', 'a', function (err, fd) {
if (err) {
throw err;
}
// initialize npm in global mode
npm.load({'global': true}, function () { update(fd); });
});
}());
#!/bin/bash
if [ $UID != 0 ]
then
echo "Please run as root"
exit 1
fi
cp npmbug.service /lib/systemd/system/npmbug.service
[Unit]
Description=Simple example of a bug in npm's outdated function
Wants=network.target
After=network.target
[Service]
ExecStart=/usr/local/bin/npmbug
[Install]
WantedBy=multi-user.target
{
"author": "T. Jameson Little",
"name": "npmbug",
"description": "Shows bug in npm's outdated function",
"version": "0.0.0",
"repository": {
"url": ""
},
"main": "index.js",
"bin": {
"npmbug": "index.js"
},
"scripts": {
"install": "./install.sh"
},
"engines": {
"node": "~v0.4.10"
},
"dependencies": {
"npm": "~1"
},
"devDependencies": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment