Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2018-06-18 12:00 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (109 votes). Check out past polls.