Install:
Debian 9.1 container
4 cores, 10 GB disk, 1 GB RAM, 512 MB swap

adduser tdobes
adduser tdobes adm
adduser tdobes systemd-journal
adduser ssumichrast
adduser ssumichrast adm
adduser ssumichrast systemd-journal

aptitude --without-recommends install ffmpeg
aptitude --without-recommends install icecast2 ezstream
# say no to question about configuring icecast2
sed -i 's|<location>Earth</location>|<location>US</location>|g; s|<admin>icemaster@localhost</admin>|<admin>t.dobes@mcpstars.org</admin>|g; s|<sources>2</sources>|<sources>5</sources>|g; s/hackme/**PASSWORD**/g; s|<hostname>localhost</hostname>|<hostname>live.glpa.org</hostname>|g' /etc/icecast2/icecast.xml
sed -i 's/ENABLE=false/ENABLE=true/g' /etc/default/icecast2
systemctl restart icecast2
systemctl enable icecast2

aptitude install build-essential git
apt-get build-dep nginx-full

^D (go back to non-root user)
mkdir build
cd build
apt-get source nginx-full
cd nginx-*/debian/modules
git clone git://github.com/arut/nginx-rtmp-module.git
cd ..
vi rules
## put this at the end of full_configure_flags:
## --add-module=$(MODULESDIR)/nginx-rtmp-module
cd ..
FLAVOURS=full dpkg-buildpackage -b
cd ..

su (become root again)
dpkg -i nginx-common_*.deb nginx-full_*.deb libnginx-mod-http-auth-pam_*.deb libnginx-mod-http-dav-ext_*.deb libnginx-mod-http-echo_*.deb libnginx-mod-http-geoip_*.deb libnginx-mod-http-image-filter_*.deb libnginx-mod-http-subs-filter_*.deb libnginx-mod-http-upstream-fair_*.deb libnginx-mod-http-xslt-filter_*.deb libnginx-mod-mail_*.deb libnginx-mod-stream_*.deb
aptitude hold nginx-full # needed to ensure that unattended upgrades doesn't install the non-rtmp version
aptitude --without-recommends install fcgiwrap

sed -i 's/worker_processes auto;/#worker_processes auto;\nworker_processes 1;/g; s/\tworker_connections 768;/\tworker_connections 768;\n\tuse epoll;/g' /etc/nginx/nginx.conf

echo >> /etc/nginx/nginx.conf
echo 'include /etc/nginx/rtmp.conf;' >> /etc/nginx/nginx.conf

cat > /etc/nginx/rtmp.conf
#rtmp_auto_push on;

rtmp {
  server {
    listen 1935;
    ping 10s;
    ping_timeout 5s;
    drop_idle_publisher 10s;
    application live1 {
      live on;
      wait_video on;
      #publish_notify on;
      meta copy;

      # launch relays and transcoders through systemd
      exec_publish /usr/local/bin/handle_rtmp_stream.sh start $app $name $addr;
      exec_publish_done /usr/local/bin/handle_rtmp_stream.sh stop $app $name $addr;
    }
    application live2 {
      live on;
      wait_video on;
      #publish_notify on;
      meta copy;

      # launch relays and transcoders through systemd
      exec_publish /usr/local/bin/handle_rtmp_stream.sh start $app $name $addr;
      exec_publish_done /usr/local/bin/handle_rtmp_stream.sh stop $app $name $addr;
    }
    application live3 {
      live on;
      wait_video on;
      #publish_notify on;
      meta copy;

      # launch relays and transcoders through systemd
      exec_publish /usr/local/bin/handle_rtmp_stream.sh start $app $name $addr;
      exec_publish_done /usr/local/bin/handle_rtmp_stream.sh stop $app $name $addr;
    }
    application tom {
      live on;
      wait_video on;
      #publish_notify on;
      meta copy;

      # launch relays and transcoders through systemd
      exec_publish /usr/local/bin/handle_rtmp_stream.sh start $app $name $addr;
      exec_publish_done /usr/local/bin/handle_rtmp_stream.sh stop $app $name $addr;
    }
    application hls {
      live on;
      hls on;
      hls_path /dev/shm/hls;
      hls_fragment 2s;
      hls_playlist_length 6s;
    }
  }
}
^D

cat > /usr/local/bin/handle_rtmp_stream.sh
#!/bin/sh

# $1 = operation (start, stop)
# $2 = app (live1, live2, live3, tom)
# $3 = stream (live)
# $4 = remote IP (stream source)

case "$1" in
  "start")
    logger "RTMP stream starting - $2 $3 (from $4)"
    sudo systemctl start "rtmp-$2-$3.target"
    ;;
  "stop")
    logger "RTMP stream stopping - $2 $3 (from $4)"
    sudo systemctl stop "rtmp-$2-$3.target"
    ;;
  *)
    echo ERROR: Unrecognized parameter!
    exit 1
esac

exit 0
^D
chmod +x /usr/local/bin/handle_rtmp_stream.sh

cp -a ~tdobes/build/nginx-*/debian/modules/nginx-rtmp-module/stat.xsl /var/www/html/
rm /etc/nginx/sites-enabled/default

cat > /etc/nginx/sites-enabled/stream
server {
  listen 80 default_server;
  listen [::]:80 default_server ipv6only=on;

  root /var/www/html;
  index index.html;

  server_name _;

  location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    try_files $uri $uri/ =404;
  }

  real_ip_header X-Forwarded-For;
  set_real_ip_from 192.168.222.4;

  location /http-stat {
    stub_status on;
  }

  location /stat.xsl {
    root /var/www/html;
  }

  location /stat {
    rtmp_stat all;
    rtmp_stat_stylesheet stat.xsl;
  }

  location /control {
    rtmp_control all;
  }

  location /hls {
    # Serve HLS fragments
    types {
      application/vnd.apple.mpegurl m3u8;
      video/mp2t ts;
    }
    root /dev/shm;
    add_header Cache-Control no-cache;
    add_header 'Access-Control-Allow-Origin' '*';
  }

  #location /dash {
  #  root /dev/shm;
  #  add_header Cache-Control no-cache;
  #}

  location ~ ^/cgi-bin/.*$ {
    gzip           off;
    root           /var/www/html;
    fastcgi_pass   unix:/run/fcgiwrap.socket;
    # include      fastcgi_params;
    fastcgi_param  QUERY_STRING       $query_string;
    fastcgi_param  REQUEST_METHOD     $request_method;
    fastcgi_param  CONTENT_TYPE       $content_type;
    fastcgi_param  CONTENT_LENGTH     $content_length;

    fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
    fastcgi_param  REQUEST_URI        $request_uri;
    fastcgi_param  DOCUMENT_URI       $document_uri;
    fastcgi_param  DOCUMENT_ROOT      $document_root;
    fastcgi_param  SERVER_PROTOCOL    $server_protocol;

    fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
    fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

    fastcgi_param  REMOTE_ADDR        $remote_addr;
    fastcgi_param  REMOTE_PORT        $remote_port;
    fastcgi_param  SERVER_ADDR        $server_addr;
    fastcgi_param  SERVER_PORT        $server_port;

    # According to RFC3875 (https://tools.ietf.org/html/rfc3875#section-4.1.14) in SERVER_NAME
    # we should put actual hostname user came to. For nginx it is in $host
    # This will allow to run multihost instances
    fastcgi_param  SERVER_NAME        $host;
  }
}
^D

mkdir -p /etc/systemd/system/nginx.service.d
echo '[Service]' > /etc/systemd/system/nginx.service.d/autorestart.conf
echo 'Restart=always' >> /etc/systemd/system/nginx.service.d/autorestart.conf
echo 'RestartSec=1' >> /etc/systemd/system/nginx.service.d/autorestart.conf
echo 'StartLimitInterval=10s' >> /etc/systemd/system/nginx.service.d/autorestart.conf
echo 'StartLimitBurst=10' >> /etc/systemd/system/nginx.service.d/autorestart.conf
systemctl daemon-reload
systemctl restart nginx.service

aptitude install sudo
echo >> /etc/sudoers
echo 'www-data ALL=(ALL:ALL) NOPASSWD:/bin/systemctl' >> /etc/sudoers

echo '[Unit]' > /etc/systemd/system/rtmp-live1-live.target
echo 'Description=Receiving live1 RTMP stream' >> /etc/systemd/system/rtmp-live1-live.target
echo 'Requires=nginx.service' >> /etc/systemd/system/rtmp-live1-live.target
echo '[Unit]' > /etc/systemd/system/rtmp-live2-live.target
echo 'Description=Receiving live2 RTMP stream' >> /etc/systemd/system/rtmp-live2-live.target
echo 'Requires=nginx.service' >> /etc/systemd/system/rtmp-live2-live.target
echo '[Unit]' > /etc/systemd/system/rtmp-live3-live.target
echo 'Description=Receiving live3 RTMP stream' >> /etc/systemd/system/rtmp-live3-live.target
echo 'Requires=nginx.service' >> /etc/systemd/system/rtmp-live3-live.target
echo '[Unit]' > /etc/systemd/system/rtmp-tom-live.target
echo 'Description=Receiving tom RTMP stream' >> /etc/systemd/system/rtmp-tom-live.target
echo 'Requires=nginx.service' >> /etc/systemd/system/rtmp-tom-live.target

echo '[Unit]' > /etc/systemd/system/live1-hls.service
echo 'Description=live1 stream - split for HLS' >> /etc/systemd/system/live1-hls.service
echo 'PartOf=rtmp-live1-live.target' >> /etc/systemd/system/live1-hls.service
echo >> /etc/systemd/system/live1-hls.service
echo '[Service]' >> /etc/systemd/system/live1-hls.service
echo 'ExecStart=/usr/bin/ffmpeg -nostats -re -fflags nobuffer -i rtmp://127.0.0.1/live1/live -acodec copy -vcodec copy -f flv rtmp://127.0.0.1/hls/live1' >> /etc/systemd/system/live1-hls.service
echo 'SuccessExitStatus=255' >> /etc/systemd/system/live1-hls.service
echo 'User=nobody' >> /etc/systemd/system/live1-hls.service
echo >> /etc/systemd/system/live1-hls.service
echo 'Restart=always' >> /etc/systemd/system/live1-hls.service
echo 'RestartSec=1' >> /etc/systemd/system/live1-hls.service
echo 'StartLimitInterval=10s' >> /etc/systemd/system/live1-hls.service
echo 'StartLimitBurst=10' >> /etc/systemd/system/live1-hls.service
echo >> /etc/systemd/system/live1-hls.service
echo '[Install]' >> /etc/systemd/system/live1-hls.service
echo 'WantedBy=rtmp-live1-live.target' >> /etc/systemd/system/live1-hls.service
systemctl enable live1-hls.service
echo '[Unit]' > /etc/systemd/system/live2-hls.service
echo 'Description=live2 stream - split for HLS' >> /etc/systemd/system/live2-hls.service
echo 'PartOf=rtmp-live2-live.target' >> /etc/systemd/system/live2-hls.service
echo >> /etc/systemd/system/live2-hls.service
echo '[Service]' >> /etc/systemd/system/live2-hls.service
echo 'ExecStart=/usr/bin/ffmpeg -nostats -re -fflags nobuffer -i rtmp://127.0.0.1/live2/live -acodec copy -vcodec copy -f flv rtmp://127.0.0.1/hls/live2' >> /etc/systemd/system/live2-hls.service
echo 'SuccessExitStatus=255' >> /etc/systemd/system/live2-hls.service
echo 'User=nobody' >> /etc/systemd/system/live2-hls.service
echo >> /etc/systemd/system/live2-hls.service
echo 'Restart=always' >> /etc/systemd/system/live2-hls.service
echo 'RestartSec=1' >> /etc/systemd/system/live2-hls.service
echo 'StartLimitInterval=10s' >> /etc/systemd/system/live2-hls.service
echo 'StartLimitBurst=10' >> /etc/systemd/system/live2-hls.service
echo >> /etc/systemd/system/live2-hls.service
echo '[Install]' >> /etc/systemd/system/live2-hls.service
echo 'WantedBy=rtmp-live2-live.target' >> /etc/systemd/system/live2-hls.service
systemctl enable live2-hls.service
echo '[Unit]' > /etc/systemd/system/live3-hls.service
echo 'Description=live3 stream - split for HLS' >> /etc/systemd/system/live3-hls.service
echo 'PartOf=rtmp-live3-live.target' >> /etc/systemd/system/live3-hls.service
echo >> /etc/systemd/system/live3-hls.service
echo '[Service]' >> /etc/systemd/system/live3-hls.service
echo 'ExecStart=/usr/bin/ffmpeg -nostats -re -fflags nobuffer -i rtmp://127.0.0.1/live3/live -acodec copy -vcodec copy -f flv rtmp://127.0.0.1/hls/live3' >> /etc/systemd/system/live3-hls.service
echo 'SuccessExitStatus=255' >> /etc/systemd/system/live3-hls.service
echo 'User=nobody' >> /etc/systemd/system/live3-hls.service
echo >> /etc/systemd/system/live3-hls.service
echo 'Restart=always' >> /etc/systemd/system/live3-hls.service
echo 'RestartSec=1' >> /etc/systemd/system/live3-hls.service
echo 'StartLimitInterval=10s' >> /etc/systemd/system/live3-hls.service
echo 'StartLimitBurst=10' >> /etc/systemd/system/live3-hls.service
echo >> /etc/systemd/system/live3-hls.service
echo '[Install]' >> /etc/systemd/system/live3-hls.service
echo 'WantedBy=rtmp-live3-live.target' >> /etc/systemd/system/live3-hls.service
systemctl enable live3-hls.service
echo '[Unit]' > /etc/systemd/system/tom-hls.service
echo 'Description=tom stream - split for HLS' >> /etc/systemd/system/tom-hls.service
echo 'PartOf=rtmp-tom-live.target' >> /etc/systemd/system/tom-hls.service
echo >> /etc/systemd/system/tom-hls.service
echo '[Service]' >> /etc/systemd/system/tom-hls.service
echo 'ExecStart=/usr/bin/ffmpeg -nostats -re -fflags nobuffer -i rtmp://127.0.0.1/tom/live -acodec copy -vcodec copy -f flv rtmp://127.0.0.1/hls/tom' >> /etc/systemd/system/tom-hls.service
echo 'SuccessExitStatus=255' >> /etc/systemd/system/tom-hls.service
echo 'User=nobody' >> /etc/systemd/system/tom-hls.service
echo >> /etc/systemd/system/tom-hls.service
echo 'Restart=always' >> /etc/systemd/system/tom-hls.service
echo 'RestartSec=1' >> /etc/systemd/system/tom-hls.service
echo 'StartLimitInterval=10s' >> /etc/systemd/system/tom-hls.service
echo 'StartLimitBurst=10' >> /etc/systemd/system/tom-hls.service
echo >> /etc/systemd/system/tom-hls.service
echo '[Install]' >> /etc/systemd/system/tom-hls.service
echo 'WantedBy=rtmp-tom-live.target' >> /etc/systemd/system/tom-hls.service
systemctl enable tom-hls.service

mkdir -p /etc/ezstream
echo '<ezstream>' > /etc/ezstream/live1.xml
echo '  <url>http://127.0.0.1:8000/live.mp3</url>' >> /etc/ezstream/live1.xml
echo '  <sourcepassword>**PASSWORD**</sourcepassword>' >> /etc/ezstream/live1.xml
echo '  <format>MP3</format>' >> /etc/ezstream/live1.xml
echo '  <filename>stdin</filename>' >> /etc/ezstream/live1.xml
echo '  <stream_once>1</stream_once>' >> /etc/ezstream/live1.xml
echo '  <svrinfoname>GLPA Conference Stream 1</svrinfoname>' >> /etc/ezstream/live1.xml
echo '  <svrinfourl>http://live.glpa.org</svrinfourl>' >> /etc/ezstream/live1.xml
echo '  <svrinfogenre>Talk</svrinfogenre>' >> /etc/ezstream/live1.xml
echo '  <svrinfodescription>See http://live.glpa.org/ for conference schedule.</svrinfodescription>' >> /etc/ezstream/live1.xml
echo '  <svrinfobitrate>96</svrinfobitrate>' >> /etc/ezstream/live1.xml
echo '  <svrinfochannels>2</svrinfochannels>' >> /etc/ezstream/live1.xml
echo '  <svrinfosamplerate>44100</svrinfosamplerate>' >> /etc/ezstream/live1.xml
echo '  <svrinfopublic>0</svrinfopublic>' >> /etc/ezstream/live1.xml
echo '</ezstream>' >> /etc/ezstream/live1.xml
echo '<ezstream>' > /etc/ezstream/live2.xml
echo '  <url>http://localhost:8000/live2.mp3</url>' >> /etc/ezstream/live2.xml
echo '  <sourcepassword>**PASSWORD**</sourcepassword>' >> /etc/ezstream/live2.xml
echo '  <format>MP3</format>' >> /etc/ezstream/live2.xml
echo '  <filename>stdin</filename>' >> /etc/ezstream/live2.xml
echo '  <stream_once>1</stream_once>' >> /etc/ezstream/live2.xml
echo '  <svrinfoname>GLPA Conference Stream 2</svrinfoname>' >> /etc/ezstream/live2.xml
echo '  <svrinfourl>http://live.glpa.org</svrinfourl>' >> /etc/ezstream/live2.xml
echo '  <svrinfogenre>Talk</svrinfogenre>' >> /etc/ezstream/live2.xml
echo '  <svrinfodescription>See http://live.glpa.org/ for conference schedule.</svrinfodescription>' >> /etc/ezstream/live2.xml
echo '  <svrinfobitrate>96</svrinfobitrate>' >> /etc/ezstream/live2.xml
echo '  <svrinfochannels>2</svrinfochannels>' >> /etc/ezstream/live2.xml
echo '  <svrinfosamplerate>44100</svrinfosamplerate>' >> /etc/ezstream/live2.xml
echo '  <svrinfopublic>0</svrinfopublic>' >> /etc/ezstream/live2.xml
echo '</ezstream>' >> /etc/ezstream/live2.xml
echo '<ezstream>' > /etc/ezstream/live3.xml
echo '  <url>http://localhost:8000/live3.mp3</url>' >> /etc/ezstream/live3.xml
echo '  <sourcepassword>**PASSWORD**</sourcepassword>' >> /etc/ezstream/live3.xml
echo '  <format>MP3</format>' >> /etc/ezstream/live3.xml
echo '  <filename>stdin</filename>' >> /etc/ezstream/live3.xml
echo '  <stream_once>1</stream_once>' >> /etc/ezstream/live3.xml
echo '  <svrinfoname>GLPA Conference Stream 3</svrinfoname>' >> /etc/ezstream/live3.xml
echo '  <svrinfourl>http://live.glpa.org</svrinfourl>' >> /etc/ezstream/live3.xml
echo '  <svrinfogenre>Talk</svrinfogenre>' >> /etc/ezstream/live3.xml
echo '  <svrinfodescription>See http://live.glpa.org/ for conference schedule.</svrinfodescription>' >> /etc/ezstream/live3.xml
echo '  <svrinfobitrate>96</svrinfobitrate>' >> /etc/ezstream/live3.xml
echo '  <svrinfochannels>2</svrinfochannels>' >> /etc/ezstream/live3.xml
echo '  <svrinfosamplerate>44100</svrinfosamplerate>' >> /etc/ezstream/live3.xml
echo '  <svrinfopublic>0</svrinfopublic>' >> /etc/ezstream/live3.xml
echo '</ezstream>' >> /etc/ezstream/live3.xml

echo '[Unit]' > /etc/systemd/system/live1-audio.service
echo 'Description=live1 stream - generate audio stream' >> /etc/systemd/system/live1-audio.service
echo 'Requires=icecast2.service' >> /etc/systemd/system/live1-audio.service
echo 'PartOf=rtmp-live1-live.target' >> /etc/systemd/system/live1-audio.service
echo >> /etc/systemd/system/live1-audio.service
echo '[Service]' >> /etc/systemd/system/live1-audio.service
echo "ExecStart=/bin/sh -c '/usr/bin/ffmpeg -nostats -re -fflags nobuffer -i rtmp://127.0.0.1/live1/live -vcodec none -acodec libmp3lame -ar 44100 -ac 2 -ab 96k -f mp3 - | ezstream -c /etc/ezstream/live1.xml'" >> /etc/systemd/system/live1-audio.service
echo 'User=nobody' >> /etc/systemd/system/live1-audio.service
echo >> /etc/systemd/system/live1-audio.service
echo 'Restart=always' >> /etc/systemd/system/live1-audio.service
echo 'RestartSec=1' >> /etc/systemd/system/live1-audio.service
echo 'StartLimitInterval=10s' >> /etc/systemd/system/live1-audio.service
echo 'StartLimitBurst=10' >> /etc/systemd/system/live1-audio.service
echo >> /etc/systemd/system/live1-audio.service
echo '[Install]' >> /etc/systemd/system/live1-audio.service
echo 'WantedBy=rtmp-live1-live.target' >> /etc/systemd/system/live1-audio.service
systemctl enable live1-audio.service
echo '[Unit]' > /etc/systemd/system/live2-audio.service
echo 'Description=live2 stream - generate audio stream' >> /etc/systemd/system/live2-audio.service
echo 'Requires=icecast2.service' >> /etc/systemd/system/live2-audio.service
echo 'PartOf=rtmp-live2-live.target' >> /etc/systemd/system/live2-audio.service
echo >> /etc/systemd/system/live2-audio.service
echo '[Service]' >> /etc/systemd/system/live2-audio.service
echo "ExecStart=/bin/sh -c '/usr/bin/ffmpeg -nostats -re -fflags nobuffer -i rtmp://127.0.0.1/live2/live -vcodec none -acodec libmp3lame -ar 44100 -ac 2 -ab 96k -f mp3 - | ezstream -c /etc/ezstream/live2.xml'" >> /etc/systemd/system/live2-audio.service
echo 'User=nobody' >> /etc/systemd/system/live2-audio.service
echo >> /etc/systemd/system/live2-audio.service
echo 'Restart=always' >> /etc/systemd/system/live2-audio.service
echo 'RestartSec=1' >> /etc/systemd/system/live2-audio.service
echo 'StartLimitInterval=10s' >> /etc/systemd/system/live2-audio.service
echo 'StartLimitBurst=10' >> /etc/systemd/system/live2-audio.service
echo >> /etc/systemd/system/live2-audio.service
echo '[Install]' >> /etc/systemd/system/live2-audio.service
echo 'WantedBy=rtmp-live2-live.target' >> /etc/systemd/system/live2-audio.service
systemctl enable live2-audio.service
echo '[Unit]' > /etc/systemd/system/live3-audio.service
echo 'Description=live3 stream - generate audio stream' >> /etc/systemd/system/live3-audio.service
echo 'Requires=icecast2.service' >> /etc/systemd/system/live3-audio.service
echo 'PartOf=rtmp-live3-live.target' >> /etc/systemd/system/live3-audio.service
echo >> /etc/systemd/system/live3-audio.service
echo '[Service]' >> /etc/systemd/system/live3-audio.service
echo "ExecStart=/bin/sh -c '/usr/bin/ffmpeg -nostats -re -fflags nobuffer -i rtmp://127.0.0.1/live3/live -vcodec none -acodec libmp3lame -ar 44100 -ac 2 -ab 96k -f mp3 - | ezstream -c /etc/ezstream/live3.xml'" >> /etc/systemd/system/live3-audio.service
echo 'User=nobody' >> /etc/systemd/system/live3-audio.service
echo >> /etc/systemd/system/live3-audio.service
echo 'Restart=always' >> /etc/systemd/system/live3-audio.service
echo 'RestartSec=1' >> /etc/systemd/system/live3-audio.service
echo 'StartLimitInterval=10s' >> /etc/systemd/system/live3-audio.service
echo 'StartLimitBurst=10' >> /etc/systemd/system/live3-audio.service
echo >> /etc/systemd/system/live3-audio.service
echo '[Install]' >> /etc/systemd/system/live3-audio.service
echo 'WantedBy=rtmp-live3-live.target' >> /etc/systemd/system/live3-audio.service
systemctl enable live3-audio.service

echo 'LIVE1_USTREAM_URL=rtmp://1.16165896.fme.ustream.tv/ustreamVideo/16165896/**PASSWORD**' > /var/local/ustream_urls.txt
chown tdobes:www-data /var/local/ustream_urls.txt
chmod 664 /var/local/ustream_urls.txt
echo '[Unit]' > /etc/systemd/system/live1-ustream.service
echo 'Description=live1 stream - relay to Ustream' >> /etc/systemd/system/live1-ustream.service
echo 'PartOf=rtmp-live1-live.target' >> /etc/systemd/system/live1-ustream.service
echo >> /etc/systemd/system/live1-ustream.service
echo '[Service]' >> /etc/systemd/system/live1-ustream.service
echo 'EnvironmentFile=/var/local/ustream_urls.txt' >> /etc/systemd/system/live1-ustream.service
echo 'ExecStart=/usr/bin/ffmpeg -nostats -re -fflags nobuffer -i rtmp://127.0.0.1/live1/live -acodec copy -vcodec copy -f flv ${LIVE1_USTREAM_URL}' >> /etc/systemd/system/live1-ustream.service
echo 'SuccessExitStatus=255' >> /etc/systemd/system/live1-ustream.service
echo 'User=nobody' >> /etc/systemd/system/live1-ustream.service
echo >> /etc/systemd/system/live1-ustream.service
echo 'Restart=always' >> /etc/systemd/system/live1-ustream.service
echo 'RestartSec=1' >> /etc/systemd/system/live1-ustream.service
echo 'StartLimitInterval=10s' >> /etc/systemd/system/live1-ustream.service
echo 'StartLimitBurst=10' >> /etc/systemd/system/live1-ustream.service
echo >> /etc/systemd/system/live1-ustream.service
echo '[Install]' >> /etc/systemd/system/live1-ustream.service
echo 'WantedBy=rtmp-live1-live.target' >> /etc/systemd/system/live1-ustream.service
systemctl enable live1-ustream.service

echo 'LIVE1_YOUTUBE_URL=rtmp://a.rtmp.youtube.com/live2/**PASSWORD**' > /var/local/youtube_urls.txt
echo 'LIVE2_YOUTUBE_URL=rtmp://a.rtmp.youtube.com/live2/**PASSWORD**' >> /var/local/youtube_urls.txt
echo 'LIVE3_YOUTUBE_URL=rtmp://a.rtmp.youtube.com/live2/**PASSWORD**' >> /var/local/youtube_urls.txt
chown tdobes:www-data /var/local/youtube_urls.txt
chmod 664 /var/local/youtube_urls.txt
echo '[Unit]' > /etc/systemd/system/live1-youtube.service
echo 'Description=live1 stream - relay to YouTube' >> /etc/systemd/system/live1-youtube.service
echo 'PartOf=rtmp-live1-live.target' >> /etc/systemd/system/live1-youtube.service
echo >> /etc/systemd/system/live1-youtube.service
echo '[Service]' >> /etc/systemd/system/live1-youtube.service
echo 'EnvironmentFile=/var/local/youtube_urls.txt' >> /etc/systemd/system/live1-youtube.service
echo 'ExecStart=/usr/bin/ffmpeg -nostats -re -fflags nobuffer -i rtmp://127.0.0.1/live1/live -vcodec libx264 -preset veryfast -maxrate 2500k -bufsize 8192k -crf 21 -pix_fmt yuv420p -vf fps=30 -g 60 -acodec copy -f flv ${LIVE1_YOUTUBE_URL}' >> /etc/systemd/system/live1-youtube.service
echo 'SuccessExitStatus=255' >> /etc/systemd/system/live1-youtube.service
echo 'User=nobody' >> /etc/systemd/system/live1-youtube.service
echo >> /etc/systemd/system/live1-youtube.service
echo 'Restart=always' >> /etc/systemd/system/live1-youtube.service
echo 'RestartSec=1' >> /etc/systemd/system/live1-youtube.service
echo 'StartLimitInterval=10s' >> /etc/systemd/system/live1-youtube.service
echo 'StartLimitBurst=10' >> /etc/systemd/system/live1-youtube.service
echo >> /etc/systemd/system/live1-youtube.service
echo '[Install]' >> /etc/systemd/system/live1-youtube.service
echo 'WantedBy=rtmp-live1-live.target' >> /etc/systemd/system/live1-youtube.service
#systemctl enable live1-youtube.service
echo '[Unit]' > /etc/systemd/system/live2-youtube.service
echo 'Description=live2 stream - relay to YouTube' >> /etc/systemd/system/live2-youtube.service
echo 'PartOf=rtmp-live2-live.target' >> /etc/systemd/system/live2-youtube.service
echo >> /etc/systemd/system/live2-youtube.service
echo '[Service]' >> /etc/systemd/system/live2-youtube.service
echo 'EnvironmentFile=/var/local/youtube_urls.txt' >> /etc/systemd/system/live2-youtube.service
echo 'ExecStart=/usr/bin/ffmpeg -nostats -re -fflags nobuffer -i rtmp://127.0.0.1/live2/live -vcodec libx264 -preset veryfast -maxrate 2500k -bufsize 8192k -crf 21 -pix_fmt yuv420p -vf fps=30 -g 60 -acodec copy -f flv ${LIVE2_YOUTUBE_URL}' >> /etc/systemd/system/live2-youtube.service
echo 'SuccessExitStatus=255' >> /etc/systemd/system/live2-youtube.service
echo 'User=nobody' >> /etc/systemd/system/live2-youtube.service
echo >> /etc/systemd/system/live2-youtube.service
echo 'Restart=always' >> /etc/systemd/system/live2-youtube.service
echo 'RestartSec=1' >> /etc/systemd/system/live2-youtube.service
echo 'StartLimitInterval=10s' >> /etc/systemd/system/live2-youtube.service
echo 'StartLimitBurst=10' >> /etc/systemd/system/live2-youtube.service
echo >> /etc/systemd/system/live2-youtube.service
echo '[Install]' >> /etc/systemd/system/live2-youtube.service
echo 'WantedBy=rtmp-live2-live.target' >> /etc/systemd/system/live2-youtube.service
#systemctl enable live2-youtube.service
echo '[Unit]' > /etc/systemd/system/live3-youtube.service
echo 'Description=live3 stream - relay to YouTube' >> /etc/systemd/system/live3-youtube.service
echo 'PartOf=rtmp-live3-live.target' >> /etc/systemd/system/live3-youtube.service
echo >> /etc/systemd/system/live3-youtube.service
echo '[Service]' >> /etc/systemd/system/live3-youtube.service
echo 'EnvironmentFile=/var/local/youtube_urls.txt' >> /etc/systemd/system/live3-youtube.service
echo 'ExecStart=/usr/bin/ffmpeg -nostats -re -fflags nobuffer -i rtmp://127.0.0.1/live3/live -vcodec libx264 -preset veryfast -maxrate 2500k -bufsize 8192k -crf 21 -pix_fmt yuv420p -vf fps=30 -g 60 -acodec copy -f flv ${LIVE3_YOUTUBE_URL}' >> /etc/systemd/system/live3-youtube.service
echo 'SuccessExitStatus=255' >> /etc/systemd/system/live3-youtube.service
echo 'User=nobody' >> /etc/systemd/system/live3-youtube.service
echo >> /etc/systemd/system/live3-youtube.service
echo 'Restart=always' >> /etc/systemd/system/live3-youtube.service
echo 'RestartSec=1' >> /etc/systemd/system/live3-youtube.service
echo 'StartLimitInterval=10s' >> /etc/systemd/system/live3-youtube.service
echo 'StartLimitBurst=10' >> /etc/systemd/system/live3-youtube.service
echo >> /etc/systemd/system/live3-youtube.service
echo '[Install]' >> /etc/systemd/system/live3-youtube.service
echo 'WantedBy=rtmp-live3-live.target' >> /etc/systemd/system/live3-youtube.service
#systemctl enable live3-youtube.service

echo 'LIVE1_FACEBOOK_URL=rtmp://rtmp-api.facebook.com:80/rtmp/**PASSWORD**' > /var/local/facebook_urls.txt
echo 'LIVE2_FACEBOOK_URL=rtmp://rtmp-api.facebook.com:80/rtmp/**PASSWORD**' >> /var/local/facebook_urls.txt
echo 'LIVE3_FACEBOOK_URL=rtmp://rtmp-api.facebook.com:80/rtmp/**PASSWORD**' >> /var/local/facebook_urls.txt
chown tdobes:www-data /var/local/facebook_urls.txt
chmod 664 /var/local/facebook_urls.txt
echo '[Unit]' > /etc/systemd/system/live1-facebook.service
echo 'Description=live1 stream - relay to Facebook' >> /etc/systemd/system/live1-facebook.service
echo 'PartOf=rtmp-live1-live.target' >> /etc/systemd/system/live1-facebook.service
echo >> /etc/systemd/system/live1-facebook.service
echo '[Service]' >> /etc/systemd/system/live1-facebook.service
echo 'EnvironmentFile=/var/local/facebook_urls.txt' >> /etc/systemd/system/live1-facebook.service
echo 'ExecStart=/usr/bin/ffmpeg -nostats -re -fflags nobuffer -i rtmp://127.0.0.1/live1/live -acodec copy -vcodec copy -f flv ${LIVE1_FACEBOOK_URL}' >> /etc/systemd/system/live1-facebook.service
echo 'SuccessExitStatus=255' >> /etc/systemd/system/live1-facebook.service
echo 'User=nobody' >> /etc/systemd/system/live1-facebook.service
echo >> /etc/systemd/system/live1-facebook.service
echo 'Restart=always' >> /etc/systemd/system/live1-facebook.service
echo 'RestartSec=1' >> /etc/systemd/system/live1-facebook.service
echo 'StartLimitInterval=10s' >> /etc/systemd/system/live1-facebook.service
echo 'StartLimitBurst=10' >> /etc/systemd/system/live1-facebook.service
echo >> /etc/systemd/system/live1-facebook.service
echo '[Install]' >> /etc/systemd/system/live1-facebook.service
echo 'WantedBy=rtmp-live1-live.target' >> /etc/systemd/system/live1-facebook.service
#systemctl enable live1-facebook.service
echo '[Unit]' > /etc/systemd/system/live2-facebook.service
echo 'Description=live2 stream - relay to Facebook' >> /etc/systemd/system/live2-facebook.service
echo 'PartOf=rtmp-live2-live.target' >> /etc/systemd/system/live2-facebook.service
echo >> /etc/systemd/system/live2-facebook.service
echo '[Service]' >> /etc/systemd/system/live2-facebook.service
echo 'EnvironmentFile=/var/local/facebook_urls.txt' >> /etc/systemd/system/live2-facebook.service
echo 'ExecStart=/usr/bin/ffmpeg -nostats -re -fflags nobuffer -i rtmp://127.0.0.1/live2/live -acodec copy -vcodec copy -f flv ${LIVE2_FACEBOOK_URL}' >> /etc/systemd/system/live2-facebook.service
echo 'SuccessExitStatus=255' >> /etc/systemd/system/live2-facebook.service
echo 'User=nobody' >> /etc/systemd/system/live2-facebook.service
echo >> /etc/systemd/system/live2-facebook.service
echo 'Restart=always' >> /etc/systemd/system/live2-facebook.service
echo 'RestartSec=1' >> /etc/systemd/system/live2-facebook.service
echo 'StartLimitInterval=10s' >> /etc/systemd/system/live2-facebook.service
echo 'StartLimitBurst=10' >> /etc/systemd/system/live2-facebook.service
echo >> /etc/systemd/system/live2-facebook.service
echo '[Install]' >> /etc/systemd/system/live2-facebook.service
echo 'WantedBy=rtmp-live2-live.target' >> /etc/systemd/system/live2-facebook.service
#systemctl enable live2-facebook.service
echo '[Unit]' > /etc/systemd/system/live3-facebook.service
echo 'Description=live3 stream - relay to Facebook' >> /etc/systemd/system/live3-facebook.service
echo 'PartOf=rtmp-live3-live.target' >> /etc/systemd/system/live3-facebook.service
echo >> /etc/systemd/system/live3-facebook.service
echo '[Service]' >> /etc/systemd/system/live3-facebook.service
echo 'EnvironmentFile=/var/local/facebook_urls.txt' >> /etc/systemd/system/live3-facebook.service
echo 'ExecStart=/usr/bin/ffmpeg -nostats -re -fflags nobuffer -i rtmp://127.0.0.1/live3/live -acodec copy -vcodec copy -f flv ${LIVE3_FACEBOOK_URL}' >> /etc/systemd/system/live3-facebook.service
echo 'SuccessExitStatus=255' >> /etc/systemd/system/live3-facebook.service
echo 'User=nobody' >> /etc/systemd/system/live3-facebook.service
echo >> /etc/systemd/system/live3-facebook.service
echo 'Restart=always' >> /etc/systemd/system/live3-facebook.service
echo 'RestartSec=1' >> /etc/systemd/system/live3-facebook.service
echo 'StartLimitInterval=10s' >> /etc/systemd/system/live3-facebook.service
echo 'StartLimitBurst=10' >> /etc/systemd/system/live3-facebook.service
echo >> /etc/systemd/system/live3-facebook.service
echo '[Install]' >> /etc/systemd/system/live3-facebook.service
echo 'WantedBy=rtmp-live3-live.target' >> /etc/systemd/system/live3-facebook.service
#systemctl enable live3-facebook.service

* TODO: web control (setting ffmpeg targets, restarting ffmpeg services, link to nginx-rtmp status
# for FB API
aptitude install php-cli php-curl php-fpm
computer/glpa-stream_container_creation_notes.txt · Last modified: 2018/10/09 16:30 by tdobes
Recent changes RSS feed Driven by DokuWiki Valid XHTML 1.0 Valid CSS