Shoutcast Automatic Start Script for CentOS
I found this script and modified it a bit so it starts all three of my Shoutcast servers automatically when/if the server ever restarts. That part works great. However, there’s something I would like to change…I want to be able to manage each server individually. I’m not really sure what to do to accomplish this. At this point it’s not too big of a deal, so I’m not going to worry about it.
I want to be able to do “service shoutcast restart” and somehow be able to choose which one to restart (or restart all of them if no specific server is specified). Restarting them all isn’t acceptable when I’m only making configuration changes to one (kicking all users=bad). There is the method of hunting down the process id and killing it and then typing in the command to start it again, but that’s getting old rather fast.
I’d appreciate any suggestions.
#!/bin/sh
#
# chkconfig: 345 99 01
#
# description: shoutcast server startup script
#
# Init script for SHOUTcast
# by caraoge, modified to work correctly by Thomas R Bailey, modified further for
# use with three servers by Nathan Skelton
#
# Last edited Jan 13 2009
# Set config to config file location
# set daemon to sc_serv location
############################################################################
## CHANGE THESE VALUES to match your setup
## CONFIG is the fully qualified location of your config file
## DAEMON is the fully qualified location of the sc_serv binary
## Note, the script will look for sc_serv and sc_serv.conf in /home/shoutcast
############################################################################
DAEMON="/home/shoutcast/sc_serv"
CONFIG="/home/shoutcast/sc_serv.conf"
CONFIG2="/home/shoutcast/sc_serv2.conf"
CONFIG3="/home/shoutcast/sc_serv3.conf"
############# Don't fiddle below this line ##############
# Check for SHOUTcast binary
test -f $DAEMON || exit 0
# The init commands
case "$1" in
start)
echo "Starting SHOUTcast server..."
$DAEMON $CONFIG > /dev/null 2>&1 &
$DAEMON $CONFIG2 > /dev/null 2>&1 &
$DAEMON $CONFIG3 > /dev/null 2>&1 &
;;
stop)
echo "Stopping SHOUTcast server..."
kill -9 `ps -C sc_serv -o pid --no-headers`
;;
restart)
echo "Stopping SHOUTcast server..."
kill -9 `ps -C sc_serv -o pid --no-headers`
echo "Starting SHOUTcast server..."
$DAEMON $CONFIG > /dev/null 2>&1 &
$DAEMON $CONFIG2 > /dev/null 2>&1 &
$DAEMON $CONFIG3 > /dev/null 2>&1 &
;;
*)
echo "usage: /etc/init.d/shoutcast"
echo "$0 {start | stop | restart}"
exit 1
;;
esac
And for those interested in this, here are the steps to set this up on CentOS (by memory, so please correct me if I’m wrong):
1. Navigate to the init.d directory
cd /etc/init.d
2. Create a new file named shoutcast by opening up the nano text editor
nano shoutcast
3. Paste in above code (right click if you’re using putty) and save by pressing CTRL + X and then Y.
4. Give the new file the correct permissions.
chmod 0755 /etc/init.d/shoutcast
5. Navigate to the rc.d directory
cd /etc/rc.d/rc5.d
6. Create a sym-link to the shoutcast file we created in init.d
ln -s ../init.d/shoutcast S99shoutcast
7. Register the script with the system.
chkconfig --add shoutcast
8. Enable the service to start automatically
chkconfig shoutcast on
9. Ensure that your servers start as planned.
/etc/init.d/shoutcast start
10. You may wish to reboot the system to ensure that they start up properly as well.
Of course you would remove “$DAEMON $CONFIG2 > /dev/null 2>&1 &,” “$DAEMON $CONFIG3 > /dev/null 2>&1 &,” etc, unless you are running more than one server (or add some with higher numbers if you have more servers). Setting $DAEMON and $CONFIG ($CONFIG, $CONFIG2, $CONFIG3 should each be unique) to wherever you placed Shoutcast is also necessary. I’m assuming you have enough Linux knowledge to accomplish this. If not, feel free to ask in the comments and I’ll try to help you the best I can.

[...] Adres URL: Life at Lipscomb » Blog Archive » Shoutcast Automatic Start Script … [...]