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: Started Test Script. Dec 27 08:27:31 raspberrypi systemd: 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: Started Test Script. Dec 27 08:27:31 raspberrypi systemd: 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?