Juel-dk
Posts: 10
Joined: Mon Jan 20, 2014 9:28 pm

Get a log when i start a daemon?

Mon Jan 20, 2014 9:35 pm

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

Juel-dk
Posts: 10
Joined: Mon Jan 20, 2014 9:28 pm

Re: Get a log when i start a daemon?

Tue Jan 21, 2014 3:19 pm

really? no one knows this?

User avatar
Douglas6
Posts: 4874
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Get a log when i start a daemon?

Tue Jan 21, 2014 7:15 pm

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.

User avatar
DougieLawson
Posts: 39301
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Get a log when i start a daemon?

Tue Jan 21, 2014 8:10 pm

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
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Juel-dk
Posts: 10
Joined: Mon Jan 20, 2014 9:28 pm

Re: Get a log when i start a daemon?

Tue Jan 28, 2014 7:46 pm

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

Juel-dk
Posts: 10
Joined: Mon Jan 20, 2014 9:28 pm

Re: Get a log when i start a daemon?

Tue Jan 28, 2014 9:49 pm

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

User avatar
DougieLawson
Posts: 39301
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Get a log when i start a daemon?

Wed Jan 29, 2014 12:00 am

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
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Juel-dk
Posts: 10
Joined: Mon Jan 20, 2014 9:28 pm

Re: Get a log when i start a daemon?

Wed Jan 29, 2014 4:39 pm

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?

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: Get a log when i start a daemon?

Wed Jan 29, 2014 6:09 pm

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
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

User avatar
DougieLawson
Posts: 39301
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Get a log when i start a daemon?

Wed Jan 29, 2014 9:41 pm

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.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Return to “Raspberry Pi OS”