[英]CGI Bash script to spawn daemon process
I am working on a project to stream HDTV from a personal computer to devices supporting HTTP Live Streaming (think iOS devices and some android). 我正在做一个项目,目的是将HDTV从个人计算机流化到支持HTTP Live Streaming的设备(想想iOS设备和某些android)。 I have the formatting of the video and the streaming aspects down.
我已经将视频的格式和流媒体方面的内容整理了下来。 What I am now trying to implement is an easy way to change the channel remotely.
我现在尝试实现的是一种轻松地远程更改频道的方法。
My current method involves connecting via SSH to kill the old stream and begin a new stream. 我当前的方法涉及通过SSH连接杀死旧流并开始新流。 This works, but isn't pretty.
这有效,但不是很漂亮。 I want something my Mom or girlfriend could use.
我想要妈妈或女友可以使用的东西。 I decided I would build an HTML5 app that would issue the channel switching over CGI scripts.
我决定我将构建一个HTML5应用程序,该应用程序将发布频道切换CGI脚本。 I currently have a parent process with a form that calls a child process to decide if the stream is running and then a subchild process to actually tune the stream.
我目前有一个父进程,该窗体具有一个窗体,该窗体调用子进程来确定流是否正在运行,然后再调用一个子进程来实际调整该流。
As I am streaming live video from my computer I need the subchild process to run indefinitely. 当我从计算机流式传输实时视频时,我需要子进程无限期地运行。 Unfortunately it seems that when my parent process is finished the background process started in the subchild process terminates.
不幸的是,当我的父进程完成时,子进程中启动的后台进程似乎终止了。
I have tried a simple &, using nohup, setsid, and daemon. 我尝试了一个简单的&,使用nohup,setsid和daemon。 daemon runs cleanest but still terminates when the parent finishes.
守护程序运行得最干净,但在父进程完成时仍会终止。 even with a -r flag.
即使带有-r标志。 I'll place my code below and maybe someone will have an idea on how I could implement this or a better way to achieve the same thing?
我将代码放在下面,也许有人会对如何实现此方法或实现相同目标的更好方法有所了解? Thanks!
谢谢! (oh and i know killing vlc is not a pretty way to kill the stream, if you have a better way i'm all ears)
(哦,我知道杀死vlc并不是杀死流的一种漂亮方法,如果您有更好的方法,那么我将不胜枚举)
parent invoking child:
----------------------
./ChangeChannel.sh $channel #passed from form submission
child (ChangeChannel.sh):
-------------------------
#!/bin/bash
directory=./Channels/
newchannel=$1
if [ $(pidof vlc) ]
then
sudo kill $(pidof vlc)
fi
daemon -r -v -d $directory$newchannel &
subchild example:
-----------------
vlc atsc://frequency=605029000 --intf=dummy --sout-transcode-audio-sync :live-cache=3000 --sout='#transcode{vcodec=h264,vb=150,fps=25,width=480,scale=1,venc=x264{aud,profile=baseline,level=30,keyint=15,bframes=0,ref=1},acodec=aac,ab=40,channels=2,samplerate=22050}:duplicate{dst=std{mux=ts,dst=-,access=livehttp{seglen=16,delsegs=true,numsegs=10,index=/var/www/stream/live.m3u8,index-url=content/live-######.ts},mux=ts{use-key-frames},dst=/var/www/stream/content/live-######.ts,ratecontrol=true}}'
how can i keep the subchild from terminating??? 我如何防止子孩子终止??? Running Apache on Ubuntu 12.04
在Ubuntu 12.04上运行Apache
I got it! 我知道了!
For anyone interested in how, i changed my tactics to use nohup, &, disown, and > /dev/null 2>&1. 对于任何对此感兴趣的人,我都改变了使用nohup,&,disown和> / dev / null 2>&1的策略。
Honestly, still not quite sure how I got it working... just a lot of trial and error with some educated guesses. 老实说,仍然不太确定我是如何工作的……只是经过反复尝试和一些有根据的猜测。 My code follows:
我的代码如下:
parent invocation:
------------------
nohup ./ChangeChannel.sh $channel & disown
child invocation:
-----------------
sudo nohup su user $directory$newchannel &> /dev/null 2>&1
subchild invocation:
--------------------
vlc atsc://frequency=605029000 --intf=dummy --sout-transcode-audio-sync :live-cache=3000 --sout='#transcode{vcodec=h264,vb=150,fps=25,width=480,scale=1,venc=x264{aud,profile=baseline,level=30,keyint=15,bframes=0,ref=1},acodec=aac,ab=40,channels=2,samplerate=22050}:duplicate{dst=std{mux=ts,dst=-,access=livehttp{seglen=16,delsegs=true,numsegs=10,index=/var/www/stream/live.m3u8,index-url=content/live-######.ts},mux=ts{use-key-frames},dst=/var/www/stream/content/live-######.ts,ratecontrol=true}}' & disown
ChangeChannel.sh uses sudo to execute su via cgi in order to execute vlc as user other than root. ChangeChannel.sh使用sudo通过cgi执行su,以便以root用户以外的用户身份执行vlc。 It seems a little messy but hell it works.
看起来有点混乱,但是它确实可行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.