0

I want to execute an interactive session on the console via systemctl on boot up.

My .service file looks something like this:

[Unit]
Description=My service.
[email protected] network-online.target
[email protected] network-online.target multi-user.target

[Service]
Type=oneshot
ExecStart=/bin/bash.bash -c '/usr/bin/nano /scripts/my_notes.txt'
Environment="TERM=xterm-256color"
Environment="SHELL=/bin/bash.bash"
StandardInput=tty-force
StandardOuput=tty
StandardError=tty
TTYPath=/dev/ttyLP0
TTYReset=yes

[Install]
WantedBy=multi-user.target

So here's where things get weird (to me). If I run this manually as root with systemctl start my_stuff.service, it opens up nano and everything works fine.

If I reboot the unit and wait, it opens up nano but arrow keys add junk to the file and don't move the cursor!

Why would this be any different then running it via systemctl "manually"?

In all cases I'm accessing the unit via serial console.

What gives? Thank you for your help!

9
  • At system startup, processes are run as root (UID 0). In your terminal, processes are run as $USER (UID id -u). Early in system startup, the TERM environment variable has a different value ($TERM tells what kind of terminal you have, and $TERM leads to a definition of what cursor motion commands may be used). Commented Apr 30, 2024 at 23:28
  • Good call, however in this case I was running these as root manually. I'll update the post. Regarding the $TERM comments - is there an "After=" I should be setting so this works correctly? Commented Apr 30, 2024 at 23:53
  • The comments make no sense. Environment variables are not a global resource that changes over time. If you've set TERM to "xterm-256color" for your process then it will have the value of "xterm-256color" for your process no matter when it's started. Commented May 1, 2024 at 1:12
  • That being said, why is this a type=oneshot service? Why does it require getty@? That's not a valid unit name anyway, for one (you can only depend on specific instances, not on "all possible instances"), but if it were valid it would be the opposite of what you'd want – the task doesn't require getty, rather, it inherently conflicts with what getty is doing. Commented May 1, 2024 at 1:16
  • Just to confirm, the .service file starts with a [Unit] line before the Description line? I'm sure it does, but if not none of the Requires or After lines will be looked at. Commented May 1, 2024 at 2:18

1 Answer 1

0

This is what ended up working for me.

  • My script service file:
    [Unit]
    Description=My service.
    [email protected]
    Requires=network-online.target
    After=network-online.target
    
    [Service]
    Type=oneshot
    ExecStart=/bin/bash.bash -c '/usr/bin/nano /scripts/my_notes.txt'
    Environment="TERM=xterm-256color"
    StandardInput=tty-force
    StandardOuput=inherit
    StandardError=inherit
    TTYPath=/dev/ttyLP0
    
    [Install]
    WantedBy=multi-user.target
    
  • The getty service file:
    [Unit]
    After=my_script.service
    

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.