The following seems to be the simplest solution (but it blocks login on other
virtual consoles until I log out of tty1):
#!/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:
#!/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:
* 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.