• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

icecast

Run Docker Compose

February 27, 2020

Here’s how to run docker-compose. I have an Icecast docker-compose.yml file. Icecast is an audio streaming server.

version: "2"
 
services:
  icecast:
    image: moul/icecast
    environment:
      - ICECAST_SOURCE_PASSWORD=secret
      - ICECAST_ADMIN_PASSWORD=secret
      - ICECAST_PASSWORD=secret
      - ICECAST_RELAY_PASSWORD=secret
    ports:
      - "8000:8000"
    restart: always

version: "2" services: icecast: image: moul/icecast environment: - ICECAST_SOURCE_PASSWORD=secret - ICECAST_ADMIN_PASSWORD=secret - ICECAST_PASSWORD=secret - ICECAST_RELAY_PASSWORD=secret ports: - "8000:8000" restart: always

To run Icecast in a container , I run docker-compose in the background.

docker-compose up -d

docker-compose up -d

Check to see if Icecast is running on your browser.

http://localhost:8000

http://localhost:8000

To stop the Icecast container, I simply stop the docker-compose.

docker-compose stop

docker-compose stop

Here are the other docker commands you can run.

docker images
docker ps
docker-compose ps

docker images docker ps docker-compose ps

Filed Under: Cloud Tagged With: docker, docker-compose, icecast, start, stop

Icecast on Docker

July 5, 2019

Run Icecast2 on a Docker container.

docker run -d \
-p 8000:8000 \
-e ICECAST_SOURCE_PASSWORD=aaaa \
-e ICECAST_ADMIN_PASSWORD=bbbb \
-e ICECAST_PASSWORD=cccc \
-e ICECAST_RELAY_PASSWORD=dddd \
moul/icecast

docker run -d \ -p 8000:8000 \ -e ICECAST_SOURCE_PASSWORD=aaaa \ -e ICECAST_ADMIN_PASSWORD=bbbb \ -e ICECAST_PASSWORD=cccc \ -e ICECAST_RELAY_PASSWORD=dddd \ moul/icecast

Access localhost:8000 on browser. Github.

Filed Under: Cloud Tagged With: container, docker, icecast, run

Upgrading Icecast2

July 13, 2016

The following instructions will perform the latest Icecast2 server upgrade on your Ubuntu Server via the PPA route.

1. Login to your Ubuntu Server via SSH. Substitute your own username and server.

$ ssh ulysses@server.com

$ ssh ulysses@server.com

2. Add Icecast2 PPA to your sources list. Since I’m running Ubuntu 12.04, I’ll use the 12.04 repository here.

$ sudo sh -c "echo deb http://download.opensuse.org/repositories/home:/dm8tbr/xUbuntu_12.04 ./ > /etc/apt/sources.list.d/icecast.list"

$ sudo sh -c "echo deb http://download.opensuse.org/repositories/home:/dm8tbr/xUbuntu_12.04 ./ > /etc/apt/sources.list.d/icecast.list"

3. Add the GPG key to the apt sources keyring. I’ll use the 12.04 release key here as well.

$ wget -qO - http://download.opensuse.org/repositories/home:/dm8tbr/xUbuntu_12.04/Release.key | sudo apt-key add -

$ wget -qO - http://download.opensuse.org/repositories/home:/dm8tbr/xUbuntu_12.04/Release.key | sudo apt-key add -

4. Run Update to begin the upgrade process to the latest version of Icecast2.

$ sudo apt-get update
$ sudo apt-get upgrade

$ sudo apt-get update $ sudo apt-get upgrade

5. The Icecast2 install script will run and ask you to overwrite your previous configuration. It’s up to you to keep or overwrite the file.

6. If you’re using your previous configuration file, it may throw out some errors and warnings, which you will probably need to fix.

7. Finally, test your Icecast2 server by sending a stream to it.

Filed Under: Linux Tagged With: icecast, ppa, ssh

Icecast PHP Class

March 14, 2014

I modified an existing Icecast PHP class that I found online. I’ve added a couple of extra fields particularly the ‘status’ field where you’ll be able to determine if your Icecast server is streaming or not. I’ve initially set the status variable to ‘On Air’ and ‘Off Air.’ To use the class, take a look at the code below:

// include the class file
include( 'icecast.php' );
 
// instantiate class
$stream = new IceCast();
 
// set server and mount
$server = 'http://yourdomain.com:8001';
$file   = '/status.xsl?mount=/yourmount.ogg';
 
// set the url
$stream->setUrl($server,$file);
 
// get status info
$radio = $stream->getStatus();
 
// assign array to variables
extract($radio);
 
// echo the status
echo $status.'<br/>';
 
// display more stats if ON AIR
if ($status=='ON AIR') :
echo $listeners.' listeners<br/>';
echo $most_listeners.' max listeners<br/>';
endif;

// include the class file include( 'icecast.php' ); // instantiate class $stream = new IceCast(); // set server and mount $server = 'http://yourdomain.com:8001'; $file = '/status.xsl?mount=/yourmount.ogg'; // set the url $stream->setUrl($server,$file); // get status info $radio = $stream->getStatus(); // assign array to variables extract($radio); // echo the status echo $status.'<br/>'; // display more stats if ON AIR if ($status=='ON AIR') : echo $listeners.' listeners<br/>'; echo $most_listeners.' max listeners<br/>'; endif;

Here’s the Icecast class.

class IceCast {
    var $server = "http://yourdomain.com:8001";
    var $stats_file = "/status.xsl?mount=/yourmount.ogg";
    var $radio_info=array();
 
    function __construct() {
        // build array to store our Icecast stats   
        $this->radio_info['server'] = $this->server;
        $this->radio_info['title'] = '';
        $this->radio_info['description'] = '';
        $this->radio_info['content_type'] = '';
        $this->radio_info['mount_start'] = '';
        $this->radio_info['bit_rate'] = '';
        $this->radio_info['listeners'] = '';
        $this->radio_info['most_listeners'] = '';
        $this->radio_info['genre'] = '';
        $this->radio_info['url'] = '';
        $this->radio_info['now_playing'] = array();
        $this->radio_info['now_playing']['artist'] = 'Unknown';
        $this->radio_info['now_playing']['track'] = 'Unknown';
        $this->radio_info['status'] = 'OFF AIR';
    }
 
    function setUrl($url,$file) {
        $this->server=$url;
        $this->stats_file=$file;
        $this->radio_info['server'] = $this->server;
    }
 
    private function fetch() {
        // create a new curl resource
        $ch = curl_init();
 
        // set the url
        curl_setopt($ch,CURLOPT_URL,$this->server.$this->stats_file);
 
        // return as a string
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
 
        // $output = the status.xsl file
        $output = curl_exec($ch);
 
        // close curl resource to free up system resources
        curl_close($ch);
 
        return $output;
    }
 
    function getStatus() {
        $output=$this->fetch();
 
        // loop through $output and sort arrays
        $temp_array = array();
 
        $search_for = "<td\s[^>]*class=\"streamdata\">(.*)<\/td>";
        $search_td = array('<td class="streamdata">','</td>');
 
        if(preg_match_all("/$search_for/siU",$output,$matches)) {
           foreach($matches[0] as $match) {
              $to_push = str_replace($search_td,'',$match);
              $to_push = trim($to_push);
              array_push($temp_array,$to_push);
           }
        }
 
        if(count($temp_array)) {
            //sort our temp array into our ral array
            $this->radio_info['title'] = $temp_array[0];
            $this->radio_info['description'] = $temp_array[1];
            $this->radio_info['content_type'] = $temp_array[2];
            $this->radio_info['mount_start'] = $temp_array[3];
            $this->radio_info['bit_rate'] = $temp_array[4];
            $this->radio_info['listeners'] = $temp_array[5];
            $this->radio_info['most_listeners'] = $temp_array[6];
            $this->radio_info['genre'] = $temp_array[7];
            $this->radio_info['url'] = $temp_array[8];
 
            if(isset($temp_array[9])) {
                $x = explode(" - ",$temp_array[9]);
                $this->radio_info['now_playing']['artist'] = $x[0];
                $this->radio_info['now_playing']['track'] = $x[1];
            }
            $this->radio_info['status'] = 'ON AIR';
 
        }
        return $this->radio_info;
        }
 
}

class IceCast { var $server = "http://yourdomain.com:8001"; var $stats_file = "/status.xsl?mount=/yourmount.ogg"; var $radio_info=array(); function __construct() { // build array to store our Icecast stats $this->radio_info['server'] = $this->server; $this->radio_info['title'] = ''; $this->radio_info['description'] = ''; $this->radio_info['content_type'] = ''; $this->radio_info['mount_start'] = ''; $this->radio_info['bit_rate'] = ''; $this->radio_info['listeners'] = ''; $this->radio_info['most_listeners'] = ''; $this->radio_info['genre'] = ''; $this->radio_info['url'] = ''; $this->radio_info['now_playing'] = array(); $this->radio_info['now_playing']['artist'] = 'Unknown'; $this->radio_info['now_playing']['track'] = 'Unknown'; $this->radio_info['status'] = 'OFF AIR'; } function setUrl($url,$file) { $this->server=$url; $this->stats_file=$file; $this->radio_info['server'] = $this->server; } private function fetch() { // create a new curl resource $ch = curl_init(); // set the url curl_setopt($ch,CURLOPT_URL,$this->server.$this->stats_file); // return as a string curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); // $output = the status.xsl file $output = curl_exec($ch); // close curl resource to free up system resources curl_close($ch); return $output; } function getStatus() { $output=$this->fetch(); // loop through $output and sort arrays $temp_array = array(); $search_for = "<td\s[^>]*class=\"streamdata\">(.*)<\/td>"; $search_td = array('<td class="streamdata">','</td>'); if(preg_match_all("/$search_for/siU",$output,$matches)) { foreach($matches[0] as $match) { $to_push = str_replace($search_td,'',$match); $to_push = trim($to_push); array_push($temp_array,$to_push); } } if(count($temp_array)) { //sort our temp array into our ral array $this->radio_info['title'] = $temp_array[0]; $this->radio_info['description'] = $temp_array[1]; $this->radio_info['content_type'] = $temp_array[2]; $this->radio_info['mount_start'] = $temp_array[3]; $this->radio_info['bit_rate'] = $temp_array[4]; $this->radio_info['listeners'] = $temp_array[5]; $this->radio_info['most_listeners'] = $temp_array[6]; $this->radio_info['genre'] = $temp_array[7]; $this->radio_info['url'] = $temp_array[8]; if(isset($temp_array[9])) { $x = explode(" - ",$temp_array[9]); $this->radio_info['now_playing']['artist'] = $x[0]; $this->radio_info['now_playing']['track'] = $x[1]; } $this->radio_info['status'] = 'ON AIR'; } return $this->radio_info; } }

Filed Under: PHP Tagged With: class, icecast, status

  • Home
  • About
  • Archives

Copyright © 2023