Here's the problem I face: I have a program that must run as root. I want that to run in a screen, but here's a twist: for admin reasons, I want to be able to re-attach to it.
I'm writing a dirty and fast restarter daemon, because the program keeps on failing in very misterious ways, that is running as sudo (because I need root priv. to start the app). However I don't want to simply run screen as sudo, because then screen -ls
won't show it, only sudo screen -ls
. If I run sudo -u USER screen -dmS SCREEN_NAME sudo APP
, it seems to work fine, it's listed with normal screen -ls, however there's a problem. If I want to check on the program, and try to reattach to the screen, after trying (and typing the password), the screen is terminated.
I don't have a problem with the password, the problem is that the reattached screen is terminating. Has anyone any suggestions, how I could start the screen from bash with these conditions?
screen
is terminating because the program is terminating. If you want to see its output you can either log it (use-L
) to examine the complete output afterwards, or, to see last few lines, start a shell with the screen and run your failing application from that shell. The screen won't exit until you exit the shell.With
-L
screen will append to a logfile if it exists. You can also suggest a different filename than the defaultscreenlog.N
(N being the screen number) with-Logfile
option.Upd: probably the confusion was caused by running
screen
inside sudo session likesudo screen
. In that case, screen is run as root (or other user if sudo was invoked with-u
argument) and you need to run subsequent operations also as that user. For example, to reattach,sudo screen -r
.