Page 1 of 1

Get a log when i start a daemon?

Posted: Mon Jan 20, 2014 9:35 pm
by Juel-dk
Hi All. :)

I have made a Pythonscript to control my house heat system :)
I have made a daemon in /etc/init.d
and run.

sudo chmod 755 /etc/init.d/heatcontroller
sudo update-rc.d heatcontroller defaults

But the script dont start, even when i run:
sudo /etc/init.d/heatcontroller start

Nothing happens, how do I turn on some logging, so I can see whats happening?

Its frustrating not to get any errors.. :/

Google didn't help om turning on logs on a daemon start :(

Kind regards

Re: Get a log when i start a daemon?

Posted: Tue Jan 21, 2014 3:19 pm
by Juel-dk
really? no one knows this?

Re: Get a log when i start a daemon?

Posted: Tue Jan 21, 2014 7:15 pm
by Douglas6
It's mostly up to you to you to do the logging. If you're using (e.g.) start-stop-daemon, it's just going to fork your code into the background and report success. If your code fails silently, that's on you.

Try running your daemon from the command line (as root, since this is closer to the environment it will run in from init.d)

Common problems are unqualified paths, or other dependencies on the environment variables or access rights in effect when you developed/tested the code.

Re: Get a log when i start a daemon?

Posted: Tue Jan 21, 2014 8:10 pm
by DougieLawson
Juel-dk wrote:
But the script dont start, even when i run:
sudo /etc/init.d/heatcontroller start
Try this
sudo bash -x /etc/init.d/heatcontroller start

Re: Get a log when i start a daemon?

Posted: Tue Jan 28, 2014 7:46 pm
by Juel-dk
Hi :)
Sorry for the late answer, been busy :)

I get this:
+ PATH=/home/pi:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
+ DAEMON=/home/pi/heatcontroller.py
+ NAME=HeatController
+ DESC=HeatController
+ test -x /home/pi/heatcontroller.py
+ exit 0

when I run:
sudo bash -x /etc/init.d/heatcontroller start

Re: Get a log when i start a daemon?

Posted: Tue Jan 28, 2014 9:49 pm
by Juel-dk
Ok, i have made a new startup scrip that points to a .sh command.

When i run the "sudo /etc/init.d/heatcontroller start" It Works perfectly :D

But i have addet it to the startup with:
sudo update-rc.d heatcontroller defaults

But it just dont start :/

When i run:
ls /etc/rc*.d It shows up in the list.. this is just wierd :D

Re: Get a log when i start a daemon?

Posted: Wed Jan 29, 2014 12:00 am
by DougieLawson
When you run ls /etc/rc*.d does it show up as K##scriptname or S##scriptname?

K01foobar means kill foobar by running the script K01foobar stop
S17barfoo means start barfoo by running the script as S17barfoo start

The numbers determine what order the scripts are run in.

Use
sudo update-rc.d xyzzy enable 2 3 4 5
to remove any K##xyzzy make the S##xyzzy scripts

Re: Get a log when i start a daemon?

Posted: Wed Jan 29, 2014 4:39 pm
by Juel-dk
Hmm it says:

rc0.d: K01heatcontroller
rc1.d: K01heatcontroller
rc2.d: S01heatcontroller
rc3.d: S01heatcontroller
rc4.d: S01heatcontroller
rc5.d: S01heatcontroller
rc6.d: K01heatcontroller

So that's ok right? I have run the sudo update-rc.d heatcontroller enable 2 3 4 5
That made no difference..

Can this be an access rights question? Or are all of the init.d runned as sudo?

Re: Get a log when i start a daemon?

Posted: Wed Jan 29, 2014 6:09 pm
by Richard-TX
Just to clear the air a bit.

sudo is a stand alone command.

sudo bash is a valid command with argument.

If you want to run as root for a while, just type sudo bash or sudo sh or my favorite, sudo ksh -o vi

Re: Get a log when i start a daemon?

Posted: Wed Jan 29, 2014 9:41 pm
by DougieLawson
Juel-dk wrote: Can this be an access rights question? Or are all of the init.d runned as sudo?
Nothing in /etc/init.d is run with sudo. Everything starts running as root.root UID(0) GID(0).
Those scripts normally log stuff to /var/log/messages and emit various messages to the console when they start.