LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-08-2015, 06:00 AM   #1
archuser
LQ Newbie
 
Registered: Feb 2015
Posts: 11

Rep: Reputation: Disabled
Managing startup and shutdown dependencies


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?

Last edited by unSpawn; 03-08-2015 at 02:20 PM.
 
Old 03-08-2015, 06:22 PM   #2
archuser
LQ Newbie
 
Registered: Feb 2015
Posts: 11

Original Poster
Rep: Reputation: Disabled
Nobody?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Managing Startup Programs in Fedora 19 leslicom Linux - Software 2 10-16-2013 11:10 PM
[SOLVED] shutdown two nodes with dependencies eccos Programming 10 04-13-2010 10:26 AM
Managing startup programs; removing YOU icon from startup General SUSE / openSUSE 2 06-14-2007 08:48 PM
icewm startup probs (dependencies?) joeln Slackware 2 02-21-2004 07:16 PM
Startup/Shutdown MasterC Linux - General 13 05-14-2002 04:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration