I'm trying to make my torrents get started with my server. A script is
at http://ubuntuforums.org/archive/index.php/t-859543.html that starts
it up in a detached screen session, but obviously the linux-ism of
that script won't work here. I pulled out the important bits and just
to start off wrote this script which I placed in ~/bin/scr:
#!/bin/sh
TAG=TAG=`date +%H%M%S`
sudo -u kousu -H /usr/local/bin/screen -d -m -S $TAG

If I run this script as myself or as root (to simulate running as
/etc/rc) it works:
$ sh bin/scr
$ screen -ls
There is a screen on:
        21423.152001    (Detached)
1 Socket in /tmp/uscreens/S-kousu.

$ sudo su
# cd /
# sh /home/kousu/bin/scr
# ^D
$ screen -ls
There are screens on:
        21423.152001    (Detached)
        22840.152333    (Detached)
2 Sockets in /tmp/uscreens/S-kousu.

$

So I added this to rc.local:
sh /home/kousu/bin/scr

But whenever I reboot I get this:
$ screen -ls
There is a screen on:
        12042.151112    (Dead ???)
Remove dead screens with 'screen -wipe'.
1 Socket in /tmp/uscreens/S-kousu.

I tried moving the "sh /home/kousu/bin/scr" to the very last line of
/etc/rc just in case, right before "exit 0" but still no luck.

I took a look at all the environment variables in the working and
broken cases and even copied all except the SUDO_* and SSH_* into my
script and got no difference, so the only remaining difference between
when I run it as a logged in user and when the system runs it for me
is that /etc/rc gets run under the the login class 'daemon'. But even
that seems wrong since I just added a test user with login class
'daemon', su'd in, and ran my script and when I came back to my user
account had a shiny new screen session waiting for me.

My only remaining theory is that getty(8) or login(1) is resetting the
terminals which might make screen(1) sad, but I have no idea how to
get error messages out of screen at boot time.

Interestingly, running rtorrent from my crontab as "@reboot screen -fa
-d -m -S torrents rtorrent" (thanks
http://www.plouj.com/blog/2008/03/31/howto-run-rtorrent-from-cron-inside-screen)
works and is simpler than having to sudo -u and give full paths for
everything so I'll just stick with that.

I'd still like to know what's going on here. Running things from boot
scripts appearently works on Linux, and a guy I asked last night
seemed to think my method should work on FreeBSD, so what is OpenBSD
doing that's upsetting screen?

Thanks for your attention,
-Nick

Reply via email to