Created
March 5, 2010 02:43
-
-
Save clofresh/322407 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var sys = require('sys') | |
var filename = process.ARGV[2]; | |
if (!filename) | |
return sys.puts("Usage: node monitor_memcached.js /path/to/memcached.log"); | |
// Look at http://nodejs.org/api.html#_child_processes for detail. | |
var tail = process.createChildProcess("tail", ["-f", filename]); | |
sys.puts("Monitoring " + filename); | |
tail.addListener("output", function (data) { | |
if(data == "event_add: No such file or directory\n") { | |
sys.exec("/etc/init.d/memcached restart", function(err, stdout, stderr){ | |
if(err) { | |
sys.puts(stdout); | |
sys.puts(stderr); | |
} else { | |
sys.puts(stdout); | |
sys.puts('memcached restarted'); | |
} | |
}) | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment