Skip to content

Commit

Permalink
Merge pull request #17 from TUS-OSK/log-to-file
Browse files Browse the repository at this point in the history
logging
  • Loading branch information
ilim0t authored Jul 22, 2019
2 parents 14717e9 + 9b8e62d commit 5453141
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ disk
);

daemon(
`ffmpeg -i rtmp://localhost:1935/live/bushitsuchan -hls_flags delete_segments -codec:v copy -g 40 -f hls ${mountPath}/output.m3u8`,
`ffmpeg -i rtmp://localhost:1935/live/bushitsuchan -hls_flags delete_segments -g 40 -f hls ${mountPath}/output.m3u8`,
);

let ngrokUrl;
Expand Down
7 changes: 6 additions & 1 deletion utils.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
const childProcess = require('child_process');
const util = require('util');
const fs = require('fs');

const exec = util.promisify(childProcess.exec);

const wait = ms => new Promise(reolve => setTimeout(() => reolve(), ms));

module.exports.daemon = async (command, ms = 1000 * 10, maxCount = 100) => {
const logger = new console.Console(
fs.createWriteStream('out.log'),
fs.createWriteStream('err.log'),
);
console.log(`start daemon ${command.slice(0, 40)}...`);
for (let i = 0; i < maxCount; i += 1) {
try {
// eslint-disable-next-line no-await-in-loop
await exec(command);
} catch (e) {
console.error(e);
logger.error(e);
// eslint-disable-next-line no-await-in-loop
await wait(ms);
}
Expand Down

0 comments on commit 5453141

Please sign in to comment.