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?

2
  • You have already asked the same question Issues with script run from /etc/rc.local
    – Ingo
    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.
    – wedwo
    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

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.