S o f t G a n z.

Web & Software Developer Gang.

Linux

ให้ Shoutcast เปิดอัตโนมัติหลายสถานี

by Little Bear @June,06 2009 14.07 ( IP : 61...187 ) | Tags : Linux , Redhat , Shoutcast

ผมทดลองเปิดสถานีวิทยุออนไลน์ ซึ่งมีหลายสถานี (port) และต้องการให้มันเปิดแบบอัตโนมัติในตอนเปิด server ก็ไปเจอวิธีการและ code ในเว็บนี้

ลองทำตามโค๊ดข้างล่าง

#!/bin/bash
#
# chkconfig: 345  91 35
# description: Starts and stops sc_serv.
#       You know, the mp3 streaming thang. # # Version 1.3 (nov 4 2001) # Now with more revisions! System now checks for pid file before cat # to display so that we receive no error messages. System also displays # pids as we are killing old processes. Profanity was removed from the
# startup messages. Tests for a pid file before reporting success. Displays # the relay server name when we start the daemon up, so that we know # which servers are getting booted. Pushed the success marker over to the
# right and added [] because I am just a slave to fashion. # # Version 1.2 (nov 3 2001) # Same exact shit, but runs as nobody for security reasons. Just # in case we are worried about buffer overflows or whatnot. # # Version 1.1 (nov 3 2001) # Starts stops and restarts jobs. Also checks for existing daemons # before calling a start, and exits without starting new ones. This # prevents you from being a dumbass and starting multiple listeners # on the same port. I would suggest using the restart command # in these cases. Also creates a shoutcast.pid file that can be used # to discover all of the (many) pids used by shoutcast when running. # # Version 1.0 (nov 3 2001)
# Starts and stops successfully.
# Kills old jobs on start command. Dirty, but
# does the job well enough. Tested functional on # mandrake version 8.1 but should work on redhat
# or any other distro that supports a standard
# sysv startup script. # # Instructions for use. # 1: untargzip shoutcast into the directory of your choosing # 2: copy sc_serv into the /usr/sbin directory
# 3: Create the directory /etc/shoutcast # 4: copy the shoutcast.conf file into your /etc/shoutcast dir. # 5: Edit the shoutcast.conf file to match your needs. # 6: Make as many more conf files as needed to support
#   multiple streams. Be sure to edit these files so that #   you are not starting multiple shoutcast servers that #   are either listening or broadcasting on the same port. # 7: Copy this file into the /etc/rc.d/init.d directory # 8: chmod this file +x (chmod ug+x /etc/rc.d/init.d/shoutcast) # 9: run chkconfig --add shoutcast from the /etc/rc.d/init.d dir. # 10:Run /etc/rc.d/init.d/shoutcast start
# 11:Drink a beer, or light one up, and enjoy the tunes. # # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. This line may cause an error on incompatible # distributions. Remove it if necessary. Also remove if the startup always # fails for no apparent reason. [[ ${NETWORKING} = "no" ]] && exit 0


stop (){ #First we want to kill the original servers, so we don't get errors.   echo "Killing old shoutcast servers."   for oldpid in `ps -A | grep sc_serv | cut -c 0-6`; do   kill -9 $oldpid   if [[ $1 == "-v" ]]   then   echo $oldpid   fi   done   rm -f /var/run/shoutcast.pid }


start (){   #Now we can start the servers up.   if [[ $1 == "-v" ]]
  then   echo "Starting up the new shoutcast servers. Starting..."   fi
  servcount=`expr 0`   for cfile in `ls /etc/shoutcast`; do   echo -n $cfile   echo -n " -> "   grep ^RelayServer /etc/shoutcast/$cfile   # This is the line where we actually run the shoutcast program!   #sudo -u nobody /usr/bin/sc_serv /etc/shoutcast/$cfile > /dev/null &   /usr/bin/sc_serv /etc/shoutcast/$cfile > /dev/null &   let servcount=servcount+1   done   #Create the pid file...   ps -A | grep sc_serv | cut -c 0-6 > /var/run/shoutcast.pid   #Done now!   echo "Started $servcount servers." }


case "$1" in   start)    if [[ ! -e /var/run/shoutcast.pid ]]   then start $2 if [[ -e /var/run/shoutcast.pid ]]
then echo "Startup [SUCCESS]" fi   else   if [[ $2 == "-v" ]]   then echo "Shoutcast is already running these processes:" #Toldja! Checks before displaying pid file. if [[ -e /var/run/shoutcast.pid ]] then cat /var/run/shoutcast.pid fi echo "Try calling shoutcast restart in order to kill old processes." else echo "SC_SERV is already running. Try calling shoutcast restart." fi echo "Startup [FAILED]"   fi ;;   restart)   stop $2   if [[ $2 == "-v" ]] then echo "Waiting for the old servers to die..." fi sleep 4 start $2 if [[ -e /var/run/shoutcast.pid ]]
then echo "Startup [SUCCESS]" fi ;;   stop)   if [[ -e /var/run/shoutcast.pid ]];   then stop $2 echo "Shoutcast shutdown [SUCCESS]"   else   echo "There are no registered shoutcast servers running right now. Attempting to kill anyways." stop $2   fi   ;;   *)   echo "Usage: shoutcast (start|stop|restart) [-v]" esac

ขั้นตอนการติดตั้ง

  1. สร้างไฟล์ /etc/init.d/shoutcast แล้วเปลี่ยน attr เป็น 755
  2. copy ไฟล์ sc_serv (ที่ดาวน์โหลดมา) ไปไว้ที่ /usr/bin
  3. สร้างโฟล์เดอร์ /etc/shoutcast แล้วนำไฟล์คอนฟิกมาใส่ไว้ในนี้ จะกี่ไฟล์ก็ได้ ตอนเปิดเครื่องมันจะ start ให้หมด

ลิงก์ผู้สนับสนุน

Relate topics

Comment #1รัน ./sc_serv ไม่ได้
pencil
Posted @May,18 2010 10.37 ip : 110...220

ผมใช้ Ubuntu 10.04 พอสั่ง ./scserv มันไม่รัน
มันขึ้นว่า -bash : ./sc
serv: No such file and directory
แล้ว code ขึ้นบนเอาไว้ใช้ยังไงครับ

Comment #2
Posted @May,18 2010 11.00 ip : 61...65

ชื่อคำสั่ง คือ scserv ครับ หากจะสั่ง ./scserv นั้น ไฟล์ sc_serv จะต้องอยู่ในโฟลเดอร์ปัจจุบัน

ลอง ls ดูนะครับว่าเจอไฟล์ sc_serv หรือเปล่า

Comment #3รัน ./sc_serv ไม่ได้
pencil
Posted @May,19 2010 11.39 ip : 110...220

อยู่ทั้งหมดเลยครับ ทั้ง  Readme, scserv,scserv.conf  หรือว่าจะไม่ support Ubuntu server 10.04 ครับ หรือว่ามันต้องอยู่ที่ folder เฉพาะหรือเปล่า หรือว่าอยู่ที่ใน  folder ไหนก็ได้แล้วแต่ว่าเราจะเอาไว้ที่ไหน ผมตั้ง ชื่อว่า radio

แสดงความคิดเห็น

« 6812
หากท่านไม่ได้เป็นสมาชิก ท่านจำเป็นต้องป้อนตัวอักษรของ Anti-spam word ในช่องข้างบนให้ถูกต้อง
The content of this field is kept private and will not be shown publicly. This mail use for contact via email when someone want to contact you.
Bold Italic Underline Left Center Right Ordered List Bulleted List Horizontal Rule Page break Hyperlink Text Color :) Quote
คำแนะนำ เว็บไซท์นี้สามารถเขียนข้อความในรูปแบบ มาร์คดาวน์ - Markdown Syntax:
  • วิธีการขึ้นบรรทัดใหม่โดยไม่เว้นช่องว่างระหว่างบรรทัด ให้เคาะเว้นวรรค (Space bar) ที่ท้ายบรรทัดจำนวนหนึ่งครั้ง
  • วิธีการขึ้นย่อหน้าใหม่ซึ่งจะมีการเว้นช่องว่างห่างจากบรรทัดด้านบนเล็กน้อย ให้เคาะ Enter จำนวน 2 ครั้ง

Member Zone

Playing