Skip to content

Instantly share code, notes, and snippets.

@ukitazume
Last active August 29, 2015 13:56
Show Gist options
  • Save ukitazume/8880034 to your computer and use it in GitHub Desktop.
Save ukitazume/8880034 to your computer and use it in GitHub Desktop.
// $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(){
})
}
}
}
});
@ukitazume
Copy link
Author

対象ファイルのオーナーが変わったら、nohup.outにtailとps auxが出力される。ファイルは再度deploy(1000)に変更するスクリプト。

const filePath = 'log/production.log';

に対象のファイルパスを記述します

$sudo nohup node owner_change_watcher.js &

でjobをはしらせます。

$sudo cat nohup.out

でログを確認します。

$sudo killall node

でプロセスを終了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment