[PATCH] tbot_contrib/utils.py: collect some usefull linux utils

Harald Seiler hws at denx.de
Tue Apr 21 11:42:39 CEST 2020


Hello Wolfgang, Heiko,

On Mon, 2020-04-20 at 21:15 +0200, Wolfgang Denk wrote:
> Dear Harald,
> 
> In message <d77523ba0ac9577cb1dfcb75da1c7b756f11a9a9.camel at denx.de> you wrote:
> > > +        ret = lnx.exec("systemctl", "status", s, "--no-pager")
> > > +        if ret[0] != 0:
> > 
> > I think it is more robust to use `systemctl is-active` for this check.
> > Also, you can use `lnx.test()` which makes this a bit more concise:
> 
> Actually it is not.  For example, consider "tftp.service".
> On deman, systemd will start /usr/sbin/in.tftpd, and intis state
> systemctl will indeed report "is-active".  After the inactivity
> timeout, in.tftpd will terminate itself, to be restarted only upon a
> new tftp request.  In _this_ situation systemctl will report that
> tftp is NOT active:

I think the issue here is that you are checking the service unit,
tftp.service which is indeed not running (because it will be started on
demand).  Instead you need to check for the socket unit, tftp.socket which
_is_ active (which means, systemd is listening for incoming connections).

So the correct invocation would be

    $ systemctl is-active tftp.socket
    active

and respectively the testcase in tbot needs to be called with
`tftp.socket` as well.
 
> -> systemctl status tftp
> tftp.service - Tftp Server
>    Loaded: loaded (/usr/lib/systemd/system/tftp.service; indirect; vendor preset: disabled)
>    Active: inactive (dead) since Sun 2020-04-19 20:42:20 CEST; 17h ago
>      Docs: man:in.tftpd
>   Process: 2639904 ExecStart=/usr/sbin/in.tftpd -s /var/lib/tftpboot (code=exited, status=0/SUCCESS)
>  Main PID: 2639904 (code=exited, status=0/SUCCESS)
>       CPU: 510ms
> 
> Apr 19 20:23:44 pollux.denx.de systemd[1]: Started Tftp Server.
> ...
> Apr 19 20:42:20 pollux.denx.de systemd[1]: tftp.service: Succeeded.
> 
> -> systemctl is-active tftp
> inactive
> -> tftp localhost
> tftp> get ...
> tftp> quit
> -> systemctl is-active tftp
> active
> 
> From the tftpd man page:
> 
>        --timeout timeout, -t timeout
>               When run from inetd this specifies how long, in
>               seconds, to wait for a second connection before
>               terminating the server. inetd will then respawn the
>               server when another request comes in. The default is
>               900 (15 minutes.)
> 
> I agree this is pretty unexpected behaviour, and I even tend to call
> it a bug, but then - who am I to criticise systemd and related
> tools...
> 
> So Heiko's approach indeed makes sense.
> 
> Best regards,
> 
> Wolfgang Denk
> 

Regards,
-- 
Harald



More information about the tbot mailing list