I have a dedicated PC providing storage of my music collection and streaming albums via Logitechmediaserver (LMS). OS is Arch running headless. For performance purposes I'd like LMS to access its SQLite database files from a RAM disk which must be dynamically created on startup of the PC with DB copied across from HDD prior to startup of LMS. On shutting down the PC the only changed files should be copied from the ramdisk back to the HDD. The intent would be to use rsync for the copying.
/etc/fstab is configured to create the ramdisk on startup:
Code:
tmpfs /mnt/ramdisk tmpfs defaults,size=4096M 0 0
and LMS has already been configured to look for its DB files in /mnt/ramdisk.
LMS' unit file is /usr/lib/systemd/system/logitechmediaserver.service. Its contents is as follows:
Code:
[Unit]
Description=Logitech Media Server Daemon
After=network.target
[Service]
User=logitechms
Group=logitechms
PIDFile=/var/run/lms.pid
WorkingDirectory=/opt/logitechmediaserver
ExecStart=/opt/logitechmediaserver/slimserver.pl \
--prefsdir /opt/logitechmediaserver/prefs \
--cachedir /opt/logitechmediaserver/cache \
--logdir /opt/logitechmediaserver/Logs
[Install]
WantedBy=multi-user.target
On the startup leg, the data needs to be copied prior to launch of LMS, on the shutdown leg, LMS needs to be stopped and trigger the rsync diff copy. How would I best go about calling a script on startup and shutdown of the PC to ensure that the contents is synced to and from ramdisk on startup and shutdown?
Ok, here is what I've done so far, perhaps someone can critique it for me:
I created a file /etc/systemd/service/sync-lms-to-ramdisk.service containing the following:
Code:
[Unit]
Description=Copy LMS data data directory to ramdisk
After=network.target
Before=logitechmediaserver.service
[Service]
ExecStart=/usr/bin/sync-lms-to-ramdisk.sh
[Install]
WantedBy=multi-user.target
I then created /usr/bin/sync-lms-to-ramdisk.sh containing the following:
Code:
#! /bin/sh
# /usr/bin/sync-lms-to-ramdisk.sh
#
rsync -av /mnt/md127/zSqueezeCache/ /mnt/ramdisk/
exit 0
I made it executable as follows:
Code:
chmod 755 /usr/bin/sync-lms-to-ramdisk.sh
I then enabled the Unit as follows:
Code:
systemctl enable sync-lms-to-ramdisk.service
If I'm not mistaken that should ensure that the ramdisk is populated before LMS fires up
Well, rebooted the server and the ramdisk is populated, but all is not well - LMS is inaccessible.
# systemctl status logitechmediaserver yields:
Code:
# systemctl status logitechmediaserver
● logitechmediaserver.service - Logitech Media Server Daemon
Loaded: loaded (/usr/lib/systemd/system/logitechmediaserver.service; enabled)
Active: inactive (dead) since Sun 2015-03-08 17:25:46 SAST; 18min ago
Process: 411 ExecStart=/opt/logitechmediaserver/slimserver.pl --prefsdir /opt/logitechmediaserver/prefs --cachedir /opt/logitechmediaserver/cache --logdir /opt/logitechmediaserver/Logs (code=exited, status=0/SUCCESS)
Main PID: 411 (code=exited, status=0/SUCCESS)
cat /usr/lib/systemd/system/logitechmediaserver.service yields:
Code:
[Unit]
Description=Logitech Media Server Daemon
After=network.target
[Service]
User=logitechms
Group=logitechms
PIDFile=/var/run/lms.pid
WorkingDirectory=/opt/logitechmediaserver
ExecStart=/opt/logitechmediaserver/slimserver.pl \
--prefsdir /opt/logitechmediaserver/prefs \
--cachedir /opt/logitechmediaserver/cache \
--logdir /opt/logitechmediaserver/Logs
[Install]
WantedBy=multi-user.target
Quick question - is /etc/fstab processed before all of the abovementioned?
Ok, I've got the problem narrowed down to folder permissions. for some reason on creation of the ramdisk its owner is samba whereas it should be owned by logitechems. I amended /usr/bin/sync-lms-to-ramdisk.sh to change ownership of /mnt/ramdisk to logitechms:
Code:
#! /bin/sh
# /usr/bin/sync-lms-to-ramdisk.sh
#
chown logitechms:logitechms /mnt/ramdisk/
rsync -av /mnt/md127/zSqueezeCache/ /mnt/ramdisk/
exit 0
However, on reboot ownership is again assigned to samba
Any ideas?