Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ################################
- # CRON #
- ################################
- # This script is executed at boot. It will mount all necessary ACD_CLI folders.
- @reboot /home/cron/plex-boot.sh >> /home/plex/plexbootlog.log
- # Minute Hour Day of Month Month Day of Week Command
- # (0-59) (0-23) (1-31) (1-12) (0-6)
- #30 minutes check to ensure ACD is mounted/node db not corrupt. Source: http://disq.us/p/1ckpl2e
- */30 * * * * /home/cron/plex-check.sh >> /home/plex/plexbootlog.log
- #Sync ACD to sorted every 20 minutes
- */20 * * * * /home/cron/plex-sync.sh >> /home/plex/plexbootlog.log
- #1 day check: clean-up locally stored files that are allready on ACD
- 0 5 * * * /home/cron/plex-cleanup.sh >> /home/plex/plexbootlog.log
- ################################
- # plex-boot.sh #
- ################################
- #!/bin/sh -e
- #
- # plex-boot.sh
- #
- # This script is executed at boot. It will mount all necessary folders.
- #
- # It is executed from crontab -e
- # >> /home/plex/plexbootlog.log
- echo "-------------"
- echo "$(date): Sleep 30 seconds"
- sleep 30
- echo "$(date): Waking up"
- # To not log use >/dev/null 2>&1
- echo "$(date): mounting /local-sorted (encfs)"
- #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 folders
- ENCFS6_CONFIG='/home/plex/encfs/encfs.xml' /usr/bin/encfs --extpass="cat /home/plex/encfs/encfspass" /home/plex/.local-sorted /home/plex/local-sorted
- echo "$(date): mounting /.acd-sorted (ACDFuse)"
- #--allow-other lets other linux users see encrypted acd dir, --modules="subdir,subdir=/dir" mounts specific acd directory
- /usr/local/bin/acd_cli mount --allow-other --modules="subdir,subdir=/plex" /home/plex/.acd-sorted/
- echo "$(date): mounting /acd-sorted (encfs)"
- #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='/home/plex/encfs/encfs.xml' /usr/bin/encfs --extpass="cat /home/plex/encfs/encfspass" /home/plex/.acd-sorted /home/plex/acd-sorted
- echo "$(date): mounting /sorted (unionfs)"
- # -o allow_other lets my other linux users follow permissions so plex can see sorted
- # uid = user id (112=plex), gid = group id (116=plex)
- /usr/bin/unionfs-fuse -o cow -o allow_other,uid=112,gid=116 /home/plex/local-sorted=RW:/home/plex/acd-sorted=RO /home/plex/sorted/
- # Make file so the cron jobs can run
- touch /tmp/allowcron
- echo "$(date): /tmp/allowcron made"
- echo "$(date): boot process finished"
- exit 0
- ################################
- # plex-check.sh #
- ################################
- #!/bin/sh -e
- #
- # plex-check.sh
- #
- # 30 minutes check to ensure ACD is mounted/node
- # db not corrupt. Source: http://disq.us/p/1ckpl2e
- #
- # flock ensures it's not executed twice.
- #
- # It is executed from crontab -e
- if [ -e /tmp/allowcron ]; then
- flock -n /home/plex/encfs/acdcheck.lock -c 'bash /usr/local/bin/acdcheck'
- else
- echo "$(date): allowcron not present: could not acdcheck"
- fi
- exit 0
- #################################
- # acdcheck (from plex-check.sh) #
- #################################
- #!/bin/sh
- echo "$(date): Remount Initiated $(date)"
- appname=$(basename $0)
- # Change this to the location of your Amazon Cloud Mountpoint
- acdmount="/home/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 "Remount Done $(date)"
- ################################
- # plex-sync.sh #
- ################################
- #!/bin/sh -e
- #
- # plex-sync.sh
- #
- # This script is executed every 20 minutes.
- # It will sync ACD data to sorted.
- #
- # flock ensures it's not executed twice.
- #
- # It is executed from crontab -e
- if [ -e /tmp/allowcron ]; then
- flock -n /home/plex/encfs/acdsync.lock -c '/usr/local/bin/acd_cli sync'
- else
- echo "$(date): allowcron not present: could not acd_cli sync"
- fi
- exit 0
- ################################
- # plex-cleanup.sh #
- ################################
- #!/bin/sh -e
- #
- # plex-cleanup.sh
- #
- # This script is executed every day.
- # Cleans up files stored locally that are already on ACD
- #
- # flock ensures it's not executed twice.
- #
- # It is executed from crontab -e
- if [ -e /tmp/allowcron ]; then
- # 22-10: might need a >/dev/null 2>&1 at the end to surpress errors
- flock -n /home/plex/encfs/acdcleanup.lock -c 'find /home/plex/.local-sorted/ -type f -exec rm -rf {} \; && find /home/plex/.local-sorted/ -type d -empty -exec rm -rf {} \;'
- else
- echo "$(date): allowcron not present: could not cleanup local files"
- fi
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement