Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: perl daemon accessing serial over usb

by Eliya (Vicar)
on May 30, 2012 at 21:33 UTC ( #973382=note: print w/ replies, xml ) Need Help??


in reply to perl daemon accessing serial over usb

Hardly anyone is going to wade through all the code and/or set up an environment where they can actually try to replicate the issue themselves.  So, to get more useful replies, you might want to add some more meta info, for example, what you've tried so far to debug the issue, and the results of those steps. Simple things like: does the daemon actually start and keep running when you invoke it via init.d, or does it die?  What (if anything) gets written to the syslog? Any other error messages?  Etc.

The environment the deamon runs in could be different depending on the way you start it, which might lead to stuff not being found, or similar...   Those ideas might seem trivial to you, but as you haven't said much about them, it's hard to tell whether they really are...  Thus this reply :)


Comment on Re: perl daemon accessing serial over usb
Re^2: perl daemon accessing serial over usb
by gordonendersby (Initiate) on May 31, 2012 at 11:56 UTC

    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?

      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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://973382]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2014-07-22 10:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (109 votes), past polls