Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^2: perl daemon accessing serial over usb

by gordonendersby (Initiate)
on May 31, 2012 at 11:56 UTC ( #973504=note: print w/replies, xml ) Need Help??

in reply to Re: perl daemon accessing serial over usb
in thread perl daemon accessing serial over usb

Thanks for looking. I just put the code in for completeness. As usually you get moaned at for not including it. Ill rephrase my question.

Its advice Im after from someone who might have done something similar with perl, daemons and serial/usb. What I suspect is that theres a gotcha with Device::SerialPort or something to do with the run levels that Im missing.

When I run it from the command line directly calling the script with -d for debug. syslog shows all the debug I expect to see and it communicates with the arduino over serial/usb exactly as expected.

When I run it through inet.d using "sudo service zoneswitch start" with debug set in the inet.d bash script syslog shows all the debug messages as expected but nothing goes over the serial/usb connection to the arduino. Obviously all errors from the script are lost as Im running it as a daemon using Proc::Daemon.

In both cases there are no errors from the module Device::SerialPort when I pass it the serial port I want. If the device isnt plugged in my script waits and tries again until it is available. So syslog would show waiting debug messages. So the script seems to be connecting to the serial port ok.

Is that enough info, or is there something Ive missed?

  • Comment on Re^2: perl daemon accessing serial over usb

Replies are listed 'Best First'.
Re^3: perl daemon accessing serial over usb
by gordonendersby (Initiate) on Jun 06, 2012 at 18:28 UTC

    Got there in the end. Several things caught me out.

    First, dirty test environment. I wasnt making sure that any processes started during testing were killed. Stupid mistake by me caused some confusion while trying to work out what was happening. Of course this shouldnt be able to happen if the pid files worked correctly. see Second point

    Second, pid files part 1 The skeleton bash script in init.d doesnt make it clear that pid files arnt created by start-stop-daemon when you give it the path to the pid file. You have to make sure that you set --make-pidfile to create the pid file or it assumes your service/daemon creates the pid file.

    Third, pid files part 2 When start-stop-daemon is called with --make-pidfile, it doesnt know anything about any forking within your service/script. It creates the pid file with the pid before forking. So any further calls of start-stop-daemon wont work as the pid file is not associated with the forked process.

    As I said got there in the end, just need to put the logic into my perl service/daemon to handle the pid file and locking rather than relying on the init.d script and start-stop-daemon as I assumed you could. Hopefully if someone else tries something like this, the above will help

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://973504]
[Discipulus]: Eily tongue twister or votes? ;=)
[Eily]: Discipulus turn me into a Bishop
Discipulus abracadabra.. Eily tranformed into a.. shop for bisexual peoples..
[LanX]: Eily don't be sad ... you are the Bishop of our hearts.
[marto]: 1nickt, I just said that in a Sean Connery accent
[LanX]: Discipulus++ # Bi-Shop
[Eily]: is the Bishop of hearts higher or lower ranked than the Jack?
[ambrus]: Higher.
[Eily]: Discipulus what's the merchandise? Other bi-people?
[1nickt]: marto would like to hear that. Of course he speaks very deliberately and dramatically, allowing pauses between words, so if anybody could pull it off it would be him, or someone impersonating him ...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (13)
As of 2017-09-26 12:07 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (294 votes). Check out past polls.