6

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
Sam K
  • 214
  • 3
  • 14

1 Answers1

2

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?

user829755
  • 1,489
  • 13
  • 27
  • Yeah, in my own troubleshooting after my OP I had determined that it was something to do with /logs. There is indeed a /home/apps/shout32/logs/sc_serv.log I tried changing the permissions and whatnot on the folder/file.... however what you suggest didn't cross my mind. How exactly would I direct a script to operate as if it was in X directory? – Sam K Jun 05 '13 at 21:45
  • Oh! I see what you're saying, just start the script off with cd /home/apps/shout32.... let me go try that now! – Sam K Jun 05 '13 at 21:46
  • I updated the OP with the results, no luck. Perhaps I am grossly misunderstanding your suggestion. – Sam K Jun 05 '13 at 21:53
  • 1
    no no, you got it right but apparently it didn't help. maybe the daemon `cd`s away into another directory. it's strange that the log file is specified with a relative path, that's unusual. what's in the `$CONFIG`? – user829755 Jun 05 '13 at 22:04
  • Ahh. The Config file does have some lines pointing to the logfile, `logfile=logs/sc_serv.log` It got passed my eye because its in the section of the config file that I didn't write, I just C&P from the sample config file (and this script is supposed to work with the default config) should that line have a different syntax? – Sam K Jun 05 '13 at 22:16
  • 2
    with a relative path you never know... at least for debugging I'd speficy a failsafe absolute path like `logfile=/tmp/sc_serv.log`. – user829755 Jun 05 '13 at 22:18
  • Hah, Brilliant! Thanks man, I just set the log file to the full path `/home/apps/shout32/logs/sc_serv.log` and it worked! – Sam K Jun 05 '13 at 23:05