Skip to content

Instantly share code, notes, and snippets.

@a5m0
Created July 21, 2016 23:50
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a5m0/5090c42f16c39c8a34876bfcc7b3703d to your computer and use it in GitHub Desktop.
Save a5m0/5090c42f16c39c8a34876bfcc7b3703d to your computer and use it in GitHub Desktop.
# basic script for restarting acd mount on failure and notifying via pushbullet,
# hardcoded and not great but whatever, note this mounts read-only, change to suit your needs
# put this in your crontab to run every 5 minuntes
# */5 * * * * python /home/user/acdmountdown.py > /dev/null
from pushbullet import Pushbullet
import os
import subprocess
import logging
logging.basicConfig(filename='acdmount.log', level=logging.INFO, format='%(asctime)s %(levelname)s %(message)s')
logging.info('ACD mount checker started')
DEVNULL = open(os.devnull, 'wb')
pb = Pushbullet('pushbullet-api-key-here')
exists = os.path.exists("/home/user/acd-mount/folder-to-check/")
if exists is not True:
logging.warning("ACD mount is down")
push = pb.push_note("ACD mount down", "attempting restart")
logging.info("attempting umount")
subprocess.call(["acd_cli", "umount"], stdin=None, stdout=DEVNULL)
logging.info("running ACD sync")
subprocess.call(["acd_cli", "sync"], stdin=None, stdout=DEVNULL)
logging.info("attempting ACD mount")
subprocess.call(["acd_cli", "mount", "-ro", "/home/user/acd-mount"], stdin=None, stdout=DEVNULL)
if os.path.exists("/home/user/acd-mount/folder-to-check/"):
push = pb.push_note("ACD mount back up", "restart successful")
logging.info("ACD mount restart succeeded")
else:
print 'all good'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment