rICh
rICh

Reputation: 1709

debugging /etc/init.d startup scripts in Ubuntu

Have custom dropr message queue pollers I'm trying to start up via /etc/init.d in ubuntu. All 3 scripts are super-simple one liners and work perfect via command line, but for some reason, only one of them actually works when the server boots up. All have 775 perms, and this works great:

sudo /etc/init.d/app-poller.sh 

Here's an example script (has to run as www-data user):

[/etc/init.d]$  cat /etc/init.d/app-poller.sh 
#!/bin/sh
su - www-data -c "bash -c '/path/to/dropr-server/daemons/app-poller.php'"

I've run removed / re-entered the inittab entries several times via:

updates-rc.d -f app-poller.sh remove
updates-rc.d app-poller.sh defaults

rcconf script also says everything is starting fine. I've followed all the instructions here: http://jonathonhill.net/2009-04-23/auto-start-a-shell-script-on-ubuntu-server/ here and here: http://stringofthoughts.wordpress.com/2009/04/16/adding-removing-shell-scripts-ubuntu-810/

And I've looked for output in all the usual suspects (/var/log/messages, /var/log/daemons, etc)... still no clue.

Would very much like to at least have some insight into why this is failing. Anyone know which logfiles I can reference to see what is going wrong & why?

Upvotes: 8

Views: 23143

Answers (4)

Chris Kerlin
Chris Kerlin

Reputation: 140

I found adding the following near the top of my /etc/init.d/scriptname was all I needed:

debug_me=true

if [[ $debug_me == true ]]; then

  # Close STDOUT
  exec 1<&-
  # Close STDERR
  exec 2<&-

  LOG_FILE=/home/myhome/scriptname.log

  # Open STDOUT as $LOG_FILE file for read and write.
  exec 1<>$LOG_FILE

  # Redirect STDERR to STDOUT
  exec 2>&1

  # Display shell commands with expanded args
  set -x

fi

Upvotes: 9

Grasshopper
Grasshopper

Reputation: 1769

Run it in a sub-shell with -x.

http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html

Upvotes: 2

Rias A. Sherzad
Rias A. Sherzad

Reputation: 758

Try calling the init-script while simulating the boottime environment:

env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" /etc/init.d/your-daemon start 

Do add some debug output to your script if you don't see any output from that command.

Upvotes: 6

Mike
Mike

Reputation: 8100

Try changing:

su - www-data -c "bash -c '/path/to/dropr-server/daemons/app-poller.php'"

to:

/bin/su - www-data -c "/bin/bash -c '/path/to/dropr-server/daemons/app-poller.php'"

Upvotes: 0

Related Questions