Search code examples
linuxstartupsystemdrhel7

How to run last and print my script output during boot with systemd?


I’m trying to configure my host during deployment process and to give an output to the screen of what my configuration script is doing.

In RHEL6 it was easy i was echoing what I want to screen or used dialog to display the output, and only when my script was done i got the login prompt.

  • ( I used rc3.d or rc5.d folder with script name S99.myscript.sh)

In RHEL7 i can’t mimic this process. rc.local does not display my output during booting and also its not guaranteed it will run last.

I guess I need to create a systemd service file that will run my script.

But how do I output the result to the screen while booting?

And how do I make sure I will not get the log-in prompt before my script ends?


Solution

  • below service example works like a charm :)

    [Unit]
    Description=ldt_bootscript1.service
    After=network.target
    Before=getty@tty1.service
    
    [Service]
    Type=oneshot
    ExecStart=/bin/bash -c "/bin/bash /tmp/ldt_scripts/postinstall/rc.firstboot.qas | /usr/bin/dialog --clear --backtitle \"Linux Deployment\"  --title \"tests\" --progressbox 20 70 > /dev/console 2>&1"
    ExecStartPre=/usr/bin/echo -e \033%G
    ExecReload=/bin/kill -HUP $MAINPID
    RemainAfterExit=no
    WorkingDirectory=/
    Environment=TERM=xterm
    
    [Install]
    WantedBy=multi-user.target