Unable to run a script at boot via /etc/rc.d/rc/local

General support questions
Post Reply
mahmood
Posts: 122
Joined: 2017/06/04 12:21:09

Unable to run a script at boot via /etc/rc.d/rc/local

Post by mahmood » 2019/10/08 13:32:27

I want to run a bash script at the boot time using rc.local, however, it doesn't work. See:

Code: Select all

[root@hpc ~]# ls -l /root/boot_vnc.sh
-rwxrwxr-x 1 mahmood mahmood 242 Oct  8 16:13 /root/boot_vnc.sh
[root@hpc ~]# ls -l /etc/rc.d/rc.local
-rwxr-xr-x 1 root root 473 Oct  8 16:49 /etc/rc.d/rc.local
[root@hpc ~]# ls -l /etc/rc.local
lrwxrwxrwx 1 root root 13 Oct  6 13:15 /etc/rc.local -> rc.d/rc.local
[root@hpc ~]# cat /etc/rc.d/rc.local
[root@hpc mahmood]# cat /etc/rc.d/rc.local
#!/bin/bash
touch /var/lock/subsys/local
/root/boot_vnc.sh
After a reboot, the script won't be executed. Looking at system log, I see this:

Code: Select all

Oct  8 16:57:41 hpc systemd: Failed to start /etc/rc.d/rc.local Compatibility.
Oct  8 16:57:41 hpc systemd: Unit rc-local.service entered failed state.
Oct  8 16:57:41 hpc systemd: rc-local.service failed.
However, I don't know if those messages are really related to my script.

If I run the script from terminal, it works.

Code: Select all

[root@hpc ~]# cat boot_vnc.sh
#!/bin/bash
while read line; do
  echo "================="
  USER=`awk '{print $1}' <<<"$line"`
  ID=`awk '{print $2}' <<<"$line"`
  echo "starting" $USER "on :"$ID
done </root/vnc_list.txt
[root@hpc ~]# ./boot_vnc.sh
=================
starting mahmood on :1

I even tried chkconfig as below but received an error:

Code: Select all

[root@hpc ~]# chkconfig /root/boot_vnc.sh on
error reading information on service /root/boot_vnc.sh: No such file or directory
How can I fix that?
How can I debug more?

tunk
Posts: 1205
Joined: 2017/02/22 15:08:17

Re: Unable to run a script at boot via /etc/rc.d/rc/local

Post by tunk » 2019/10/08 13:40:42

You could try to use the full path to echo, awk etc., e.g. /usr/bin/echo

mahmood
Posts: 122
Joined: 2017/06/04 12:21:09

Re: Unable to run a script at boot via /etc/rc.d/rc/local

Post by mahmood » 2019/10/08 13:47:11

Yeah it works. Thanks for the tip.

mahmood
Posts: 122
Joined: 2017/06/04 12:21:09

Re: Unable to run a script at boot via /etc/rc.d/rc/local

Post by mahmood » 2019/10/08 14:00:04

Excuse me,
If I write

/root/boot_vnc.sh 2>&1 /root/boot_vnc.log

Then no log file is generated. However, there must be some outputs.

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Unable to run a script at boot via /etc/rc.d/rc/local

Post by TrevorH » 2019/10/08 14:15:55

I've got a nasty feeling that you should really be using systemctl enable vncserver@something for each user rather than writing your own script to do something hacky.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

mahmood
Posts: 122
Joined: 2017/06/04 12:21:09

Re: Unable to run a script at boot via /etc/rc.d/rc/local

Post by mahmood » 2019/10/08 17:51:19

Can you send a document on vncserver@something?

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Unable to run a script at boot via /etc/rc.d/rc/local

Post by TrevorH » 2019/10/08 18:13:13

If you yum install tigervnc-server then you get a systemd unit file out of the box called /usr/lib/systemd/system/vncserver@.service. That file has instructions in it about how to change it.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

mahmood
Posts: 122
Joined: 2017/06/04 12:21:09

Re: Unable to run a script at boot via /etc/rc.d/rc/local

Post by mahmood » 2019/10/08 18:25:10

Yes I have. I want to know if I have to copy this file only to /etc/systemd/system/vncserver@.service and then add multiple users in the service section. Like this:

Code: Select all

[Service]
Type=forking
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l u1 -c "/usr/bin/vncserver %i"
PIDFile=/home/u1/.vnc/%H%i.pid
ExecStart=/usr/sbin/runuser -l u2 -c "/usr/bin/vncserver %i"
PIDFile=/home/u2/.vnc/%H%i.pid
ExecStart=/usr/sbin/runuser -l u3 -c "/usr/bin/vncserver %i"
PIDFile=/home/u3/.vnc/%H%i.pid
ExecStart=/usr/sbin/runuser -l u4 -c "/usr/bin/vncserver %i"
PIDFile=/home/u4/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
Am I correct?

Post Reply