Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ################################
- # Cron on boot #
- ################################
- echo "-------------" >> /volume1/Plex/plexbootlog.log
- echo $(date): Sleep 30 seconds >> /volume1/Plex/plexbootlog.log
- sleep 30
- echo $(date): Waking up >> /volume1/Plex/plexbootlog.log
- # To not log use >/dev/null 2>&1
- echo $(date): attempting encfs local-sorted >> /volume1/Plex/plexbootlog.log
- #Mounting ENCFS, ENCFS6_CONFIG points to local config, --extpass="cat /passwordfilepath" so we do not have to enter a password to mount on boot
- #Mount encrypted local folder
- ENCFS6_CONFIG='/volume1/Plex/encfs/encfs.xml' /opt/bin/encfs --extpass="cat /volume1/Plex/encfs/encfspass" /volume1/Plex/.local-sorted /volume1/Plex/local-sorted >> /volume1/Plex/plexbootlog.log
- echo $(date): attempting acdcli mount >> /volume1/Plex/plexbootlog.log
- export LIBFUSE_PATH="/lib/libfuse.so.2"
- echo "$(date): LIBFUSE_PATH set ($LIBFUSE_PATH)" >> /volume1/Plex/plexbootlog.log
- #--allow-other lets other linux users see encrypted acd dir, --modules="subdir,subdir=/dir" mounts specific acd directory
- /usr/local/bin/acd_cli mount -nl --allow-other --modules="subdir,subdir=/plex" /volume1/Plex/.acd-sorted/ >> /volume1/Plex/plexbootlog.log
- echo $(date): attempting encfs acd-sorted >> /volume1/Plex/plexbootlog.log
- #Mounting ENCFS, ENCFS6_CONFIG points to local config, --extpass="cat /passwordfilepath" so we do not have to enter a password to mount on boot
- #Mount unencrypted acd folder
- ENCFS6_CONFIG='/volume1/Plex/encfs/encfs.xml' /opt/bin/encfs --extpass="cat /volume1/Plex/encfs/encfspass" /volume1/Plex/.acd-sorted /volume1/Plex/acd-sorted >> /volume1/Plex/plexbootlog.log
- echo $(date): attempting unionfs mount >> /volume1/Plex/plexbootlog.log
- # -o allow_other lets my other linux users follow permissions so plex can see sorted
- # uid = user id (1024=admin), gid = group id (100=users)
- /opt/bin/unionfs -o cow -o allow_other,uid=1024,gid=100 /volume1/Plex/local-sorted=RW:/volume1/Plex/acd-sorted=RO /volume1/Plex/sorted/ >> /volume1/Plex/plexbootlog.log
- # Make file so the cron jobs can run
- touch /tmp/allowcron
- ################################
- # Cron on timers #
- ################################
- #----- Plex - 20m - Sync ACD to sorted
- #Sync ACD to sorted every 20 minutes
- if [ -e /tmp/allowcron ]; then
- flock -n /volume1/Plex/encfs/acdsync.lock -c '/usr/local/bin/acd_cli sync' >/dev/null 2>&1
- else
- echo "$(date): allowcron not present: could not sync ACD to sorted" >> /volume1/Plex/plexbootlog.log
- fi
- #----- Plex - 30m - Check if DB is ok
- #30 minutes check to ensure ACD is mounted/node db not corrupt. Source: http://disq.us/p/1ckpl2e
- if [ -e /tmp/allowcron ]; then
- flock -n /volume1/Plex/encfs/acdcheck.lock -c 'bash /root/acdcheck' >> /volume1/Plex/plexbootlog.log
- else
- echo "$(date): allowcron not present: could not check if DB is ok" >> /volume1/Plex/plexbootlog.log
- fi
- #----- Plex - 1h - Upload
- #Hourly upload, flock ensures we do not run again if already running
- if [ -e /tmp/allowcron ]; then
- flock -n /volume1/Plex/encfs/acdupload.lock -c '/usr/local/bin/acd_cli upload /volume1/Plex/.local-sorted/* /plex/' >/dev/null 2>&1
- else
- echo "$(date): allowcron not present: could not upload" >> /volume1/Plex/plexbootlog.log
- fi
- #----- Plex - 6h - Delete local folders
- #Delete local folders that are empty last modified 14 days ago, runs every 6 hours.
- if [ -e /tmp/allowcron ]; then
- find /volume1/Plex/.local-sorted/ -type d -empty -mtime +14 -exec rm -rf {} \; >/dev/null 2>&1
- else
- echo "$(date): allowcron not present: could not delete local folders" >> /volume1/Plex/plexbootlog.log
- fi
- #----- Plex - 6h - Delete local files
- #Delete local files last modified 14 days ago, runs every 6 hours.
- if [ -e /tmp/allowcron ]; then
- find /volume1/Plex/.local-sorted/ -type f -mtime +14 -exec rm -rf {} \; >/dev/null 2>&1
- else
- echo "$(date): allowcron not present: could not delete local files" >> /volume1/Plex/plexbootlog.log
- fi
- #----- Plex - 7d - Remove trashed and deleted items
- #Sync ACD to sorted to remove trashed/deleted items from acd currently not used still uploading files, runs every 7 days
- if [ -e /tmp/allowcron ]; then
- flock -n /volume1/Plex/encfs/acdrsync.lock -c '/usr/bin/rsync -r --delete --existing --ignore-existing /volume1/Plex/sorted/ /volume1/Plex/acd-sorted/' >/dev/null 2>&1
- else
- echo "$(date): allowcron not present: could not remove trashed and deleted items" >> /volume1/Plex/plexbootlog.log
- fi
- ################################
- # acdcheck from above #
- ################################
- #!/bin/sh
- echo "$(date): Remount Initiated"
- appname=$(basename $0)
- # Change this to the location of your Amazon Cloud Mountpoint
- acdmount="/volume1/Plex/.acd-sorted"
- if [ $(ls -l $acdmount | grep -v '^total' | wc -l) -gt 0 ]; then
- echo "$(date): Everything looks ok"
- exit
- fi
- if [ $(ps -Al | grep $appname | wc -l) -gt 2 ]; then
- echo "$(date): Already Running! Count $(ps -Al | grep $appname | wc -l)"
- exit
- fi
- echo "$(date): Remounting"
- /usr/local/bin/acd_cli umount "$acdmount"
- syncresult=$(/usr/local/bin/acd_cli sync 2>&1)
- if [ $(echo $syncresult | grep -i error | wc -l) -gt 0 ]; then
- echo "$(date): Error with the DB"
- echo "$(date): Removing ~/.cache/acd_cli/nodes.db"
- rm ~/.cache/acd_cli/nodes.db
- echo "$(date): acd_cli sync"
- /usr/local/bin/acd_cli sync
- sleep 10
- fi
- echo "syncresult: $syncresult"
- /usr/local/bin/acd_cli -nl mount --allow-other --modules="subdir,subdir=/plex" "$acdmount"
- echo "$(date): Remount Done"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement