Old 3rd May 2011, 04:37   #1
red1d1
Junior Member
 
Join Date: May 2011
Posts: 3
After my efforts to find a kick ass Shoutcast DNAS Startup/Init script were proven futile, I decided to write my own. This script is a full blown init script that will allow you to start, stop, restart and check the status of your shoutcast 1.9 server. I haven't tested this on 2.0 yet. Feel free to let me know how it works

FYI, this script requires Screen to be installed on your server... (which any modern linux server has or can be installed using a package manager.)

There's a section that reads 'Settings.' Set them to your liking... or leave them at default if you're only running one instance of DNAS

Quote:
#!/bin/bash
#
# Shoutcast startup script
# Requries Screen to be installed in order for proper operation
# Written by Eric Howey
# PLEASE SHARE THIS SOFTWARE!
# Because sharing is caring
# 04/26/2011
#

### BEGIN INIT INFO
# Provides: shoutcast
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Shoutcast server
# Description: Starts the shoutcast server
### END INIT INFO


# Settings - Please edit these...
BINARY='sc_serv'
CONFIG='sc_serv.conf'
USERNAME='sc'
SCPATH='/home/shoutcast/sc_serv'

# Select the specified user. mmmk?
ME=`whoami`
as_user() {
if [ $ME == $USERNAME ] ; then
bash -c "$1"
else
su - $USERNAME -c "$1"
fi
}


# Now, let's start, stop and check status of the server...
sc_start() {
if ps ax | grep -v grep | grep -v -i SCREEN | grep $BINARY > /dev/null
then
echo "Tried to start but $BINARY was already running!"
else
echo "$BINARY was not running... starting."
cd $SCPATH
as_user "cd $SCPATH && screen -dmS $BINARY ./$BINARY ./$CONFIG"
sleep 2
if ps ax | grep -v grep | grep -v -i SCREEN | grep $BINARY > /dev/null
then
echo "$BINARY is now running."
else
echo "Could not start $BINARY."
fi
fi
}


sc_stop() {
if ps ax | grep -v grep | grep -v -i SCREEN | grep $BINARY > /dev/null
then
echo "$BINARY is running... stopping."
kill $(pgrep $BINARY)
sleep 2
else
echo "$BINARY was not running."
fi
if ps ax | grep -v grep | grep -v -i SCREEN | grep $BINARY > /dev/null
then
echo "$BINARY could not be shut down... still running."
else
echo "$BINARY is shut down."
fi
}


sc_status() {
if ps ax | grep -v grep | grep -v -i SCREEN | grep $BINARY > /dev/null
then
echo "$BINARY is running."
else
echo "$BINARY is not running."
fi
}


# Link to start-stop
case "$1" in
start)
sc_start
;;
stop)
sc_stop
;;
restart)
sc_stop
sc_start
;;
status)
sc_status
;;
*)
echo "Usage: $0 {start | stop | restart | status}"
exit 1
;;

esac

exit 0
To install, add this to your /etc/init.d directory. To set this script to run at startup:

Fedora/Red Hat/CentOS
code:
sudo chkconfig sc_serv on


Ubuntu/Debian
code:
sudo update-rc.d sc_serv defaults


Since code formatting is pretty fail on these forums, a much cleaner version is available in the link below...

http://pastie.org/1859169

Enjoy!
red1d1 is offline   Reply With Quote
Old 2nd July 2012, 22:14   #2
pigdog
Junior Member
 
Join Date: Jul 2012
Posts: 1
I hope this helps someone else. I have slightly modified the code above to work with 2.0 also be sure to name the script shoutcastd or something other than "sc_serv" or containing sc_serv or it will always report as running

Quote:
#!/bin/bash
#
# Shoutcast startup script
# Requries Screen to be installed in order for proper operation
# Written by Eric Howey
# PLEASE SHARE THIS SOFTWARE!
# Because sharing is caring
# 04/26/2011
#

### BEGIN INIT INFO
# Provides: shoutcast
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Shoutcast server
# Description: Starts the shoutcast server
### END INIT INFO


# Settings - Please edit these...
# No trailing slash for SCPATH please
BINARY='sc_serv'
CONFIG='sc_serv.conf'
USERNAME='root'
SCPATH='/usr/shout'

# Select the specified user. mmmk?
ME=`whoami`
as_user() {
if [ $ME == $USERNAME ] ; then
bash -c "$1"
else
su - $USERNAME -c "$1"
fi
}


# Now, let's start, stop and check status of the server...
sc_start() {
if ps ax | grep -v grep | grep $BINARY > /dev/null
then
echo "Tried to start but $BINARY was already running!"
else
echo "$BINARY was not running... starting."
as_user "$SCPATH/$BINARY daemon $SCPATH/$CONFIG"
sleep 2
if ps ax | grep -v grep | grep $BINARY > /dev/null
then
echo "$BINARY is now running."
else
echo "Could not start $BINARY."
fi
fi
}


sc_stop() {
if ps ax | grep -v grep | grep $BINARY > /dev/null
then
echo "$BINARY is running... stopping."
kill $(pgrep $BINARY)
sleep 2
else
echo "$BINARY was not running."
fi
if ps ax | grep -v grep | grep $BINARY > /dev/null
then
echo "$BINARY could not be shut down... still running."
else
echo "$BINARY is shut down."
fi
}


sc_status() {
if ps ax | grep -v grep | grep $BINARY > /dev/null
then
echo "$BINARY is running."
else
echo "$BINARY is not running."
fi
}


# Link to start-stop
case "$1" in
start)
sc_start
;;
stop)
sc_stop
;;
restart)
sc_stop
sc_start
;;
status)
sc_status
;;
*)
echo "Usage: $0 {start | stop | restart | status}"
exit 1
;;

esac

exit 0
pigdog is offline   Reply With Quote
Old 2nd July 2012, 22:29   #3
DrO
 
Join Date: Sep 2003
Posts: 27,873
why have you changed how it's run since even the current public build of the v2 DNAS should work ok in daemon mode - or am i missing something?

-daz
DrO is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Shoutcast > Shoutcast Technical Support

Tags
init, script, startup

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump