Mopidy Autostart

Have some feedback, questions, suggestions, or just fancy a chat? Pop it in here.
Post Reply
Marekkon5
Posts: 1
Joined: Fri Jun 08, 2018 10:23 pm

Mopidy Autostart

Post by Marekkon5 »

Hello. I installed Mopidy using dietpi-software. I need it to automatically play radio from tunein (or m3u playlist).

I tried:
Editing cron
Custom afterboot dietpi script

Nothing worked.....

Thanks
User avatar
MichaIng
Site Admin
Posts: 2293
Joined: Sat Nov 18, 2017 6:21 pm

Re: Mopidy Autostart

Post by MichaIng »

@Marekkon5
When exactly the player should start? After user login or automatically on/after boot?

Login: Use /etc/profile.d/custom_script.sh, but custom script option with dietpi-autostart should have the same effect. But as said, you need to manually log in first then.
NB: The script is started with the login user permissions. Thus assure that it does not need e.g. root permissions. As I see, the mopidy service itself is started as root user, thus I guess any access needs root permissions as well (?).

Boot: Add /var/lib/dietpi/postboot.d/custom_script.sh, which will be started after the boot process is fully finished, which is most properly what you want.

If it does not work, check logs /var/log/syslog or journalctl if you find some related error. Also of course run the script manually first to assure it does not contain any syntax error and works as expected.
jaba42se2njklr
Posts: 1
Joined: Wed Jan 02, 2019 8:03 pm

Re: Mopidy Autostart

Post by jaba42se2njklr »

I had the same wish (start playing a playlist after boot), but just calling mpc (apt-get install mpc) in /var/lib/dietpi/postboot.d/custom_script.sh does not work as mopidy is not started at this point by the boot scripts or at least not ready to accept mpd/mpc communication.

I created a small bash script I like to share. Put this in /var/lib/dietpi/postboot.d/custom_script.sh (as root, chmod ugo+x). Before, create a playlist (e.g.) "default" or "autostart" in mopidy (is a parameter for bash function AutoplayMpc). In short, the script waits for mpd (=mopidy) readiness and then loads the desired playlist, otherwise it times-out after 120s. It forkes to background to not block booting.

Code: Select all

#!/bin/bash
# Start mopidy via mpc with given playlist, wait for mpd being ready until timeout
AutoplayMpc () {
        theplaylist=$1
        thetimeout=120 #seconds
        theprefix="[AutostartMpc]“
        logger "$theprefix Started"
        loops=1
        while true;
        do
                mpc >/dev/null 2>&1
                if [ $? -eq 0 ]; then
                        logger "$theprefix MPD found, starting playlist $theplaylist"
                        mpc -q clear >/dev/null
                        mpc -q load $theplaylist >/dev/null
                        mpc -q repeat on >/dev/null
                        mpc -q play  >/dev/null
                        break
                else
                        sleep 1s
                        if [ "$loops" -gt "$thetimeout" ]; then logger "$theprefix MPD timeout" && break; else loops=$((loops+1)); fi
                fi
        done
}
AutoplayMpc "default" & # remove & for blocking execution
Post Reply