0

On a headless RaspberryPi, I would like to automatically start radio on boot, without any human action. I have written this file as /etc/systemd/system/radio.service :

[Unit]
Description=Radio
Wants=network-online.target
After=network.target network-online.target

[Service]
Type=oneshot
ExecStart=/usr/bin/mplayer http://audio.scdn.arkena.com/11016/fip-midfi128.mp3 &
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Unfortunately it doesn't work: after boot, doing systemctl status radio shows :

Loaded: loaded (/etc/systemd/system/radio.service; disabled)
Active: inactive (dead)

I think the Wants and After are necessary because an "up" network is required, as described here.

Should I change Type or RemainAfterExit? Or remove the & at the end of ExecStart? Something else?


Basj
  • 2,519
  • Did you enable the service? systemctl enable radio. Does it start with systemctl start radio? – Thomas Feb 07 '16 at 15:22
  • @Thomas It works when I manually systemctl start radio. But when I reboot, it doesn't start automatically. Instead the status shows Loaded: loaded (/etc/systemd/system/radio.service; disabled) Active: inactive (dead). – Basj Feb 07 '16 at 15:26
  • Ohhhhh that's true, that's the answer! I forgot this step. I'll accept it if you copy paste as an answer! By the way, Should I change Type or RemainAfterExit? Or remove the & at the end of ExecStart for "best practice"? – Basj Feb 07 '16 at 15:28
  • I think you do not need the & at the end of the binary. And I also would leave RemainAfterExit=no which is the default. I'd rather would change to Type=Simple. – Thomas Feb 07 '16 at 15:38

1 Answers1

1

Alright, being able to start the service manually sounds good. You also have to enable the service with systemctl enable radio?
From the systemctl status radio it looks like the service is not enabled and thus doesn't start.

Thomas
  • 6,362