Skip to main content
Topic: SOLVED (sort of) Autologin without automatic relogin? (Read 2688 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

SOLVED (sort of) Autologin without automatic relogin?

Is there something like a oneshot service, as with systemd? When I configure
agetty.tty1 with "--autologin <username>" I immediately get logged back in when
I log out. Is it possible to restart agetty with different options (w/o killing
my login shell)? I can always log in as root on another tty and do
Code: [Select]
# mount --bind /etc/conf.d/agetty.tty2 /etc/conf.d/agetty.tty1
# rc-service agetty.tty1 restart
# umount /etc/conf.d/agetty.tty1
whereby agetty.tty2 has the default options, but this is kind of ugly (basically
cracking my own system. I can also run the first 2 lines on the console with
sudo). There has to be a better way. Adding this to /etc/conf.d/agetty.tty1
Code: [Select]
# extra options to pass to agetty for this port
if [[ $RC_CMD = 'restart' ]]; then # single brackets work but give an error msg
agetty_options=""
else
agetty_options="--autologin <username>"
fi
works, sort of: I can log out with "sudo rc-service agetty.tty1 restart". But of
course this is no proper logout; I am still throwing myself out of my own system.
To be sure I won't need this every day but a proper procedure would be welcome.

Re: Autologin without automatic relogin?

Reply #1
I had a similar issue, the solution I found was using tests in .bashrc. There are a few .bashrc variants suggested online I saw. My version was for an X session login, you see the X session makes a file in /tmp when it is running, but I think it removes it when it exits hence the relogin due to the agetty service being restarted. I added a test for the runlevel so it wouldn't restart X at shutdown. Other use cases might need further adjustment.
Tutorials and HOWTOs
agetty autologin with Xfce and OpenRC
Perhaps you just don't want the agetty service to be auto restarted at all though, but for a typical desktop login it might be useful if it was, if any unexpected errors at boot ever occurred.
I see your point though, the shell still re - logs in at shut down, even if X is now not restarted, and if you weren't powering off that would be unhelpful.

Re: Autologin without automatic relogin?

Reply #2
The following seems to be the simplest solution (but it blocks login on other
virtual consoles until I log out of tty1):
Code: [Select]
#!/usr/bin/openrc-run
# save as /etc/init.d/agetty1
description="oneshot agetty on tty1"
supervisor="start-stop-daemon"
port="tty1"
term_type="${term_type:-linux}"
agetty_options="--autologin <username>"
command=/sbin/agetty
command_args="${agetty_options} ${port} ${baud} ${term_type}"
#no pidfile required
export EINFO_QUIET="${quiet:-yes}"

depend() {
after local
before agetty.tty1
keyword -prefix
}

start_pre() {
if [ -z "$port" ]; then
return 1
fi
}

Make it executable and add it to the default runlevel.


Improvement (but may have to be manually restored after upgrades):
If I replace the link "/etc/init.d/agetty.tty1" with a copy of the standard
/etc/init.d/agetty file and then modify /etc/init.d/agetty like this:
Code: [Select]
#!/usr/bin/openrc-run

description="start agetty on a terminal line"
supervisor=supervise-daemon
port="${RC_SVCNAME#*.}"
term_type="${term_type:-linux}"
command=/sbin/agetty
command_args_foreground="${agetty_options} ${port} ${baud} ${term_type}"
pidfile="/run/${RC_SVCNAME}.pid"
export EINFO_QUIET="${quiet:-yes}"

depend() {
after local
before agetty1 # adding this line to all gettys EXCEPT agetty.tty1
keyword -prefix
}

start_pre() {
if [ -z "$port" ]; then
eerror "${RC_SVCNAME} cannot be started directly. You must create"
eerror "symbolic links to it for the ports you want to start"
eerror "agetty on and add those to the appropriate runlevels."
return 1
fi
}
Edit:
It seems to work, but if I reboot without actually having logged out of tty1 (so
the agetty1 service is still running), it logs me back in, and I get a string of
errors:
Code: [Select]
* WARNING: you are stopping a boot service
* WARNING: you are stopping a sysinit service
* WARNING: you are stopping a sysinit service
* WARNING: you are stopping a sysinit service
* WARNING: you are stopping a sysinit service
 ...
It seems to be harmless, but it's annoying. So how do I prevent a service from
restarting at reboot/shutdown? I found nothing on how to bind services to specific
runlevels (and I don't mean "rc-update add <service> <runlevel>", I need something
to INHIBIT a service at a specific runlevel). There seems to be no "conflicts"
keyword.

 

Re: Autologin without automatic relogin?

Reply #3
Replying to myself this time, since editing does not update the post date.
I added
Code: [Select]
start_pre() {
mark_service_started agetty1
}
to agetty1. This gets it out of /run/openrc/starting - but I still get the
errors at shutdown. This needs to be fixed - this is exactly the reason why
people are fleeing to systemd. I don't intend to flee (systemd simply doesn't
work for me) but I am annoyed. I expected openrc to be more mature.

There is an open issue (https://github.com/OpenRC/openrc/issues/159), probably
related.

Re: Autologin without automatic relogin?

Reply #4
Replying to myself this time, since editing does not update the post date.
I added
Code: [Select]
start_pre() {
mark_service_started agetty1
}
to agetty1. This gets it out of /run/openrc/starting - but I still get the
errors at shutdown. This needs to be fixed - this is exactly the reason why
people are fleeing to systemd. I don't intend to flee (systemd simply doesn't
work for me) but I am annoyed. I expected openrc to be more mature.

There is an open issue (https://github.com/OpenRC/openrc/issues/159), probably
related.

Perhaps poking the devs @github would help, or nagging a little in #openrc@freenode. I don't use autologin anywhere and I haven't met the issue.

Re: Autologin without automatic relogin?

Reply #5
supervisor=supervise-daemon

I think this probably relates to the fact that the supervisor is ensuring the service is restarted, so when you log out you are logged in again. But if you follow the guides for using agetty's in OpenRc you use the provided service file that does exactly this. So I would agree this is an OpenRC issue at present. Supervisor's restart stopped processes. There is various documentation (not all  up to date) around on the init scripts, the format changes sometimes as versions progress, so you have to be prepared to try stuff out.
Getting rid of the above line or changing it to something else could provide a fix if you have the time to reboot numerous times trying different things to hit on a working solution, while being prepared for the possibility of accidentally hanging the boot process.

Re: Autologin without automatic relogin?

Reply #6
Partial success:
If I use the following service INSTEAD of agetty.tty1 (I suppose it could be
called agetty.tty1, replacing the link in /etc/init.d, but then there could be
problems with openrc updates):
Code: [Select]
#!/usr/bin/openrc-run
# save as /etc/init.d/agetty1
description="oneshot autologin agetty on tty1"

depend() {
after local
keyword -prefix
}

# This could probably be placed in a configfile /etc/conf.d/agetty1 (not tested):
if [[ $RC_CMD = 'restart' ]]; then
agetty_options=""
else
agetty_options="--autologin <username>"
fi

start() {
mark_service_stopped agetty1 # this seems to be needed
if [[ $RC_RUNLEVEL != reboot ]]; then
/sbin/agetty $agetty_options tty1 38400 linux
fi
rc-service agetty1 restart
}
I still get logged back in on reboot, but there are no more error messages. And
I can actually log out of tty1 - I get a proper login prompt. This can be combined
with a suitable startx command in .bash_profile to get directly to the graphics.

But after logging out and back in there are 2 instances of agetty1 running:
Code: [Select]
# Before logging out and back in:
ps ax|grep agetty[1]
 1908 ?        S      0:00 /usr/bin/openrc-run /etc/init.d/agetty1 --lockfd 17 start
 1909 ?        S      0:00 /bin/sh /usr/lib/openrc/sh/openrc-run.sh /etc/init.d/agetty1 start
# After logging out and back in:
$ ps ax|grep agetty[1]
 1908 ?        S      0:00 /usr/bin/openrc-run /etc/init.d/agetty1 --lockfd 17 start
 1909 ?        S      0:00 /bin/sh /usr/lib/openrc/sh/openrc-run.sh /etc/init.d/agetty1 start
 2197 ?        S      0:00 /usr/bin/openrc-run /etc/init.d/agetty1 restart
 2199 ?        S      0:00 /bin/sh /usr/lib/openrc/sh/openrc-run.sh /etc/init.d/agetty1 start
If anybody wants to try this, don't forget to delete agetty.tty1 from default.

Re: Autologin without automatic relogin?

Reply #7
The test is actually redundant; if I leave it out, the script behaves exactly as
before:
Code: [Select]
#!/usr/bin/openrc-run
# save as /etc/init.d/agetty1
description="oneshot autologin agetty on tty1"

depend() {
after local
keyword -prefix
}

if [[ $RC_CMD = 'restart' ]]; then
agetty_options=""
else
agetty_options="--autologin <username>"
fi

start() {
mark_service_stopped agetty1
/sbin/agetty $agetty_options tty1 38400 linux
rc-service agetty1 restart
}
It seems that the shutdown runlevel only kicks in after this script exits.

Re: Autologin without automatic relogin?

Reply #8
Here is my current state, which seems to work. I still get re-logged in at reboot,
but it does not seem to affect the system:
Code: [Select]
#!/usr/bin/openrc-run
# save as /etc/init.d/agetty1 and link to /etc/init.d/agetty.tty1:
# ln -sf /etc/init.d/agetty1 /etc/init.d/agetty.tty1
# To protect against overwriting during openrc updates, put the following into
# /etc/pacman.conf:
# NoUpgrade = etc/init.d/agetty.tty1
description="oneshot autologin agetty"
port="tty1"
term_type="${term_type:-linux}"
baud="${baud:-38400}"

depend() {
after local
after agetty.tty2
after agetty.tty3
after agetty.tty4
after agetty.tty5
after agetty.tty6
keyword -prefix
}

start_pre() {
if [[ $RC_CMD = 'restart' ]]; then
agetty1_options=""
else
agetty1_options="--autologin <username>"
fi
}

start() {
(mark_service_stopped "${RC_SVCNAME}"
/sbin/agetty ${agetty_options} ${agetty1_options} ${port} ${baud} ${term_type}
rc-service "${RC_SVCNAME}" restart) &
}