Skip to content

Instantly share code, notes, and snippets.

@nuess0r
Forked from hSammir/shoutcast.sh
Created November 12, 2017 15:51
Show Gist options
  • Save nuess0r/2546ad19928f2e08681a9d5fb6ee2cbb to your computer and use it in GitHub Desktop.
Save nuess0r/2546ad19928f2e08681a9d5fb6ee2cbb to your computer and use it in GitHub Desktop.
Shoutcast Server Initscript.
#!/bin/sh
# kFreeBSD do not accept scripts as interpreters, using #!/bin/sh and sourcing.
if [ true != "$INIT_D_SCRIPT_SOURCED" ] ; then
set "$0" "$@"; INIT_D_SCRIPT_SOURCED=true . /lib/init/init-d-script
fi
### BEGIN INIT INFO
# Provides: skeleton
# Required-Start: $remote_fs $syslog $network
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: shoutcast server startup script
# Description: Init script for SHOUTcast.
### END INIT INFO
# Author: Eric Howey, extended to have a correct LSB header by nuess0r
############################################################################
## 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 DAEMON
## NAME the USERNAME the server should run under, often shoutcast
## Note, the script will look for sc_serv and sc_serv.conf in /home/shoutcast
############################################################################
SCPATH="/home/shoutcast/sc_serv2"
DAEMON="sc_serv"
CONFIG="sc_serv.conf"
NAME="shoutcast"
############# Don't fiddle below this line ##############
# Check for SHOUTcast DAEMON
if [ ! -e $SCPATH/$DAEMON ]
then
echo "The path/file $SCPATH/$DAEMON does not exist!"
exit 0
fi
# Select the specified user.
ME=`whoami`
as_user() {
if [ $ME = $NAME ] ; then
bash -c "$1"
else
su - $NAME -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 $DAEMON > /dev/null
then
echo "Tried to start but $DAEMON was already running!"
else
echo "$DAEMON was not running... starting."
cd $SCPATH
as_user "cd $SCPATH && screen -dmS $DAEMON ./$DAEMON ./$CONFIG"
sleep 2
if ps ax | grep -v grep | grep -v -i SCREEN | grep $DAEMON > /dev/null
then
echo "$DAEMON is now running."
else
echo "Could not start $DAEMON."
fi
fi
}
sc_stop() {
if ps ax | grep -v grep | grep -v -i SCREEN | grep $DAEMON > /dev/null
then
echo "$DAEMON is running... stopping."
kill $(pgrep $DAEMON)
sleep 2
else
echo "$DAEMON was not running."
fi
if ps ax | grep -v grep | grep -v -i SCREEN | grep $DAEMON > /dev/null
then
echo "$DAEMON could not be shut down... still running."
else
echo "$DAEMON is shut down."
fi
}
sc_status() {
if ps ax | grep -v grep | grep -v -i SCREEN | grep $DAEMON > /dev/null
then
echo "$DAEMON is running."
else
echo "$DAEMON 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment