Skip to content

Instantly share code, notes, and snippets.

@a-c-t-i-n-i-u-m
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a-c-t-i-n-i-u-m/f5397b938d945d9aa45a to your computer and use it in GitHub Desktop.
Save a-c-t-i-n-i-u-m/f5397b938d945d9aa45a to your computer and use it in GitHub Desktop.
recpt1 http serverをtvtest BonDriver_HTTP.dllをつかって起動/停止する
/**
* recpt1 http serverをtvtest BonDriver_HTTP.dllをつかって起動/停止する
* 目的:少ないチューナーをtvtestで見るときだけ占有するようにして精神的安定感を得る
*
* $ nohup node recpt1-http-manager.js > /dev/null 2>&1 &
*
* などでこのスクリプトを起動しておき、BonDriver_HTTP.iniに
*
* NAME_n="起動"
* HOST_n="[server IP address]"
* PORT_n=[settings.port + 1]
* PATH_n="/start"
*
* NAME_m="停止"
* HOST_m="[server IP address]"
* PORT_m=[settings.port + 1]
* PATH_m="/stop"
*
* のように設定
* チャンネルを切り替えるのと同じく「起動」「停止」を選局することで動作する
*
* settings.recpt1Path: http server対応のrecpt1のパス
* settings.recpt1Args: --http <port> をのぞく引数
* settings.port: recpt1 http serverのつかうポート(>=1024)
* settings.host: 待ち受けhost,
* 127.0.0.1でローカルのみ(リバースプロキシなどでつかうとき、おすすめ)
* 0.0.0.0で制限なし(あぶない)
*
* !利用は自己責任で!
*/
var child_process = require('child_process');
var http = require('http');
// settings
var settings = {
port: 8080,
host: '127.0.0.1',// '0.0.0.0',
recpt1Path: '/usr/local/bin/recpt1',
recpt1Args: [
'--b25',
'--strip',
].join(' '),
};
var recpt1Command = settings.recpt1Path + ' ' + settings.recpt1Args + ' --http ' + settings.port;
var onRequest = function (req, res) {
switch (req.url) {
case '/start':
try {
child_process.execSync(recpt1Command + ' > /dev/null 2>&1');
} catch (e) {
}
break;
case '/stop':
try {
var pid = child_process.execSync(
'ps aux | grep "' + recpt1Command + '" | head -n 1'
).toString().split(/\s+/);
if (pid[1]) {
child_process.execSync('kill -9 ' + pid[1]);
}
} catch (e) {
}
break;
}
res.writeHead(200);
res.end();
};
http.createServer(onRequest).listen(settings.port + 1, settings.host);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment