You are not logged in.

#51 2013-11-08 05:06:01

Alister.Hood
Member
From: Auckland, New Zealand
Registered: 2011-12-09
Posts: 18

Re: Automatic X login without a DM

I'm afraid that went completely over my head. 
But I think the problem was that I didn't realise I still had to follow the instructions at https://wiki.archlinux.org/index.php/Systemd/User as well.  After doing that everything seems to work - except when I start rxvt from my window manager it doesn't use my prompt from /etc/profile. And I'm now finding the extra entries in lxtask annoying - this doesn't really seem worth it, just to get rid of an autologin to tty1 wink

Offline

#52 2013-11-09 00:16:50

Alister.Hood
Member
From: Auckland, New Zealand
Registered: 2011-12-09
Posts: 18

Re: Automatic X login without a DM

Oh dear sad
I also need to put a sleep in .xinitrc before executing anything which needs dbus, otherwise it isn't able to connect.  I thought the fix for this might be to tell systemd to start xlogin after dbus.service, but that doesn't work.

Offline

#53 2013-11-09 00:52:12

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: Automatic X login without a DM

There is a reason why this is not yet a supported feature... it is not ready for prime time.

Offline

#54 2013-11-10 20:18:44

jouke
Member
Registered: 2009-10-14
Posts: 72

Re: Automatic X login without a DM

You don't need anything from https://wiki.archlinux.org/index.php/Systemd/User, you don't need a sleep in your .xinitrc and it works very reliable.

Here are the installation steps, including for a systemd managed user dbus session instance.

1.
Install xlogin-git from the AUR.

2.
Create the following two files.

/etc/systemd/user/dbus.socket containing:

[Unit]
Description=D-Bus Message Bus Socket
Before=sockets.target

[Socket]
ListenStream=/run/user/%U/dbus/user_bus_socket

[Install]
WantedBy=default.target

/etc/systemd/user/dbus.service containing:

[Unit]
Description=D-Bus Message Bus
Requires=dbus.socket

[Service]
ExecStart=/usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation
ExecReload=/usr/bin/dbus-send --print-reply --session --type=method_call --dest=org.freedesktop.DBus / org.freedesktop.DBus.ReloadConfig

3.
Run (as root) systemctl --global enable dbus.socket.

4.
Set up your .xinitrc and make sure it has the following near the top.

if [ -d /etc/X11/xinit/xinitrc.d ]; then
    for f in /etc/X11/xinit/xinitrc.d/*; do
        [ -x "$f" ] && . "$f"
    done
    unset f
fi

Running your .xinitrc should not return, so either have wait as the last command in your .xinitrc, or add exec to the last command that will be called and which should not return (your window manager, for instance).

5.
Include the following in your .bashrc.

for sd_cmd in systemctl systemd-analyze systemd-run; do
    alias $sd_cmd='DBUS_SESSION_BUS_ADDRESS="unix:path=$XDG_RUNTIME_DIR/dbus/user_bus_socket" '$sd_cmd
done

6.
Run (as root) systemctl enable xlogin@<username> for automatic login at boot, or systemctl start xlogin@<username> for launching a graphical user session (on tty7).


The user session lives entirely inside a systemd scope and everything in the user session should work just fine. The above may look hard, but is not.

P.S.
The xorg-xinit package is not required for this method.

Offline

#55 2013-11-10 21:21:14

lahwaacz
Wiki Admin
From: Czech Republic
Registered: 2012-05-29
Posts: 748

Re: Automatic X login without a DM

@jouke: From xorg-launch-helper:

...a daemon that can be used to make applications wait with starting until XOrg is ready for X11 connections.

It seems that your 'x-daemon' workaround does not consider this case, would you mind to elaborate?

Offline

#56 2013-11-11 08:15:54

jouke
Member
Registered: 2009-10-14
Posts: 72

Re: Automatic X login without a DM

It does. The x-daemon program does the same as xorg-launch-helper but in under 10 lines of Bash. The xlogin@ service orders itself after the x@ service, which finishes as soon as Xorg is ready for X11 connections.

Offline

#57 2013-11-11 15:40:08

lahwaacz
Wiki Admin
From: Czech Republic
Registered: 2012-05-29
Posts: 748

Re: Automatic X login without a DM

Thanks, it seems I finally understood the trap. I should have taken one more cup of coffee yesterday...

I'll try to set it up then, and update the wiki (if you're ok with that).

Offline

#58 2013-11-11 20:04:02

jouke
Member
Registered: 2009-10-14
Posts: 72

Re: Automatic X login without a DM

Updating the wiki would be cool. I think this method makes a lot of sense and is a lot cleaner than the alternatives.

Offline

#59 2013-11-11 21:06:21

Alister.Hood
Member
From: Auckland, New Zealand
Registered: 2011-12-09
Posts: 18

Re: Automatic X login without a DM

> You don't need anything from https://wiki.archlinux.org/index.php/Systemd/User, you don't need a sleep in your .xinitrc and it works very reliable.

Not for me it doesn't.  It seems it usually works on a cold boot, but not a warm reboot.  Whether that's because I have an old slow machine, or run as root, or something else - I don't know.

Offline

#60 2013-11-13 18:46:31

lahwaacz
Wiki Admin
From: Czech Republic
Registered: 2012-05-29
Posts: 748

Re: Automatic X login without a DM

@jouke: One more thing - is there a particular reason why not use the systemd user bus for the X session? So far it works absolutely fine for me, I just had to export it from ~/.profile:

export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$UID/dbus/user_bus_socket

I remember reading that systemd should export it automatically like $XDG_RUNTIME_DIR, but that was surely before v206...

Edit: One obvious problem is the $DISPLAY variable, previously I solved it by setting it directly in dbus.service, but this may not be ideal. Also there may be other caveats...

Last edited by lahwaacz (2013-11-13 19:03:15)

Offline

#61 2013-11-13 22:22:28

Alister.Hood
Member
From: Auckland, New Zealand
Registered: 2011-12-09
Posts: 18

Re: Automatic X login without a DM

Alister.Hood wrote:

It seems it usually works on a cold boot, but not a warm reboot.

Sorry, other way around - it usually works on a warm reboot, but not on a cold boot.
This morning it even failed to start X the first time...

Offline

#62 2013-11-14 12:11:07

jouke
Member
Registered: 2009-10-14
Posts: 72

Re: Automatic X login without a DM

Alister.Hood wrote:

> You don't need anything from https://wiki.archlinux.org/index.php/Systemd/User, you don't need a sleep in your .xinitrc and it works very reliable.

Not for me it doesn't.  It seems it usually works on a cold boot, but not a warm reboot.  Whether that's because I have an old slow machine, or run as root, or something else - I don't know.

This means at least one of the following scenarios is the case.

  1. You deviated from my 6-step installation instructions.

  2. My installation instructions are incomplete.

  3. You found a bug.

In the third case, we need to find out what the bug is, exactly.


lahwaacz wrote:

Is there a particular reason why not use the systemd user bus for the X session?

Users and sessions are different things. Using the user bus as session bus breaks a lot of stuff, the $DISPLAY variable being the most obvious example. There is an ongoing discussion on how to deal with this. Lennart Poettering (lead developer of systemd) has suggested a couple of possible solutions, the second of which is implemented by xlogin.

Offline

#63 2013-11-29 18:58:33

lahwaacz
Wiki Admin
From: Czech Republic
Registered: 2012-05-29
Posts: 748

Re: Automatic X login without a DM

Finally I got some time to update the wiki, please check it if I made any mistakes...

Offline

#64 2013-11-29 22:00:46

Alister.Hood
Member
From: Auckland, New Zealand
Registered: 2011-12-09
Posts: 18

Re: Automatic X login without a DM

Alister.Hood wrote:

Sorry, other way around - it usually works on a warm reboot, but not on a cold boot.
This morning it even failed to start X the first time...

OK, it all seems to work now.  I guess the problem with the window manager starting before dbus was caused by some sort of bad upgrade before I tried switching to this method, as it seemed to come right after a couple of system upgrades.  When it came right the problem with X sometimes failing to start at all began, and that seems to have been an interaction with the remnants of a previous method of starting X, which I hadn't cleaned out properly.

Last edited by Alister.Hood (2013-11-29 22:06:09)

Offline

#65 2013-11-30 23:46:10

jouke
Member
Registered: 2009-10-14
Posts: 72

Re: Automatic X login without a DM

@lahwaacz: thank you, I like it! I think this puts Arch at least 4 months ahead of other distros :-).

Offline

#66 2013-12-04 15:27:15

ackalker
Member
Registered: 2012-11-27
Posts: 201

Re: Automatic X login without a DM

I think it is worth mentioning that there is another, much simpler way of starting a user session from a service, and I hope it gets considered for its merit before upstream settles on one choice or the other.

It involves using `runuser -l <user> -c "<command>"`, which allows root (and only root!) to run a command in a full user login session.
To use it requires the presence of a PAM config file, /etc/pam.d/runuser-l, which is currently missing in Arch Linux. (Note: the documentation for util-linux (the owner of /usr/bin/runuser) says that this file must be provided by distributions themselves.)

My suggestion for /etc/pam.d/runuser-l is currently under review for Arch (check FS#37644). On my system it is:

#%PAM-1.0

auth    sufficient pam_rootok.so
session include    system-login

which is taken almost verbatim from the example in util-linux.

Since the session part of /etc/pam.d/system-login takes care of everything to do with setting up the login session, including systemd seat assignment and ACLs, there is nothing left to do. No need for <user> to be a member of any special groups, no polkit rules, no D-Bus setup, no wrapper scripts, nothing. <command> will run exactly as if <user> had logged in manually and executed it from a shell.

An example service file, xbmc@.service, which I use daily to start XBMC (as user 'xbmc', stripped of all the now redundant group memberships and polkit rules) on my media center PC:

[Unit]
Description=XBMC on %I
Conflicts=getty@%i.service
After=systemd-user-sessions.service getty@%i.service plymouth-quit.service

[Service]
ExecStart=/usr/bin/runuser -l xbmc -c "/usr/bin/startx /usr/bin/xbmc --standalone"
ExecStop=/usr/bin/runuser -l xbmc -c "/usr/bin/pkill xbmc.bin"
StandardInput=tty
StandardOutput=tty
TTYPath=/dev/%I
Restart=always

[Install]
WantedBy=graphical.target

(Note: the TTY stuff is there to avoid the hassle of having to determine the current VT from $XDG_VTNR, which would require a wrapper script for anything which involves starting X)

To use it, do:

# systemctl start xbmc@tty2

and verify it is indeed running in its own session by switching VTs back to your 'regular' DE/WM and doing:

$ loginctl list-sessions

Comments and suggestions are welcome.

Last edited by ackalker (2013-12-06 16:33:35)

Offline

#67 2013-12-04 16:03:08

ackalker
Member
Registered: 2012-11-27
Posts: 201

Re: Automatic X login without a DM

I realize that the original problem was about starting X as a specific user, not a fixed user on a specific TTY. This is easy to do by substituting the template variable %I in the appropriate places, but as I don't know of a way to pass multiple values to a systemd service template like: <servicename>@<user>:<tty>.service and then separate them again within the template, the choice currently remains either one or the other.

Last edited by ackalker (2013-12-04 16:06:06)

Offline

#68 2013-12-06 16:33:09

ackalker
Member
Registered: 2012-11-27
Posts: 201

Re: Automatic X login without a DM

Edited the edit: runuser -l does actually run a login shell for the command.

Offline

#69 2014-05-07 02:45:13

Alister.Hood
Member
From: Auckland, New Zealand
Registered: 2011-12-09
Posts: 18

Re: Automatic X login without a DM

Hmmm.  I think my problems earlier with X failing to start were somehow related to nouveau driver issues and this method trying to launch X earlier than other methods, as I don't have that problem with the nvidia drivers.
But I do still have the problem that I can't figure out how to get my preferred prompt when I launch a terminal from my file manager or my WM/panel.  I always get this:

sh-4.3#

Can anybody tell me where you specify your prompt that works with this method of starting X?

Offline

Board footer

Powered by FluxBB