Exemplo n.º 1
0
 private function stream_operate_nginx($server_info, $channel_stream, $action)
 {
     $return = array('ret_input_id' => 'nginx', 'ret_delay_id' => 'nginx', 'ret_change_id' => 'nginx', 'ret_output_id' => 'nginx', 'ret_live_output_id' => 'nginx', 'ret_record_output_id' => 'nginx');
     $init_data = array('host' => $server_info['host'], 'dir' => $server_info['input_dir']);
     include_once CUR_CONF_PATH . 'lib/nginx.live.php';
     $postdata = array('app' => $server_info['output_dir'], 'name' => build_nginx_stream_name($channel_stream['code'], $channel_stream['stream_name']));
     $server = new m2oLive();
     $server->init_env($init_data);
     switch ($action) {
         case 'start':
             $server->start($postdata);
             break;
         case 'stop':
             $server->stop($postdata);
             break;
         case 'restart':
             $server->restart($postdata);
             break;
         default:
             break;
     }
     return $return;
 }
Exemplo n.º 2
0
 public function switch_host()
 {
     $id = $this->input['id'];
     //配置id
     if (!$id) {
         $this->errorOutput(NOID);
     }
     $is_on = $this->input['is_on'];
     //操作,1是切到备播,0是切到主控
     //获取使用该配置的所有频道标识
     $sql = "SELECT code,table_name FROM " . DB_PREFIX . "channel WHERE server_id = " . $id;
     $q = $this->db->query($sql);
     while ($row = $this->db->fetch_array($q)) {
         $codes[] = array('code' => $row['code'], 'table_name' => $row['table_name']);
     }
     /***************** 获取主备服务器信息 *******************/
     $sql = "SELECT fid,host,input_dir,ts_host FROM " . DB_PREFIX . "server_config WHERE id = " . $id . " OR fid = " . $id;
     $query = $this->db->query($sql);
     while ($row = $this->db->fetch_array($query)) {
         if (!$row['fid']) {
             $host['m_host'] = $row;
         } else {
             $host['b_host'] = $row;
         }
         //备播
     }
     include_once CUR_CONF_PATH . 'lib/nginx.live.php';
     $server = new m2oLive();
     /******************************************************/
     if ($is_on) {
         //备播服务器状态验证
         $server->init_env(array('host' => $host['b_host']['host'], 'dir' => $host['b_host']['input_dir']));
         if (!$server->get_status()) {
             $this->errorOutput('备播主机异常,不能开启');
         }
         //重写缓存
         foreach ((array) $codes as $k => $v) {
             @(include CACHE_DIR . 'channel/' . $v['code'] . '.php');
             $v['table_name'] == 'dvr' ? $tablename = 'dvr1' : ($tablename = $v['table_name'] . '_1');
             $channel_info['channel']['table_name'] = $tablename;
             $channel_info['channel']['config']['ts_host'] = $host['b_host']['ts_host'];
             file_put_contents(CACHE_DIR . 'channel/' . $v['code'] . '.php', '<?php $channel_info = ' . var_export($channel_info, 1) . ';?>');
         }
         //打开开关
         $sql = "UPDATE " . DB_PREFIX . "server_config SET is_used = 0 WHERE id = " . $id;
         $this->db->query($sql);
     } else {
         //主控服务器状态验证
         $server->init_env(array('host' => $host['m_host']['host'], 'dir' => $host['m_host']['input_dir']));
         if (!$server->get_status()) {
             $this->errorOutput('主控主机异常,不能开启');
         }
         //重建缓存
         foreach ((array) $codes as $k => $v) {
             @unlink(CACHE_DIR . 'channel/' . $v['code'] . '.php');
         }
         //关闭开关
         $sql = "UPDATE " . DB_PREFIX . "server_config SET is_used = 1 WHERE id = " . $id;
         $this->db->query($sql);
     }
 }
Exemplo n.º 3
0
 public function show_stream_status()
 {
     $server_id = intval($this->input['id']);
     $sql = 'SELECT * FROM ' . DB_PREFIX . 'server_config WHERE id = ' . $server_id;
     $server_info = $this->db->query_first($sql);
     if (!$server_info) {
         $this->errorOutput("服务器配置已被删除");
     }
     $type = $server_info['type'];
     include_once CUR_CONF_PATH . 'lib/' . $type . '.live.php';
     $server = new m2oLive();
     $server->init_env(array('host' => $server_info['host'], 'dir' => $server_info['input_dir']));
     $ret = $server->select();
     if ($ret && $type == 'nginx') {
         $all_streams = $ret[0]['applications'][0];
         $push_streams = $all_streams['pushes'];
         unset($all_streams['pushes']);
         if ($push_streams) {
             foreach ($push_streams as $k => $v) {
                 $v['url'] = build_push_stream_url($v['name'], $server_info);
                 $push_streams[$k] = $v;
             }
             $all_streams['pushes'] = $push_streams;
         }
         $this->addItem($all_streams);
     }
     $this->output();
 }