View previous topic :: View next topic |
Author |
Message |
notCarl n00b
Joined: 28 Sep 2016 Posts: 27
|
Posted: Sat Nov 05, 2016 5:31 am Post subject: Best way to run X Server on log in? |
|
|
I'm using i3wm and have to $startx when I log in for now. I tried adding xserver to run level with $rc-update add xdm , but it didnt work when I reboot.
How does everyone else start xserver on startup?
Thanks |
|
Back to top |
|
|
Buffoon Veteran
Joined: 17 Jun 2015 Posts: 1369 Location: EU or US
|
Posted: Sat Nov 05, 2016 5:47 am Post subject: |
|
|
I do it from ~/.bash_profile, but there are many ways to skin this cat. |
|
Back to top |
|
|
The Doctor Moderator
Joined: 27 Jul 2010 Posts: 2678
|
Posted: Sat Nov 05, 2016 5:48 am Post subject: |
|
|
Yes! As a matter of fact, I had the exact same setup.
You want to run a program when the user logs in on the local machine. This provides a possible solution. When the user logs on their environment is loaded. This means the problem can be solved using the .bashrc file (or equivalent depending on your shell of choice).
This script needs to do 2 things. 1) check to see if the log on is local or ssh. 2) check to see if X is already running or the nox kernel command line was passed 3) start X and disown the process. This has the advantage of also not running X as root which is a security risk.
To do this, add the following lines to your ~/.bashrc file Code: | if [ $(echo $DISPLAY | wc -w) -eq 0 -a $(cat /proc/cmdline | grep nox | wc -l) -eq 0 ]; then
if [ -n $SSH_CONNECTION ]; then
exec startx > /dev/null 2>&1 &
disown
fi
fi | A bit dirty in places but it does the job. You can redirect to a log file instead of /dev/null if you prefer. _________________ First things first, but not necessarily in that order.
Apologies if I take a while to respond. I'm currently working on the dematerialization circuit for my blue box. |
|
Back to top |
|
|
khayyam Watchman
Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Sat Nov 05, 2016 9:58 am Post subject: |
|
|
The Doctor wrote: | Code: | if [ $(echo $DISPLAY | wc -w) -eq 0 -a $(cat /proc/cmdline | grep nox | wc -l) -eq 0 ]; then
if [ -n $SSH_CONNECTION ]; then
exec startx > /dev/null 2>&1 &
disown
fi
fi |
|
doc ... UUoC, and wc ... all you need do is check if $DISPLAY is empty, I'm not sure the second test is needed (as $DISPLAY would qualify whether 'nox' is in use), anyhow, use 'test' for both conditions:
Code: | if [[ -z ${DISPLAY} ]] && (grep nox /proc/cmdline >/dev/null 2>&1) ; then |
Also, 'disown' is superfluious, with 'exec' you are replacing the shell with 'command' (and so shell goes bye-bye).
Also, you, or the OP, might use an interactive question/answer:
Code: | ask() {
echo -n "$@" '[y/n] ' ; read ans
case "$ans" in
y*|Y*) return 0 ;;
*) return 1 ;;
esac
}
if [[ -z $DISPLAY ]] ; then
ask "startx?" && exec startx
fi |
best ... khay |
|
Back to top |
|
|
Tony0945 Watchman
Joined: 25 Jul 2006 Posts: 5127 Location: Illinois, USA
|
Posted: Sat Nov 05, 2016 2:49 pm Post subject: Re: Best way to run X Server on log in? |
|
|
notCarl wrote: | I'm using i3wm and have to $startx when I log in for now. I tried adding xserver to run level with $rc-update add xdm , but it didnt work when I reboot. | Did you make your session file in /etc/X11/Sessions executable? I got bitten by this adding lumina by hand (the ebuild doesn't do it). The symptom is, you log in, xdm seems to be ldoing something, then returns to the login screen. What's in your $HOME/.xsession?
You can make a nice little menu by creating /etc/X11/xdm/Xresources.custom Code: | xlogin*login.translations: #override \
Ctrl<Key>R: abort-display()\n\
<Key>F1: set-session-argument(failsafe) finish-field()\n\
<Key>F2: set-session-argument(lumina) finish-field()\n\
<Key>F3: set-session-argument(fluxbox) finish-field()\n\
<Key>Delete: delete-character()\n\
<Key>Left: move-backward-character()\n\
<Key>Right: move-forward-character()\n\
<Key>Home: move-to-begining()\n\
<Key>End: move-to-end()\n\
Ctrl<Key>KP_Enter: set-session-argument(failsafe) finish-field()\n\
<Key>KP_Enter: set-session-argument() finish-field()\n\
Ctrl<Key>Return: set-session-argument(failsafe) finish-field()\n\
<Key>Return: set-session-argument(menu) finish-field() | The only change made to /etc/xdm/Xresources is adding the argument "menu" to <Key>Return.
This will cause xdm to launch /etc/X11/Sessions/menu instead of /etc/X11/Sessions/XSession or what a myriad of environment variables have set up.
Here is my /etc/X11/Sessions/menu file (don't forget to make it executable). Code: | #!/bin/bash
xmessage "" -buttons " MATE , Lumina , Fluxbox" -center -font '-*-bitstream vera sans-*-r-*-*-18-140-100-c-100-*-*' -bg black -fg white
SELECTION=$?
logger "chose $SELECTION"
case $SELECTION in
101) exec /etc/X11/Sessions/MATE ;;
102) exec /etc/X11/Sessions/lumina ;;
103) exec /etc/X11/Sessions/fluxbox ;;
esac
| Edit this for whatever session managers you have. The logger line is unnecessary, I just like t have the selection logged. I only wish I knew how to change the font to be much bigger. |
|
Back to top |
|
|
Buffoon Veteran
Joined: 17 Jun 2015 Posts: 1369 Location: EU or US
|
Posted: Sat Nov 05, 2016 6:26 pm Post subject: |
|
|
FWIW, here's mine
Code: | # /etc/skel/.bash_profile
# This file is sourced by bash for login shells. The following line
# runs your .bashrc and is recommended by the bash info pages.
[[ -f ~/.bashrc ]] && . ~/.bashrc
PATH=$PATH:~/bin
if [ -z "$DISPLAY" ] && [ $(tty) == /dev/tty1 ]; then
sleep 1
startx
sleep 3
exit
fi
|
|
|
Back to top |
|
|
|