Last active
August 29, 2015 13:56
-
-
Save ukitazume/8880034 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
// $nohup node owner_change_watcher.js & | |
// set file target log | |
const filePath = 'log/production.log'; | |
const fs = require('fs'); | |
const process = require('child_process'); | |
fs.watchFile(filePath, function(cur, pre){ | |
for (var key in cur) { | |
if (cur[key] !== pre[key]) { | |
if (key === 'uid') { | |
console.log(new Date()); | |
console.log(key + " => cur:" + cur[key] + "; pre: " + pre[key]); | |
process.exec('tail -100 ' + filePath, function(err, stdout, stderr){ | |
console.log("--------- tail ----------"); | |
console.log(stdout.toString()); | |
}); | |
process.exec('ps aux | grep root', function(err, stdout, stderr){ | |
console.log("-------- ps aux ---------"); | |
console.log(stdout.toString()); | |
}); | |
fs.chown(filePath, 1000, 1000, function(){ | |
}) | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
対象ファイルのオーナーが変わったら、nohup.outにtailとps auxが出力される。ファイルは再度deploy(1000)に変更するスクリプト。
に対象のファイルパスを記述します
でjobをはしらせます。
でログを確認します。
でプロセスを終了