1

On CentOS 7.

I have edited /etc/rc.d/rc.local, and made it executable, and I am starting a screen session from it.

Problem is, when I log to server as root, I am not seeing screen sessions started from rc.local, under screen -ls run as root user.

If I do ps axuf | grep -i screen, I see screen sessions are active, and I can see processes inside screen are running.

How do I attach myself to this screen sessions?

My rc.local section for screen looks something like this.

/usr/bin/screen -wipe
/usr/bin/screen -dmS scr1 /script/rsync1.sh
/usr/bin/screen -dmS scr2 /script/rsync2.sh
/usr/bin/screen -dmS scr3 /script/rsync3.sh
/usr/bin/screen -dmS scr4 /script/rsync4.sh
/usr/bin/screen -dmS scr5 /script/rsync5.sh

I can see screen sessions are started with ps auxf after server boot.

root@server [~]# ps auxf | grep -i screen
root       90642  0.0  0.0 112648   988 pts/0    S+   21:54   0:00          \_ grep --color=auto -i screen
root        3384  0.0  0.0 127784  2212 ?        Ss   21:33   0:00 /usr/bin/SCREEN -dmS scr1 /script/rsync1.sh
root        3390  0.0  0.0 127784  2252 ?        Ss   21:33   0:00 /usr/bin/SCREEN -dmS scr2 /script/rsync2.sh    
root        3393  0.0  0.0 127784  2252 ?        Ss   21:33   0:00 /usr/bin/SCREEN -dmS scr3 /script/rsync3.sh
root        3398  0.0  0.0 127784  2252 ?        Ss   21:33   0:00 /usr/bin/SCREEN -dmS scr4 /script/rsync4.sh
root        3403  0.0  0.0 127784  2248 ?        Ss   21:33   0:01 /usr/bin/SCREEN -dmS scr5 /script/rsync5.sh

If i try to do screen -r scr1, I will get that there is no such screen running.

Sessions are running as root, so I am not sure why am I not able to see them.

I have tried adding /usr/bin/sudo to beginning of commands, but then it fails to start completely.

Jul 10 22:07:37 server systemd[1]: Starting /etc/rc.d/rc.local Compatibility...
Jul 10 22:07:39 server rc.local[3645]: sudo: sorry, you must have a tty to run sudo
Jul 10 22:07:39 server rc.local[3645]: sudo: sorry, you must have a tty to run sudo
Jul 10 22:07:39 server rc.local[3645]: sudo: sorry, you must have a tty to run sudo
Jul 10 22:07:39 server rc.local[3645]: sudo: sorry, you must have a tty to run sudo
Jul 10 22:07:39 server rc.local[3645]: sudo: sorry, you must have a tty to run sudo
Jul 10 22:07:39 server systemd[1]: rc-local.service: control process exited, code=exited status=1
Jul 10 22:07:39 server systemd[1]: Failed to start /etc/rc.d/rc.local Compatibility.
Jul 10 22:07:39 server systemd[1]: Unit rc-local.service entered failed state.
Jul 10 22:07:39 server systemd[1]: rc-local.service failed.

Also, the screen -wipe on the start, doesn't seem to affect sessions that were started manually outside rc.local.

In case server crashes, screens that were started manually will still be shown as dead in screen -ls under root.

I have added this to rc.local, and not to crontab with @reboot, because that would not work in case system crashes or gets powered off/shutdown without reboot, it would only get triggered on reboots, as far as I understand @reboot in cron.

Solved by Stephen Harris comment about $SCREENDIR.

In your startup script do a screen -ls > /tmp/xyzzy.$$ (or similar filename) - that'll tell you what directory it has stored the sockets in. You may need to set $SCREENDIR to point to this directory in order to see the sessions when trying to re-attach. – Stephen Harris 10 hours ago

rc.local used /var/run/screen/S-root as SCREENDIR

root used /root/screens as SCREENDIR, which is why it didn't see sessions from rc.local

Note:

It is not needed to add screen -ls > /tmp/xyzzy.$$ to rc.local to find which folder is used as SCREENDIR. It can be seen by doing systemctl status rc-local, it will show something like this in output

rc.local[3258]: No Sockets found in /var/run/screen/S-root.

After doing export SCREENDIR=/var/run/screen/S-root screen -ls shows screens started from rc.local

  • imo, you should not be using /usr/bin/SCREEN in your rc.local , you should use /usr/bin/screen – amisax Jul 11 '16 at 5:49
  • it is /usr/bin/screen in rc.local it is only /usr/bin/SCREEN in ps output, I corrected the question. – rAlen Jul 11 '16 at 6:00
  • The screen -wipe should be unnecessary. You don't have another screen wipe that runs after your rc.local? – roaima Jul 11 '16 at 7:59
  • screen -wipe is to remove dead screens in case system crashes. In case of system crash server resets with dead screen sessions. – rAlen Jul 11 '16 at 8:17
  • 2
    In your startup script do a screen -ls > /tmp/xyzzy.$$ (or similar filename) - that'll tell you what directory it has stored the sockets in. You may need to set $SCREENDIR to point to this directory in order to see the sessions when trying to re-attach. – Stephen Harris Jul 11 '16 at 10:45
0

Solved by Stephen Harris comment about $SCREENDIR.

In your startup script do a screen -ls > /tmp/xyzzy.$$ (or similar filename) - that'll tell you what directory it has stored the sockets in. You may need to set $SCREENDIR to point to this directory in order to see the sessions when trying to re-attach. – Stephen Harris 10 hours ago

rc.local used /var/run/screen/S-root as SCREENDIR

root used /root/screens as SCREENDIR, which is why it didn't see sessions from rc.local

Note:

It is not needed to add screen -ls > /tmp/xyzzy.$$ to rc.local to find which folder is used as SCREENDIR. It can be seen by doing systemctl status rc-local, it will show something like this in output

rc.local[3258]: No Sockets found in /var/run/screen/S-root.

After doing export SCREENDIR=/var/run/screen/S-root screen -ls shows screens started from rc.local

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.