Debugging /etc/init.d startup scripts in Ubuntu

Have custom prpr message queues that I'm trying to run through /etc/init.d in ubuntu. All 3 scripts are super simple single-line and work fine on the command line, but for some reason, only one of them really works when the server boots. All have 775 perm, and this works great:

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

Here's an example script (should run as the 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 ran / re-entered inittab entries several times through:

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

The rcconf script also says that everything starts fine. I 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 searched for the output in all the usual suspects (/ var / log / messages, / var / log / daemons, etc.) ... there is still no clue.

I would really like to at least get an idea of โ€‹โ€‹why this fails. Does anyone know which log files I can link to see what is going wrong and why?

+4
source share
4 answers

Try calling init-script while simulating the boot environment:

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

Add extra debugging output to your script if you do not see any output from this command.

+4
source

After searching a bit, I found that adding the following at 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 
+1
source

Try changing:

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

in

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

0
source

Source: https://habr.com/ru/post/1379162/


All Articles