Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

My goal is an Arch based HTPC which on one tty runs XBMC and on another runs a minimalistic desktop (mainly for web browsing).

I haven't yet started on the XBMC slice of the pie, but at the moment it automatically logs in to the desktop user's account via

c1:2345:respawn:/sbin/agetty -a USERNAME -8 -s 38400 tty1 linux

then via ~/.bash_profile it does a startx which does a startxfce4. This is fine until you switch to another tty, then back to tty1. Upon switching back it seems to reexecute the ~/.bash_profile which then has a tantrum because an xsession is already running.

My questions are:

  1. Is this a sensible way of implementing a desktop & XBMC configuration? It was the easiest thing I could think of (not being particularly pro on linux) for me and the end user.

  2. Is there a way I can check for a correctly operating XFCE session running on tty1 and switch to it if there is, and run a new one if not?

  3. Or is there a better way of performing an auto-start of XFCE on login which wouldn't get called every time you switch to the console?

(Better ways of implementing this which don't directly answer these questions would be useful too; I'm aiming for light-weight & simple).

share|improve this question
add comment

1 Answer

I'm not sure I understand what you're trying to do.

If you want to start a logged-in graphical environment automatically, don't start a text session, log in directly in graphic mode, with an X display manager. For example, you can use LightDM, for which the Arch wiki has all the information you need:

  • Make sure that there is a line like this in your /etc/inittab:

    x:2345:respawn:/usr/sbin/lightdm >& /dev/null
    
  • Enable autologin in /etc/lightdm/lightdm.conf:

    [SeatDefaults]
    autologin-user=styne666
    autologin-user-timeout=0
    pam-service=lightdm-autologin
    

If you want to start a GUI only if there isn't one already, here's a way to detect whether you are logging in on a text console and there isn't an X server running yet. It isn't perfect (there will always be corner cases where this doesn't do what you wish it did, because “there is no X server running but it would make sense to start one” isn't a precise requirement), but should be good enough. Put this in your .bash_profile.

case $(tty) in
  /dev/tty[0-9]) # running on a text console
     if [ -z "$(ps -o pid= -C Xorg)" ]; then # if there no X running?
       x=yes
       trap 'x=; echo >&2 Will not start x.' INT
       echo >&2 'Starting X (press Ctrl+C *now* not to)...'
       sleep 2
       if [ -n "$x" ]; then # the user didn't press Ctrl+C
         exec startxfce4
       fi
     fi;;
esac
share|improve this answer
    
Thanks; you have given me a few ideas. –  Styne666 Sep 27 '12 at 8:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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