Tuesday, 19 November 2013

Raspberry Pi Setup As MPD Sever - Part 2

This is to continue last post about Raspberry Pi setup as MPD server. With Arch Linux setup and ready to play music using MPD, the next thing to do is to make it read-only so as to minimize the wrap n' wear to the SD card.

1. (This step is copied from Voyage MPD with some modification. Credit goes to the creator of this script in Voyage MPD.)

1a. Create the following new service:

vi /etc/systemd/system/voyage.service
Description=Voyage Sync


ExecStart=/usr/local/sbin/voyage-sync start
ExecStart=/usr/local/sbin/voyage-util start

ExecStop=/usr/local/sbin/voyage-util stop
ExecStop=/usr/local/sbin/voyage-sync stop



1b. Execute command to enable the new service, so that it starts automatically in every boot up.

systemctl enable voyage.service

1c. Copy from Voyage MPD, the files in "/usr/local/sbin" to the same folder in Arch Linux.
1d. chmod -Rf 755 /usr/local/sbin

2. Auto mounting of USB media and update MPD music library on-the-fly
(source from a tool called USBFlash  with some modification: http://code.google.com/p/yad/wiki/USBFlash)
vi /etc/udev/rules.d/11-auto-mount.rules
KERNEL!="sd[a-z]*", GOTO="auto_mount_end"
KERNEL=="sd[a-z]", GOTO="auto_mount_end"
ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="auto_mount_end"

# Set environment
ACTION=="add", IMPORT{program}="/sbin/blkid -o udev -p -s TYPE -s LABEL %N"

# Global mount options
ACTION=="add", ENV{mount_options}="relatime,users,umask=0,ro"

# Filesystem specific options
ACTION=="add", ENV{ID_FS_TYPE}=="ntfs", ENV{mount_options}="%E{mount_options},utf8"

# Get mount point
ACTION=="add", ENV{ID_FS_LABEL}=="?*", PROGRAM="/usr/bin/basename '%E{ID_FS_LABEL}'", ENV{dir_name}="%c"
ACTION=="add", ENV{dir_name}!="?*", ENV{dir_name}="USB-%k"

# Main action
ACTION=="add", ENV{dir_name}=="?*", RUN+="/bin/mkdir '/var/lib/mpd/music/%E{dir_name}'", RUN+="/bin/mount -o %E{mount_options} /dev/%k '/var/lib/mpd/music/%E{dir_name}'", RUN+="find /var/lib/mpd/music -type d -empty -delete", RUN+="/usr/bin/mpc update"
ACTION=="remove", ENV{dir_name}=="?*", RUN+="/bin/umount -l '/var/lib/mpd/music/%E{dir_name}'", RUN+="find /var/lib/mpd/music -type d -empty -delete", RUN+="/usr/bin/mpc update"


# label must be cleared


(Afterword: I still prefer loading PiCorePlayer in my Pi. The next thing to do is to make a case for Pi.)

No comments:

Post a Comment