Bug 11897 - checkvnc script fails on Centos 7 due to netstat being deprecated
Summary: checkvnc script fails on Centos 7 due to netstat being deprecated
Status: RESOLVED FIXED
Alias: None
Product: AutoBuilder
Classification: Infrastructure
Component: autobuilder (show other bugs)
Version: unspecified
Hardware: x86 Multiple
: Medium enhancement
Target Milestone: 2.4
Assignee: Tracy Graydon
QA Contact:
URL:
Whiteboard:
Depends on:
Blocks:
 
Reported: 2017-08-04 22:35 UTC by Tracy Graydon
Modified: 2017-09-13 09:09 UTC (History)
5 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: Don't know


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tracy Graydon 2017-08-04 22:35:32 UTC
When running checkvnc script on Centos 7, the script fails on missing netstat command. The netstat command is deprecated for Centos and ss is used instead.

A potential fix would be to replace the "netstat -tnl | grep :5901 > /dev/null" line in the checkvnc script with "grep ':170D' /proc/net/tcp > /dev/null"

i.e.

#!/bin/sh
#
# check if vnc server is running, and if not, cleanup and restart
#
grep ':170D' /proc/net/tcp > /dev/null
if [ $? != 0 ]; then
    echo "Xvnc not running, attempting restart"
    vncserver -kill :1
    vncserver
fi
Comment 1 Joshua Lock 2017-08-07 13:06:08 UTC
We have netstat installed on the CentOS 7 workers on the public Autobuilder clusters. 

$ yum provides /usr/bin/netstat

net-tools-2.0-0.17.20131004git.el7.x86_64 : Basic networking tools
Repo        : @base
Matched from:
Filename    : /usr/bin/netstat
Comment 2 Tracy Graydon 2017-08-07 16:49:22 UTC
I could certainly install the net-tools package on the meta-intel systems, but I am questioning whether or not we might want to update the script in anticipation of the general deprecation of net-tools and the rise of using ss (from iproute2) instead. i.e. We may eventually see checkvnc fail down the road on systems using OS that have dropped net-tools, as that becomes more common.

This is obviously not a big ole' fire or anything, but my feeling is that it would be better to update the script to move away from the deprecated net-tools (and netstat command), since it is a simple fix and actually just requires grep. But can't say I have my heart set on the outcome. ;)
Comment 3 Joshua Lock 2017-08-07 18:45:29 UTC
Oh, sure. Apologies, I hadn't internalised that net-tools is abandoned/deprecated.

Would we better off using ss instead?

[joshuagl@centos7 ~]$ netstat -tnl | grep :5901
tcp        0      0 0.0.0.0:5901            0.0.0.0:*               LISTEN     
tcp6       0      0 :::5901                 :::*                    LISTEN   
  
[joshuagl@centos7 ~]$ ss -tnl | grep :5901
LISTEN     0      5            *:5901                     *:*                  
LISTEN     0      5           :::5901                    :::*
Comment 4 Michael Halstead 2017-08-07 20:03:44 UTC
We could choose dynamically to depend on ss or netstat depending on which is available. I recommended just removing the dependency entirely since  /proc/net/tcp should work on all Linux hosts but I don't really care.
Comment 5 Tracy Graydon 2017-08-07 23:59:48 UTC
I concur with Michael. Going straight to grep, which will be ubiquitous, seems the cleanest. No mucking with searching for which package is installed and then conditionally executing. In either case, we would be passing that output to grep for the port. So, I'd vote for cutting to the chase and just using the /proc/net/tcp grep for port and call it good.
Comment 6 Joshua Lock 2017-08-08 08:46:21 UTC
Sure, let's do it
Comment 7 Tracy Graydon 2017-08-15 21:58:10 UTC
Submitted patch to yocto mailing list:

[Yocto #11897]

The checkvnc script uses deprecated netstat command for finding vnc sessions.
This breaks on Centos, and will break on other OS as it is removed in the
future.

Drop the dependency on netstat and instead grep /proc/net/tcp for
active sessions on 5901 port.

Signed-off-by: Graydon, Tracy <tracy.graydon@intel.com>
---
bin/checkvnc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bin/checkvnc b/bin/checkvnc
index d934dfa..11e03bb 100755
--- a/bin/checkvnc
+++ b/bin/checkvnc
@@ -2,7 +2,7 @@
#
# check if vnc server is running, and if not, cleanup and restart
#
-netstat -tnl | grep :5901 > /dev/null
+grep ':170D' /proc/net/tcp > /dev/null
if [ $? != 0 ]; then
     echo "Xvnc not running, attempting restart"
     vncserver -kill :1
--
2.7.0

--


Also can be found on yocto-autobuilder branch contrib/tgraydon/checkvnc-11897