Search code examples
systemdubuntu-18.04

How to convert init script into systemd?


The below init code works on ubuntu 14 however latest Ubuntu does not support init and need to convert this script to work in systemd.

I figured starting the service part however unable to figure out on how to restrict it to only tty2,3; how can I fix this?

(init-code)

 # tty1 - getty
    #
    # This service maintains a getty on tty1 from the point the system is
    # started until it is shut down again.

    start on stopped rc RUNLEVEL=[23] and (
                not-container or
                container CONTAINER=lxc or
                container CONTAINER=lxc-libvirt)

    stop on runlevel [!23]

    respawn
    exec /sbin/getty -n -l /etc/init/banner.sh -8 <port> tty1

[Unit]
Description=This service maintains a getty on tty1 from the point the system is started until it is shut down again.
After=network.target

[Service]
Type=simple
ExecStart=/sbin/getty -n -l /etc/init/bapp_banner.sh -8 <Port> tty1
StandardOutput=syslog
StandardError=syslog

[Install]
WantedBy=multi-user.target

Solution

  • There are no runlevels in systemd, and tty1 are available and managed automagically until the system HAS to HANGUP on them.