Cannot run a program at boot that uses a serial device

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Cannot run a program at boot that uses a serial device

Mark Barton-2
I have a couple of Python programs that will no
longer start at boot time.  This was working until
yesterday afternoon just after a did a reboot.
There haven't been any changes to either program,
but I did do an update (upgrade and dist-upgrade)
a few days ago. I cannot recall if I did a reboot
at the time though. I'm guessing that I did not do
the reboot until yesterday and that my problem
might be due to the upgrade.  Using systemctl
status command revealed that  USB serial device
could not be found which caused the abort. It
seems my programs are getting executed before the
devices are available. I can however manually
start the programs using systemctl after the
system is finish booting. After some searching I
found what is needed to setup a udev rule to wait
until a specific tty device is available, but it
didn't work. The is a difference between my udev
rule is that I am using a symlink device name and
the example used the actual  ttyUSBx device name.

My udev rule:

SUBSYSTEM=="tty", ATTRS{idVendor}=="0403",
ATTRS{idProduct}=="6001",
ATTRS{serial}=="A10xxxx", SYMLINK+="ttyEmon",
GROUP="dialout", OWNER="root"
SUBSYSTEM=="tty", KERNEL=="ttyEmon",
TAG+="systemd",
ENV{SYSTEMD_WANTS}+="home-energy.service"

And my systemd service:

#service file for starting/stopping home-energy.py

[Unit]
Description=home-energy startup

[Service]
Type=simple
ExecStart=/usr/local/bin/home-energy.py

[Install]
#commented out because a udev rule checks for
/dev/tty... availability
#WantedBy=multi-user.target


Running Ubuntu 16.04

Any pointers on how the best to debug is appreciated

Mark


--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: Cannot run a program at boot that uses a serial device

Oliver Grawert
hi,
Am Dienstag, den 16.10.2018, 07:46 -0400 schrieb Mark Barton:


> My udev rule:
>
> SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", 
> ATTRS{idProduct}=="6001", 
> ATTRS{serial}=="A10xxxx", SYMLINK+="ttyEmon", 
> GROUP="dialout", OWNER="root"
> SUBSYSTEM=="tty", KERNEL=="ttyEmon", 
> TAG+="systemd", 
> ENV{SYSTEMD_WANTS}+="home-energy.service"
>
why waste cycles to systemd here, just use a RUN= statement in the udev
rule:
 
SUBSYSTEM=="tty", 
ATTRS{idVendor}=="0403", 
ATTRS{idProduct}=="6001", 
ATTRS{serial}=="A10xxxx",  
RUN+="/usr/local/bin/home-energy.py"

(if your script actually needs the symlink create this as a searate
rule with a higher number prefix than the one creating the link)

ciao
        oli
--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users

signature.asc (188 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Cannot run a program at boot that uses a serial device

Colin Watson
On Sat, Oct 20, 2018 at 10:08:08AM +0200, Oliver Grawert wrote:
> why waste cycles to systemd here, just use a RUN= statement in the udev
> rule:
>  
> SUBSYSTEM=="tty", 
> ATTRS{idVendor}=="0403", 
> ATTRS{idProduct}=="6001", 
> ATTRS{serial}=="A10xxxx",  
> RUN+="/usr/local/bin/home-energy.py"

That only works if home-energy.py has a brief runtime.  I had the
impression (perhaps wrongly) that it was a long-running process.

--
Colin Watson                                       [[hidden email]]

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: Cannot run a program at boot that uses a serial device

Mark Barton-2
On 10/20/18 6:38 AM, Colin Watson wrote:

> On Sat, Oct 20, 2018 at 10:08:08AM +0200, Oliver Grawert wrote:
>> why waste cycles to systemd here, just use a RUN= statement in the udev
>> rule:
>>  
>> SUBSYSTEM=="tty",
>> ATTRS{idVendor}=="0403",
>> ATTRS{idProduct}=="6001",
>> ATTRS{serial}=="A10xxxx",
>> RUN+="/usr/local/bin/home-energy.py"
> That only works if home-energy.py has a brief runtime.  I had the
> impression (perhaps wrongly) that it was a long-running process.
>
Yes it cranks up at boot time and stays running
forever. It reads an energy monitoring devices and
sends data to a MQTT broker. I actually have
several of these programs connected to difference
devices.

I plan to upgrade to 18.04 soon and will explore
why I cannot get the systemd "wait on serial" to
work if the problem persists.

Thanks for the info.

Mark


--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users