Link to home
Start Free TrialLog in
Avatar of Support Engineer
Support Engineer

asked on

Problem with booting yad script on startup with CentOS 7

CentOS 7 booting yad script on startup, tried making service script but when starting the service the status give me the following:

[patrol@ppt_ae33sf etc]$ systemctl status rc-local
  rc-local.service - /etc/rc.d/rc.local Compatibility
    Loaded: loaded (/usr/lib/systemd/system/rc-local.service; static; vendor preset: disabled)
    Active: active (exited) since Thu 2019-05-30 12:21:27 EDT; 2h 19min ago
      Tasks: 0

May 30 12:21:26 ppt_ae33sf systemd[1]: Starting /etc/rc.d/rc.local Comaptibility...
May 30 12:21:27 ppt_ae33sf yad[5506]: cannot open display:
May 30 12:21:27 ppt_ae33sf sudo[5789]:                root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/bin/nmtui
May 30 12:21:27 ppt_ae33sf sudo[5789]: pam_limits(sudo:session): invalid line '* -nofile 2048' - skipped
May 30 12:21:27 ppt_ae33sf sudo[5789]: pam_limits(sudo:session): invalid line '* -nofile 2048' - skipped
May 30 12:21:26 ppt_ae33sf rc.local[5494]: Your terminal lacks the ability to clear the screen or position the cursor.
May 30 12:21:27 ppt_ae33sf yad[5506]: cannot open display:
May 30 12:21:26 ppt_ae33sf systemd[1]: Started /etc/rc.d/rc.local Comaptibility.


It looks like Yad is trying to access a open display. is their a way to prevent this or a way to bypass the message and make this script start on startup? any help is greatly appreciated.
Avatar of David Favor
David Favor
Flag of United States of America image

1) It appears your /etc/security/limits file (or CentOS equivalent) is corrupt. Best fix this or all manner of super odd problems will crop up throughout your system.

You'll know this is fixed when the invalid line '* -nofile 2048' - skipped lines disappear.

This might also be due to your /etc/rc.local contents.

2) Attach your /etc/rc.local file (as text, not an image).

3) However you start yad on the command line (interactively), execute the command + attach the entire output (as text, not an image).

Tip: The entire point of yad is to all scripts to generate GTK dialogs, so it makes no sense to startup yad in /etc/rc.local, so likely the real question here is for you to describe why you're trying to product a GTK dialog inside a non-interactive, boot time script.
Avatar of Support Engineer
Support Engineer

ASKER

Hi David,

The main reason we are using yad is to have a friendly user GUI to get to nmtui, set hostname, and troubleshoot certain areas of their network (without using Python, Java, etc...). We don't want them to have to start up the yad script themselves, we want it already open and running when the linux system boots up (it is on a VM). But its sounding like we maybe better off just using Python or Java for this instead.

Here is our rc.local file:

#!/bin/sh -e
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
sh /etc/init.d/ParkView/ParkViewStartup.sh

exit 0
~
~
~
Using Python or Java, seems overkill to me.

Also nmtui won't work, because this still requires human interaction, while your running in batch/non-interactive mode

Just do all this using BASH or PERL.

Here's a simple hostname setting script I use...

#!/usr/bin/env perl

use strict;
use warnings;

sub docmd ($) {
    my $cmd = shift;
    print $cmd, "\n";
    system($cmd);
}

die "Please specify the new hostname + try again...\n" unless @ARGV;

my $newhost  = shift @ARGV;
my $newshort = $newhost; $newshort =~ s/\..++//o;

docmd("echo $newhost > /etc/hostname");
docmd("echo $newhost > /proc/sys/kernel/hostname");
docmd("sed -i 's/127.0.1.0.*/127.0.1.0\t\'\"localhost.localdomain localhost\"\'/g' /etc/hosts");
docmd("sed -i 's/127.0.1.1.*/127.0.1.1\t\'\"$newhost $newshort\"\'/g' /etc/hosts");

# this fails to start (stop/waiting forever) + should be debugged sometime
#docmd("service hostname restart");

docmd("hostname $newhost");

Open in new window


Note: My simple script is just one way to accomplish hostname setting.

Tip: My opinion.... Once you set your hostname... never, ever, ever muck around with your hostname during your boot process.

This will cause all manner of impossible to debug problems.

You should set your hostname once, interactively, as root.

If you muck around with hostname setting in your boot process, anytime someone changes the hostname interactively, next boot hostname will reset to something else.

This can leave many people pulling their hair out trying to debug phantom hostname changes.
i am not familiar with yad....
It does seem quite convoluted to require to have an active X11 (or wayland) server + GTK (+ GNOME  or  any other windowing framework)  up and running while still having a need to configure the basic system. Or just to ask a question.
If you need dialogs from shell why not use the one that is used in the installers:  dialog.
https://www.systutorials.com/docs/linux/man/1-dialog/

host names are mostly setup while the system being setup has never run before [ CDROM based installers f.e. ]. It can be changed though, the hostname setup SHOULD be done before any service is being started. If services are started best is to restart them all.
During system boot mostly a very limited console environment is available, if it is graphics there are severe restraints on available graphics drivers.

IMO it is much easier to use shell scripting (and if task get more complex, use a scripting language that can handle the more complex code like Python, Perl, etc.
Python and Perl are on the comparable level of functionality and availability of libraries. Most important choice is what are you most familiar with,

[ Most installers are shell scripts btw. although some installers have a special set scripting tool (RedHat). ]
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.