Centos – Replacing TTY with a script in CentOS 6

centosstartupupstart

How would I go about replacing a TTY with a custom script in CentOS 6. CentOS 6 uses upstart instead of the standard SysV init scripts, so I'm having difficulty figuring out how it all works.

Typically (in SysV init scripts), I would edit /etc/inittab and replace one of the mingetty lines with my script, like this:

1:2345:respawn:/root/myscript tty1

However, with Upstart, this file doesn't the relevant lines, so I'm unsure of how to accomplish this.

Best Answer

I've figured it out.

First I modified /etc/init/start-ttys.conf to have this for the script section:

script
    . /etc/sysconfig/init
    for tty in $(echo $ACTIVE_CONSOLES) ; do
          [ "$RUNLEVEL" = "5" -a "$tty" = "$X_TTY" ] && continue
            if [ "$tty" == "/dev/tty1" ]; then
                    initctl start myjob TTY=$tty
                    continue
            fi
            initctl start tty TTY=$tty
    done
end script

I then created /etc/init/myjob.conf:

stop on runlevel [012456]

respawn
exec /usr/bin/openvt -c 1 -f -e /root/myscript

This ultimately starts /root/myscript on tty1, instead of mingetty. I'm unsure if this the is simplest way of doing it, but it works quite nicely.