Last active
April 9, 2025 04:20
-
-
Save wcheek/c1a1347b660775866e70629bee6b29cc to your computer and use it in GitHub Desktop.
mount-s3 on Amazon Linux 2 connection watchdog script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# mount-s3-watchdog.sh | |
# Inspiration from https://github.com/s3fs-fuse/s3fs-fuse/issues/152 | |
# Run from the root user's crontab to keep an eye on mount-s3 which should always | |
# be mounted. | |
# | |
# Note: If getting the amazon S3 credentials from environment variables | |
# these must be entered in the actual crontab file (otherwise use one | |
# of the s3fs other ways of getting credentials). | |
# | |
# Example: To run it once every minute getting credentials from envrironment | |
# variables enter this via "sudo crontab -e": | |
# | |
# AWSACCESSKEYID=XXXXXXXXXXXXXX | |
# AWSSECRETACCESSKEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | |
# * * * * * /root/mount-s3-watchdog.sh | |
# | |
# every ten minutes: */10 * * * * /root/mount-s3-watchdog.sh | |
NAME=mount-s3 | |
BUCKET=<bucket name> | |
MOUNTPATH=<mount point> | |
MOUNT=/bin/mount | |
UMOUNT=/bin/umount | |
GREP=/bin/grep | |
PS=/bin/ps | |
NOP=/bin/true | |
# Check if mount-s3 for your bucket is running | |
$PS -ef | $GREP -v grep | $GREP $NAME | grep $BUCKET >/dev/null 2>&1 | |
case "$?" in | |
0) | |
# It is running in this case so we do nothing. | |
# echo "$NAME is RUNNING for bucket $BUCKET. Doing Nothing." >/tmp/watchdogmount.out | |
$NOP | |
;; | |
1) | |
echo "$NAME is NOT RUNNING for bucket $BUCKET. Remounting $BUCKET with $NAME." >>/root/watchdogmount.out | |
fusermount -uz $MOUNTPATH >/dev/null 2>&1 | |
mount-s3 --allow-other --allow-delete --dir-mode 777 $BUCKET $MOUNTPATH >>/root/watchdogmount.out | |
;; | |
esac | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment