Mopidy Autostart

Have some feedback, questions, suggestions, or just fancy a chat? Pop it in here.
Post Reply
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.....

User avatar
Site Admin
Posts: 3024
Joined: Sat Nov 18, 2017 6:21 pm

Re: Mopidy Autostart

Post by MichaIng »

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

Login: Use /etc/profile.d/, 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/, 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.
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/ 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/ (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

# Start mopidy via mpc with given playlist, wait for mpd being ready until timeout
AutoplayMpc () {
        thetimeout=120 #seconds
        logger "$theprefix Started"
        while true;
                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
                        sleep 1s
                        if [ "$loops" -gt "$thetimeout" ]; then logger "$theprefix MPD timeout" && break; else loops=$((loops+1)); fi
AutoplayMpc "default" & # remove & for blocking execution
Post Reply