Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SHOUTcast daemon script not functioning properly

I've got a SHOUTcast server running on Ubuntu. The server process is running great, but I can't seem to get the daemon script to function properly. Following a couple tutorials I found I came up with this:

#!/bin/sh

CONFIG="/home/apps/shout32/sc_plex.conf"
DAEMON="/home/apps/shout32/sc_serv"

case "$1" in
    start)
        echo "Starting SC..."
        $DAEMON $CONFIG > /dev/null 2>&1 &
        ;;
    stop)
        echo "Stopping SC..."
        kill -9 `ps -C sc_serv -o pid --no-headers`
        ;;
    restart)
        echo "Rebooting SC..."
        kill -9 `ps -C sc_serv -o pid --no-headers`
        $DAEMON $CONFIG > /dev/null 2>&1 &
        ;;
    *)
        echo "usage: service sc32d {start | stop | restart}"
        exit 1
        ;;
esac

This however does not work. I didn't know what a lot of this meant, so I started to break it down line by line. If I remove the /dev/null stuff - which as I now understand keeps the program running 'silent' in the background - I get this message, and the program closes:

root@streams3:/etc/init.d# service sc32d start
Starting SC...
root@streams3:/etc/init.d# 2013-05-21 14:41:50  E       msg:<***>       logger could not open file logs/sc_serv.log
2013-05-21 14:41:50     I       msg:<***>       Logger shutdown

root@streams3:/etc/init.d#
root@streams3:/etc/init.d# ps -C sc_serv
  PID TTY          TIME CMD
root@streams3:/etc/init.d#

I was still in the process of researching what exactly /dev/null did and why, so I wanted to run those commands with all the /dev/null stuff by hand, which I did, and that's where I got some sort of error code:

root@streams3:/etc/init.d# /home/apps/shout32/sc_serv /home/apps/shout32/sc_plex.conf > /dev/null 2>&1 &
[2] 2261
root@streams3:/etc/init.d#
[2]-  Exit 255                /home/apps/shout32/sc_serv /home/apps/shout32/sc_plex.conf > /dev/null 2>&1
root@streams3:/etc/init.d# ps -C sc_serv
  PID TTY          TIME CMD

Unfortunately from the brief amount of research I did it sounds like 'Exit 225' is like a catch-all error code for codes that are outside of the acceptable range of codes.

The interesting part of the whole issue is this: When I navigate to the /home/apps/shout32/ folder, and run the commands there, without the full path... damn thing works:

root@streams3:/home/apps/shout32# ./sc_serv sc_plex.conf > /dev/null 2>&1 &
[2] 2245
root@streams3:/home/apps/shout32#
root@streams3:/home/apps/shout32# ps -C sc_serv
  PID TTY          TIME CMD
 2245 pts/0    00:00:00 sc_serv

So, something is messing up because the script file is in /etc/init.d/ and not in the folder the application is in? As far as I know I followed every step in the published tutorials for setting up SHOUTcast in Ubuntu and then making a daemon... I don't think I missed anything. I have a feeling the solution is either staring me right in the face or its some sort of obscure permissions thing that's a bit over my head.

But any help would be greatly appreciated!


So, based on an answer below I added cd /home/apps/shout32/ to the START command in my script, also added pwd and ls... to see if we could eliminate the fact that the script couldn't find the /log/ directory.

So now my script is:

CONFIG="/home/apps/shout32/sc_plex.conf"
DAEMON="/home/apps/shout32/sc_serv"

cd /home/apps/shout32/

case "$1" in
        start)
                echo "Starting SC..."
                cd /home/apps/shout32/
                pwd
                ls
                $DAEMON $CONFIG &
                ;;
        stop)
                echo "Stopping SC..."
                kill -9 `ps -C sc_serv -o pid --no-headers`
                ;;
        restart)
                echo "Rebooting SC..."
                kill -9 `ps -C sc_serv -o pid --no-headers`
                $DAEMON $CONFIG &
                ;;
        *)
                echo "usage: service sc32d {start | stop | restart}"
                exit 1
                ;;
esac

I got this:

admin@streams3:/etc/init.d$ service sc32d start
Starting SC...
/home/apps/shout32
changes.txt     readme.txt                     sc_serv_debug.conf
config_builder  sc_plex.conf                   sc_serv_public.conf
control         sc_serv                        sc_serv_relay.conf
docs            sc_serv2_linux_07_31_2011.tar  sc_serv_simple.conf
logs            sc_serv_basic.conf             tos.txt
admin@streams3:/etc/init.d$ 2013-06-05 17:52:08      E       msg:<***>      logger could not open file logs/sc_serv.log
2013-06-05 17:52:08     I       msg:<***>       Logger shutdown
like image 314
Sam K Avatar asked May 21 '13 19:05

Sam K


1 Answers

your second snippet contains logger could not open file logs/sc_serv.log. So it tries to write to a file sc_serv.log which it either expects or wants to create in the directory logs which it expects in the current directory. This also explains that it works when you cd to /home/apps/shout32/ first. I guess there's a file /home/apps/shout32/logs/sc_serv.log.

can you configure the location of that file? can't you just add some cd ... at the start of the script?

like image 80
user829755 Avatar answered Sep 30 '22 13:09

user829755