Set up cron job to stop/start Logitech Media Server

Longtime DietPi user, still learning my way around the Linux command line.

I recently migrated my Logitech Media Server install from my NAS to my Pi. I managed to get everything up and running (many thanks to DietPi’s ease of use) but am still working out some kinks.

Although the Pi runs 24-7, the NAS (where the music shares are hosted) powers off around midnight and powers back on around 6am. LMS does not appear to like this at all. It seems like the easiest way to avoid the LMS looking for mounts that aren’t there is to stop the service just before the NAS powers down and restart it just after the NAS powers on in the morning.

So, how exactly do I set up a cron job in DIetPi to stop and restart LMS at a specific time? And if someone’s got a suggestion that’s easier than a cron job, I’m definitely open to it.

Simply create 2 crontab entries to start and stop LMS. I will link some nice blog entry where the basic stuf about crontab is explained

“Simply” is relative. I wasn’t even sure how the LMS executable identified itself to the system.

A user at the LMS forums suggested this:

55 23  * * * /etc/init.d/logitechmediaserver stop
05  6  * * * /etc/init.d/logitechmediaserver restart

… but he added that there might be more elegant syntax like systemctl. I’ve seen that command used in DietPi, but I’m not sure if it should be used here or if the code above will be just as good.

On DietPi we use systemd to start/stop services. Therefore it should be

/usr/bin/systemctl stop logitechmediaserver
/usr/bin/systemctl start logitechmediaserver

for testing, you could run it on CLI

Or a single

systemctl restart logitechmediaserver


It should be stopped MichaIng for some hours. Therefore restating might not be correct way :wink:

Ah whoops, I should have read more carefully :slight_smile:.

Thanks for your help, MichaIng and Joulinar. You both make it easier to Linux newbs to get more out of DietPi.

The epilogue to this is that I’ve found that cron jobs have not been necessary for LMS. After those initial hiccups, it’s been running fine with the NAS shutting down overnight and LMS continuing to run on the Pi. With no additional steps on my part, the mount is re-establishing itself in the morning before the alarms go off on our LMS-controlled radios.

So, for anyone in the same boat, storing music files on an external drive doesn’t appear to mess things up if that drive is unmounted for a period — provided, of course, that LMS is not attempting to access that drive for any reason during the downtime.

Good it is working somehow :sunglasses: