Difference between revisions of "Frontend Auto Login"

From MythTV Official Wiki
Jump to: navigation, search
(overhaul, bit by bit, part 1, inittab rewritten)
(overhaul, bit by bit, part 2, UpStart)
Line 23: Line 23:
 
}}
 
}}
  
The exact number of virtual, ttyX, terminals will vary. Here the user will either replace, or add to the list the mingetty command. The user can also at this point decide if they wish to run fewer virtual terminals. This can save valuable memory for those running on low memory systems, but the amount is small; or they can eliminate them for "aesthetic" reasons.
+
The exact number of virtual, ttyX, terminals will vary. Here the user will either replace, or add to the list the mingetty command. The user can also at this point decide if they wish to run fewer virtual terminals. This can save valuable memory for those running on low memory systems, but the amount is small; or they can eliminate them for "aesthetic" reasons. It is not recommended to only have the one MythTV terminal as a minimum of one standard should be kept in case of emergency.
  
 
As such, one of the lines will need to look similar to,
 
As such, one of the lines will need to look similar to,
Line 44: Line 44:
  
 
=== UpStart ===
 
=== UpStart ===
 +
UpStart is one of the newer initialization systems written by Canonical for use in their Ubuntu distribution, and it's sub distributions Mythbunut, Kubuntu, etc. UpStart does not use the ''inittab'' file for login terminals. UpStart, like the init system uses scripts to launch daemons, etc. The user will find ttyX.conf files in their ''/etc/init'' directory where UpStart stores these files.
  
 +
Here the user can decide to add to the virtual terminals and create a new one, or replace an existing one, and of course able to limit the number of virtual terminals as described above, again, keeping at least one standard terminal in case of emergency.
 +
 +
The standard ''ttyX.conf'' file will look like,
 +
{{Code box|/etc/init/tty6.conf|
 +
<pre>
 +
# tty6 - getty
 +
#
 +
# This service maintains a getty on tty6 from the point the system is
 +
# started until it is shut down again.
 +
 +
start on runlevel [23]
 +
stop on runlevel [!23]
 +
 +
respawn
 +
exec /sbin/getty -8 38400 tty6
 +
</pre>
 +
}}
 +
 +
The specifics, like the runlevel, may be different depending on your specific distribution. We will assume that you have the correct runlevels if you choose a terminal script that launches upon standard boot, as the template.
 +
 +
Thus, to use mingetty to login your mythtv user your ''ttyX.conf'' should look similar to,
 +
{{Code box|/etc/init/tty6.conf|
 +
<pre>
 +
# tty6 - getty
 +
#
 +
# This service maintains a getty on tty6 from the point the system is
 +
# started until it is shut down again.
 +
 +
start on runlevel [23]
 +
stop on runlevel [!23]
 +
 +
respawn
 +
exec /sbin/mingetty --autologin=mythtv tty7
 +
</pre>
 +
}}
 +
 +
This line, like above, upon reboot, will cause a virtual terminal 6 to be created and the user mythtv will automatically, '''with no password prompt''', be logged in.
 +
 +
As well, like above, you may also need to add the following to your '/etc/login.defs' file to allow a no password login,
 +
{{Code box|/etc/login.defs|
 +
<pre>
 +
NO_PASSWORD_CONSOLE tty7
 +
</pre>
 +
}}
  
 
=== .bash_profile ===
 
=== .bash_profile ===

Revision as of 14:34, 24 July 2010

Part of a proper frontend system is having it automatically login as the mythtv user and loading mythfrontend. There are a variety of methods to do this. KDM allows for auto-login, but doesn't handle mythfrontend crashes well. The best method is to use inittab to login the user straight into mythfrontend.

Option 1

The first option involves using the system's initialization scripts to automagically log in as the mythtv user (or whichever user you wish to run the MythTV frontend as) without using a graphical log in manager, and have mythfrontend launch. The user can then choose whether to use a GUI or to run "window-less".

Setup

The standard command line login is considered a "virtual" terminal and uses a program called getty to provide the login prompt. We will replace the standard getty with an alternative, mingetty, which allows for an autologin feature. Depending on your chosen distribution one of the following methods will work for you, (may need to be slightly amended for your distribution)

inittab

inittab is one of the older initialization systems for SysV.

Initiall your inittab will look like,

Script.png /etc/inittab

# inittab for linux
id:1:initdefault:
rc::bootwait:/etc/rc
1:1:respawn:/etc/getty 9600 tty1
2:1:respawn:/etc/getty 9600 tty2
3:1:respawn:/etc/getty 9600 tty3
4:1:respawn:/etc/getty 9600 tty4

The exact number of virtual, ttyX, terminals will vary. Here the user will either replace, or add to the list the mingetty command. The user can also at this point decide if they wish to run fewer virtual terminals. This can save valuable memory for those running on low memory systems, but the amount is small; or they can eliminate them for "aesthetic" reasons. It is not recommended to only have the one MythTV terminal as a minimum of one standard should be kept in case of emergency.

As such, one of the lines will need to look similar to,

Script.png /etc/inittab

7:12345:respawn:/sbin/mingetty --autologin=mythtv tty7

The first portion of the line, is the id for that entry. It is generally accepted that a line with a single number for the id is to designate the launch of a virtual terminal. Adding a letter, A, B, or C will cause the line to be considered OnDemand. This is left to the user to google and decide whether it is how they would like their system set up. For the sake of this exercise in use with MythTV we will omit the letter.

This line, upon reboot, will cause a virtual terminal 7 to be created and the user mythtv will automatically, with no password prompt, be logged in.

You may also need to add the following to your '/etc/login.defs' file to allow a no password login,

Script.png /etc/login.defs

NO_PASSWORD_CONSOLE tty7

UpStart

UpStart is one of the newer initialization systems written by Canonical for use in their Ubuntu distribution, and it's sub distributions Mythbunut, Kubuntu, etc. UpStart does not use the inittab file for login terminals. UpStart, like the init system uses scripts to launch daemons, etc. The user will find ttyX.conf files in their /etc/init directory where UpStart stores these files.

Here the user can decide to add to the virtual terminals and create a new one, or replace an existing one, and of course able to limit the number of virtual terminals as described above, again, keeping at least one standard terminal in case of emergency.

The standard ttyX.conf file will look like,

Script.png /etc/init/tty6.conf

# tty6 - getty
#
# This service maintains a getty on tty6 from the point the system is
# started until it is shut down again.

start on runlevel [23]
stop on runlevel [!23]

respawn
exec /sbin/getty -8 38400 tty6

The specifics, like the runlevel, may be different depending on your specific distribution. We will assume that you have the correct runlevels if you choose a terminal script that launches upon standard boot, as the template.

Thus, to use mingetty to login your mythtv user your ttyX.conf should look similar to,

Script.png /etc/init/tty6.conf

# tty6 - getty
#
# This service maintains a getty on tty6 from the point the system is
# started until it is shut down again.

start on runlevel [23]
stop on runlevel [!23]

respawn
exec /sbin/mingetty --autologin=mythtv tty7

This line, like above, upon reboot, will cause a virtual terminal 6 to be created and the user mythtv will automatically, with no password prompt, be logged in.

As well, like above, you may also need to add the following to your '/etc/login.defs' file to allow a no password login,

Script.png /etc/login.defs

NO_PASSWORD_CONSOLE tty7

.bash_profile

In that home directory, create/edit a .bash_profile file like this,

Script.png .bash_profile

if [ -z "$DISPLAY" ] && [ $(tty) == /dev/tty7 ]; then
while [ 1 == 1 ]
     do
          startx
          sleep 10
     done
fi

this will start X only if running on virtual terminal 7, so if you telnet or ssh into the box it will not react strange. It will also restart X if the frontend crashes.

.xinitrc

There are two options for .xinitrc, one will load a window manager, the other will not.

No Window Manager

For no windowmanager, create/edit the user's .xinitrc and add,

Script.png .xinitrc

xset -dpms s off
xsetroot -solid black
mythfrontend -l /home/mythtv/mythfrontend.log
#mythtv-setup
#xterm

This will turn off dpms, turn the X default background color black and log to /home/mythtv/mythfrontend.log, this can be changed. Also included is an easy way to access mythtv-setup or xterm, just uncomment the appropriate line and comment out the mythfrontend line.

You should note that running mythfrontend without a window manager is not a supported configuration. You may run into focus problems when trying to press buttons, enter text and generally use the system.

fvwm

To use fvwm, edit your .xinitrc like,

Script.png .xinitrc

xset -dpms s off
xsetroot -solid black
x11vnc -many -q -bg -rfbauth .vnc/passwd
fvwm2 &
mythfrontend -l /home/mythtv/mythfrontend.log 2>&1
#mythtv-setup
#xterm

Next edit your .fvwm2rc,

Script.png .fvwm2rc

#Set Windows Styles
Style "*" RandomPlacement, DumbPlacement
Style myth* NoTitle, NoHandles, Sticky, WindowListSkip, SloppyFocus, GrabFocus, 
BorderWidth 0, HilightFore Black, HilightBack #c06077, Color Black/#60a0c0
Style xmame* NoTitle, NoHandles, Sticky, WindowListSkip, SloppyFocus, GrabFocus, 
BorderWidth 0, StaysOnTop,BoundaryWidth 0, HilightFore Black, HilightBack #c06077, 
Color Black/#60a0c0
Style mplayer* NoTitle, NoHandles, Sticky, WindowListSkip, SloppyFocus, GrabFocus, 
BorderWidth 0, HilightFore Black, HilightBack #c06077, Color Black/#60a0c0
Style xine* NoTitle, NoHandles, Sticky, WindowListSkip, SloppyFocus, GrabFocus, 
BorderWidth 0, HilightFore Black, HilightBack #c06077, Color Black/#60a0c0

#set the desk top size in units of physical screen size
DeskTopSize 1X1

# Starts mythfrontend from the keyboard using F1
Key F1  R   A   exec /usr/local/bin/mythfrontend -v important,general -l /var/log/mythfrontend.log 2>&1

ratpoison

Another popular window manager is ratpoison. This version of the .xinitrc file also allows you to use vnc to connect to your frontend (as the fvwm example above) and rotates the log files at each restart of the frontend.

Script.png .xinitrc

xset -dpms s off
xsetroot -solid black
ratpoison &
x11vnc -many -q -bg -rfbauth .vnc/passwd
mythfrontend > /home/mythtv/mythfrontend.log 2>&1
for i in 5 4 3 2 1 ; do
  if [ -f mythfrontend.log.$i ]; then
    mv -f mythfrontend.log.$i  mythfrontend.log.$(($i + 1))
  fi
done
mv mythfrontend.log  mythfrontend.log.1

And the associated .ratpoisonrc file. Note that the mythtvstart.jpg file is just something knocked up with the GIMP.

Script.png .ratpoisonrc

# This is a sample .ratpoisonrc file
#
# Set the prefix key to that of screen's default
escape C-a

# put something informative on the screen while we load stuff
exec xloadimage -onroot -quiet -center /home/mythtv/.mythtv/mythtvstart.jpg

# Gets rid of that ugly crosshairs default cursor and set the background to black
exec xsetroot -cursor_name left_ptr

# Use the name of the program rather than the title in the window list
defwinname name

### fire up an xterm with ctrl-A x
bind x exec xterm -j -fn '*-courier-*-r-*-14-*'

# Since running a 720x576 definition the ratpoison screens are too big for the
# display so we reduce the size of them with defpadding to make them fit
#defpadding 25 25 25 25

keystate_numlock = enable

Option 2

If the above instructions don't give you results you like, there is another option to autologin. You can use inittab to login as the mythtv user and launch X all at once, without having to create a .bash_profile script.

Find the following line in your /etc/inittab file:|

6:2345:respawn:/sbin/getty 38400 tty6

And comment it out by adding the "#" symbol in front of it:

#6:2345:respawn:/sbin/getty 38400 tty6

Then add this line directly under the line you just commented out:

6:2345:respawn:/usr/bin/openvt -fwc 2 -- /bin/su - mythtv -c /usr/bin/startx >& /dev/null

Note: you should test the command to verify that the the mythtv user is authorized to start the X server. If not, modify your /etc/X11/Xwrapper.conf file to include:

allowed_users=anybody

This command starts X as the mythtv user, and will restart X automatically if MythTV crashes. This option has the advantage that if your distribution has a graphical boot sequence like Ubuntu, Red Hat, Mandriva, etc, then you won't see any text before Myth starts. It looks a little more professional. This also means that you don't have to create a .bash_profile script. Edit your .xinitrc file according to the directions above and you are done.

Some may prefer this method of logging in and starting X to the method above because X prefers to use tty 7 and the method above may cause problems.

Note on inittab option 2 and runlevels

If you want to be able to easily change between auto-login and normal xdm login you can restrict the autologin to eg. runlevel 3, so the auto-start line is /etc/inittab looks like this:

6:3:respawn:/usr/bin/openvt -fwc 2 -- /bin/su - mythtv -c /usr/bin/startx >& /dev/null

The default runlevel specification in inittab can then be set to 3 for auto-login or 5 for X-login.

id:3:initdefault:             # auto-login to MythTv

If you have booted in auto-login mode and want to change to X-login mode you can just change run level with the init command:

/sbin/init 5

or back to mythtv mode with:

/sbin/init 3

Note on Ubuntu Edgy (6.10)

Important.png As of Ubuntu Edgy, inittab is no longer an option for an automatic login setup. However, you can use Gnome to automatically login and run mythfrontend. Note that this option requires Gnome and X.

First, edit your /etc/gdm/gdm.conf-custom file:

Script.png /etc/gdm/gdm.conf-custom

[daemon]
AutomaticLoginEnable=true
AutomaticLogin=mythtv

Next, create and edit .gnomerc in the user's home folder:

touch /home/mythtv/.gnomerc
chmod 755 .gnomerc

Now edit this file and add the following line:

sleep 10 && mythfrontend > /tmp/mythfrontend.log 2>&1 &

Note on Ubuntu Gutsy (7.10) through Hardy Heron (8.04)

Important.png This method has been verified on all newer releases of (K/Myth)Ubuntu up to Hardy Heron LTS. This method is similar to the inittab method above and requires mingetty and a .bash_profile and .xinitrc file in the mythtv users' home directory.

First copy /etc/event.d/tty6 to /etc/event.d/tty7 change it from:


Script.png /etc/event.d/tty7

# tty6 - getty
#
# This service maintains a getty on tty6 from the point the system is
# started until it is shut down again.

start on runlevel 2
start on runlevel 3

stop on runlevel 0
stop on runlevel 1
stop on runlevel 4
stop on runlevel 5
stop on runlevel 6

respawn
exec /sbin/getty 38400 tty6

to

Script.png /etc/event.d/tty7

# tty7 - mingetty for MythTV
#
# This service maintains a mingetty on tty7 from the point the system is
# started until it is shut down again.

start on runlevel 2

stop on runlevel 0
stop on runlevel 1
stop on runlevel 3
stop on runlevel 4
stop on runlevel 5
stop on runlevel 6

respawn
exec /sbin/mingetty --autologin=mythtv tty7

This will only run on the Ubuntu default runlevel of 2 allowing the user to switch to runlevel 3 to disable MythTV but still maintain a GUI setup.

If you want to use the openvt method mentioned above then this will also work:

Script.png /etc/event.d/tty7

# tty7 - openvt for MythTV
#
# This service maintains a mythtv session on tty7 from the point the system is
# started until it is shut down again.

start on runlevel 2

stop on runlevel 0
stop on runlevel 1
stop on runlevel 3
stop on runlevel 4
stop on runlevel 5
stop on runlevel 6

respawn
exec /usr/bin/openvt -fwc 2 -- /bin/su - mythtv -c /usr/bin/startx
console none

Note on Ubuntu Karmic (9.10) and Fedora 13

As part of the Karmic changes, Ubuntu (and Fedora 13) has moved the files responsible for launching gettys. They are now located in /etc/init and have had a name change from ttyX to ttyX.conf.

The mingetty command applicable for ttyX in Gutsy and Hardy remain usable in the new ttyX.conf files.

Option 3

Configure a Login Manager to login automatically as a default user. Then configure your desktop (KDE or GNOME) to autostart a program like mythfrontend. To deal with mythfrontend crashes, I would suggest that you run a wrapper around mythfrontend like

while true; do mythfrontend; sleep 5s; done

KDM Auto Login

For the default user, create a link in ~/.kde/Autostart that points either to the script listed above (or some other script that starts the front end) or merely to mythfrontend itself. The system will now log in automatically, and immediately start the frontend.

Frontend Auto Login with Fedora Core 5 and GNOME / GDM

To set GDM to auto-login your mythtv user, edit your GDM configuration:

 vi /etc/gdm/custom.conf

Add the following lines to the [daemon] section:

[daemon]
AutomaticLoginEnable=true
AutomaticLogin=mythtv

Then, set the $HOME/.xsession file for your mythtv user to start mythwelcome.

 vi ~mythtv/.xsession

Important.png Note: more recent versions of Fedora (possibly 9 and later) don't automatically run the .xsession file in $HOME. Following an installation you may well find that gnome-desktop is run as the window manager which may not be what you want on a dedicated MythTV PC. You can specify the window manager of your choice and the programs executed on starting X Windows in your own $HOME/.xsession file. In order to ensure your own $HOME/.xsession is executed you need to click the Sessions menu at the bottom of the GDM automatic login screen and select "User script". This will force the execution of $HOME/.xsession file. (Note that you may have to click a username first in the login window in order to get the menu bar to display at the bottom of the GDM auto-login screen).

An example $HOME/.xsession file , which will start the Metacity window manager, an xterm (which you can start with F12 from mythwelcome) and finally, mythwelcome itself is shown here:

Important.png Note: If mythwelcome dies for some reason, GDM will restart it.

Script.png ~mythtv/.xsession

#!/bin/bash
metacity &
xterm &
mythwelcome

Make sure to make it executeable:

 chmod 755 ~mythtv/.xsession

If you'd like to be able to login as a different user before GDM logs in your mythtv user, replace the AutomaticLogin lines in your GDM configuration with TimedLogin lines.

This example will wait 10 seconds before logging in the mythtv user.

[daemon]
TimedLoginEnable=true
TimedLogin=mythtv
TimedLoginDelay=10

Frontend Auto Login with Kubuntu / KDM

To set KDM to auto-login your mythtv user, edit your KDM configuration:

 sudo vi /etc/kde3/kdm/kdmrc

Go to (almost) the bottom of the file and edit the next lines:

[X-:0-Core]
AutoLoginDelay=0
AutoLoginEnable=true
AutoLoginUser=mythtv

Frontend Auto Login for Fedora and KDE

Fedora Core 6 uses a script to let you choose which login manager to use. If no default is given it uses xdm. You can set the default by creating a file called /etc/sysconfig/desktop and adding DISPLAYMANAGER="KDE" or DISPLAYMANAGER="GNOME". Once this file is there then you can set the auto login from within KDE like so:

  1. Click on the K menu.
  2. In the K menu, click on Control Center.
  3. When the control center screen appers there is a list of options to pick. Select the System option.
  4. The System menu will expand and give a list of sub menus - click on Login Manager.
  5. When the login manager is displayed there are tabs that you can select Appearance/Font/Background/Sessions/Users/Convenience. Click on the Convenience tab.
  6. Go to the Automatic Login box, you will see there is 2 check boxes and a drop down menu. Click Enable Auto-login. Select user from the drop down menu.
  7. Click the Apply button down on the bottom right.
  8. Close window. The automatic login process will take effect when you restart your computer.

Frontend Auto Login for Fedora 9

If Fedora 9 seems to ignore any changes to /etc/inittab try making the changes in /etc/event.d/ttyX. (Not sure what directs using /etc/inittab versus /etc/event.d)

exec /sbin/mingetty --autologin mythtv tty1

Frontend Auto Login for Fedora 9 Method 2

In /etc/gdm/custom.conf in the [daemon] section ensure you have the following lines present (subsitute "myth" for your mythtv user).

[daemon]
TimedLoginEnable=true
TimedLoginDelay=5
AutomaticLoginEnable=true
AutomaticLogin=myth
TimedLogin=myth
RemoteGreeter=/usr/libexec/gdmgreeter

Frontend Auto Login for openSUSE 10.2

Geeko head48.png see the Opensuse_10.2 page