[Solved] Run script when screen turns on

Post Reply
alpe
Posts: 67
Joined: Sat Apr 12, 2014 1:21 pm
languages_spoken: portuguese, english
ODROIDs: C1, N2 4GB
Location: Rio de Janeiro, Brazil
Has thanked: 12 times
Been thanked: 5 times
Contact:

[Solved] Run script when screen turns on

Unread post by alpe » Thu Oct 17, 2019 11:40 pm

I use Ubuntu Minimal.

What I wanted:
A way to start Kodi automatically everytime my TV is turned on.
This way I can exit kodi when I stop using it (save some cpu cycles) and it'll automatically start again after I turn on my tv again.

My solution:
I already run kodi via systemd.
I created another systemd service with:

Code: Select all

nano /etc/systemd/system/kodi-autostart.service

Code: Select all

[Unit]
Description=Kodi Autostart
After=network.target

[Service]
Type=simple
ExecStart=/bin/sh -c "/usr/bin/tail -fn0 /var/log/syslog | /usr/bin/awk '/hdmitx: system: plugin/ { system(\"/bin/systemctl start kodi\") }'"
Restart=on-failure

PrivateDevices=yes
NoNewPrivileges=true
ProtectSystem=strict
StandardOutput=null


[Install]
WantedBy=multi-user.target
I enabled this service (systemctl enable kodi-autostart) and started it (systemctl start kodi-autostart).
Now everytime I turn on my TV "systemctl start kodi" is run. If it's already running, this does nothing. If it isn't, it starts.
The only "problem" is that if I exit kodi and want to open it again (without access to console) I have to restart my TV. But this is no problem on my setup.
Last edited by alpe on Sat Oct 19, 2019 6:43 am, edited 3 times in total.
These users thanked the author alpe for the post (total 2):
odroid (Fri Oct 18, 2019 8:37 am) • rooted (Fri Oct 18, 2019 5:46 pm)

User avatar
odroid
Site Admin
Posts: 32508
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Has thanked: 181 times
Been thanked: 349 times
Contact:

Re: [Solved] Run script when screen turns on

Unread post by odroid » Fri Oct 18, 2019 8:38 am

Thank you for sharing a nice and useful solution.

Post Reply

Return to “Ubuntu”

Who is online

Users browsing this forum: No registered users and 0 guests