Managing startup and shutdown dependencies


Results 1 to 8 of 8

Thread: Managing startup and shutdown dependencies

  1. #1
    Join Date
    Mar 2015
    Posts
    10

    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 it's 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?

  2. #2
    Join Date
    Mar 2015
    Posts
    10
    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

  3. #3
    Join Date
    Mar 2015
    Posts
    10
    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

  4. #4
    Join Date
    Mar 2015
    Posts
    10
    Quick question - is /etc/fstab processed before all of the abovementioned?

  5. #5
    Join Date
    Mar 2015
    Posts
    10
    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?

  6. #6
    Join Date
    Aug 1999
    Location
    Juneau, AK USA
    Posts
    780
    Maybe make /mnt/ramdisk immutable?

    chattr +i /mnt/ramdisk
    or, if appropriate maybe:
    chattr -R +i /mnt/ramdisk
    We'll get thisright yet!

  7. #7
    Join Date
    Mar 2015
    Posts
    10
    Quote Originally Posted by camelrider View Post
    Maybe make /mnt/ramdisk immutable?

    chattr +i /mnt/ramdisk
    or, if appropriate maybe:
    chattr -R +i /mnt/ramdisk
    Thanks for the suggestion, but that generates an error:
    Code:
    chattr +i /mnt/ramdisk
    chattr: Inappropriate ioctl for device while reading flags on /mnt/ramdisk

  8. #8
    Join Date
    Mar 2015
    Posts
    10
    Even modifying the lne in /etc/fstab that creates the ramdisk to the following doesn't make any difference:
    Code:
    tmpfs      /mnt/ramdisk tmpfs     defaults,size=4096M,uid=logitechms,gid=logitechms 0    0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •