1

Before I describe the problem, I just want to mention that I was able to get this working on a Pi 3 under Raspbian Buster. For some reason it's not firing on a Pi 4 under the same OS.

I have a basic bash script with an infinite loop that I want to run at boot. In order to ensure the output of all commands within the script are directed to the TV connected to HDMI, I want to launch the script using openvt. The service appears to start without error but the script just never runs.

The script (we'll call it /home/pi/test.sh) looks like this:

#!/bin/bash
while true
do
 echo "Still alive"
 echo "Still alive" >> /tmp/output
 sleep 5
done

I created a service: /etc/systemd/system/test.service that looks as follows:

[Unit]
Description=Test Script
After=network.target
[Service]
WorkingDirectory=/home/pi
ExecStart=/bin/bash -c '/bin/openvt -c 1 -f -- /home/pi/test.sh'
[Install]
WantedBy=multi-user.target

After enabling the service and manually starting it (or after a reboot), the /tmp/output file is never created and nothing outputs to the screen on HDMI.

systemctl status test.service outputs this:

くろまる test.service - Test Script
 Loaded: loaded (/etc/systemd/system/test.service; enabled; vendor preset: enabled)
 Active: inactive (dead) since Fri 2019年12月27日 08:27:31 GMT; 2min 17s ago
 Process: 527 ExecStart=/bin/bash -c /bin/openvt -c 1 -f -- /home/pi/test.sh (code=exited, status=0/SUCCESS)
 Main PID: 527 (code=exited, status=0/SUCCESS)
Dec 27 08:27:31 raspberrypi systemd[1]: Started Test Script.
Dec 27 08:27:31 raspberrypi systemd[1]: test.service: Succeeded.

The output from journalctl --unit=test.service is as follows:

-- Logs begin at Fri 2019年12月27日 08:27:16 GMT, end at Fri 2019年12月27日 08:29:49 GMT. --
Dec 27 08:27:31 raspberrypi systemd[1]: Started Test Script.
Dec 27 08:27:31 raspberrypi systemd[1]: test.service: Succeeded.

If I manually run the command:

sudo /bin/bash -c '/bin/openvt -c 1 -f -- /home/pi/test.sh'

it runs fine and behaves as expected. Any reason it won't run as a service?

Ingo
43k20 gold badges87 silver badges207 bronze badges
asked Dec 27, 2019 at 8:28
2
  • You have already asked the same question Issues with script run from /etc/rc.local Commented Dec 27, 2019 at 18:54
  • This question better identifies the issue which relates to openvt - I wasn't aware of that when I posted the previous question. If I were to have one or the other, the other can be deleted and this one left since it's a more accurate heading. Commented Dec 29, 2019 at 10:23

1 Answer 1

2

OK, the service works when running openvt with -s -w parameters:

ExecStart=/bin/openvt -s -w /home/pi/test.sh
answered Jan 6, 2020 at 19:46

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.