Skip to content

Commit

Permalink
AutoNFS v1.4.2: Added support for new loglevels
Browse files Browse the repository at this point in the history
fixes #7

Signed-off-by: Martin Seener <[email protected]>
  • Loading branch information
martinseener committed Aug 17, 2014
1 parent 263abdf commit 3031d91
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
AutoNFS is a client-side autofs-free NFS Share Automount-Script, initially designed for Debian Squeeze or derivates.
The Code can be found at [https://github.com/martinseener/autonfs](https://github.com/martinseener/autonfs)

## v1.4.2
- Added new logging system. You can disbale logging completly or switch up to debug logging. ([fixes #7](https://github.com/martinseener/autonfs/issues/7))

## v1.4.1
- Renamed OS folders to Init-System names. So we support SysVinit (Debian), Upstart (Ubuntu) and the new Systemd (OpenSUSE) and their respective derivates ([fixed #6](https://github.com/martinseener/autonfs/issues/6))
- Renamed OS folders to Init-System names. So we support SysVinit (Debian), Upstart (Ubuntu) and the new Systemd (OpenSUSE) and their respective derivates ([fixes #6](https://github.com/martinseener/autonfs/issues/6))

## v1.4
- Removed Roadmap from README - we have Github for this
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# AutoNFS

AutoNFS is a client-side autofs-free NFS Share Automount-Script, initially designed for Debian Squeeze or derivates.
AutoNFS is a client-side autofs-free NFS Share Automount-Script, initially designed for Debian Squeeze or derivates it now also runs smoothly on systems that use SysVinit, Upstart or Systemd init-systems like Ubuntu, OpenSUSE or RHEL/CentOS.

The initial Github version of AutoNFS v1.2.1 - as is - running quite well and stable in our production environment containing of about 20 NFS Shares and one NFS 3 Server - all with latest Debian Squeeze
## Available versions

If you want the latest stable version of AutoNFS you can easily stick with the master branch. If you want a specific version, checkout the respective branch.
The latest stuff is always available on the Development branch.

## Installation and Usage

Expand All @@ -23,6 +26,7 @@ You can also uncomment all lines starting with `#logger` to get a more verbose s
## Variables explanation

- `SCRIPTPATH` - The path to the AutoNFS executable (default: /usr/local/bin/autonfs.sh)
- `LOGLEVEL` - Set the desired log level from 0 (disabled) trough 1 (normal logging) to 2 (debug logging)
- `NFSSERVER` - The NFS Server you want to mount something from can be either a single IP or a DNS-Name
- `NFSVERS` - Defines the NFS Protocol (2,3 or 4) to be used for checking the Server and is needed to prevent writing "unknown version" warnings in the syslog
- `MOUNTOPT` - Here you can define the classic NFS Mount options like you would in the fstab (uses good defaults for most scenarios)
Expand Down
5 changes: 5 additions & 0 deletions etc/default/autonfs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
# Default: /usr/local/bin/autonfs.sh
SCRIPTPATH="/usr/local/bin/autonfs.sh"

# Set the log level
# LOGLEVEL=2 debug, LOGLEVEL=1 normal logging, LOGLEVEL=0 disabled
# Default: 1
LOGLEVEL=1

# The hostname or IP address of the NFS Server
# Can be an resolvable DNS Name like "nfsserver.example.com"
# or an IP like "10.10.10.2"
Expand Down
21 changes: 9 additions & 12 deletions usr/local/bin/autonfs.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
#!/usr/bin/env bash

# AutoNFS v1.4.1
# AutoNFS v1.4.2

# (c) 2012-2014 by Martin Seener ([email protected])
# Licensed under the GPLv2

# Code can be found at github.com/martinseener/autonfs

# Hints:
# - only limited logging is active; for debug logging, uncomment all "logger" lines

# Load the configuration file
if [ -f "/etc/default/autonfs" ]; then
. /etc/default/autonfs
else
logger -t autonfs "Cannot find configuration file. Exiting."
if [ $LOGLEVEL -ge 1 ]; then logger -t autonfs "Cannot find configuration file. Exiting."; fi
exit 3
fi

Expand All @@ -28,12 +25,12 @@ while true; do
/usr/bin/rpcinfo -t "$FILESERVER" nfs $NFSVERS &>/dev/null
if [ $? -ne 0 ]; then
# First check failed, therefore doing it twice after a second
logger -t autonfs "Fileserver[${FILESERVER}] seems to be down - Rechecking in a second"
if [ $LOGLEVEL -ge 1 ]; then logger -t autonfs "Fileserver[${FILESERVER}] seems to be down - Rechecking in a second"; fi
sleep 1
/usr/bin/rpcinfo -t "$FILESERVER" nfs $NFSVERS &>/dev/null
if [ $? -eq 0 ]; then
# Second check was succssful, checking if all NFS Shares are mounted
logger -t autonfs "Fileserver[${FILESERVER}] is up"
if [ $LOGLEVEL -ge 1 ]; then logger -t autonfs "Fileserver[${FILESERVER}] is up"; fi
for MOUNT in ${MOUNTS[@]}; do
# Split the share if it has a different remote and local mountpoint
# Both will be the same if the mountpoints are so too
Expand All @@ -44,13 +41,13 @@ while true; do
mount | grep -E "^${FILESERVER}:${RMNTPATH} on .*$" &>/dev/null
if [ $? -ne 0 ]; then
# The actual NFS Share is not mounted, so it will be done now
#logger -t autonfs "NFS-Share[${MOUNT}] not mounted - attempting to mount it from: ${FILESERVER}:${MOUNT}"
if [ $LOGLEVEL -eq 2 ]; then logger -t autonfs "NFS-Share[${MOUNT}] not mounted - attempting to mount it from: ${FILESERVER}:${MOUNT}"; fi
mount -t nfs ${MOUNTOPT} ${FILESERVER}:${RMNTPATH} ${LMNTPATH}
fi
done
else
# The Fileserver was not reachable two times, unmounting shares which are still mounted
logger -t autonfs "Fileserver(${FILESERVER}) is down."
if [ $LOGLEVEL -ge 1 ]; then logger -t autonfs "Fileserver(${FILESERVER}) is down."; fi
for MOUNT in ${MOUNTS[@]}; do
# Split the share if it has a different remote and local mountpoint
# Both will be the same if the mountpoints are so too
Expand All @@ -60,14 +57,14 @@ while true; do
# Let's check if its already mounted
mount | grep -E "^${FILESERVER}:${RMNTPATH} on .*$" &>/dev/null
if [ $? -eq 0 ]; then
logger -t autonfs "Cannot reach ${FILESERVER}, therefore unmounting NFS-Share[${LMNTPATH}]"
if [ $LOGLEVEL -ge 1 ]; then logger -t autonfs "Cannot reach ${FILESERVER}, therefore unmounting NFS-Share[${LMNTPATH}]"; fi
umount -f ${LMNTPATH}
fi
done
fi
else
# First check succeeded, so just checking if all NFS-Shares are mounted
#logger -t autonfs "Fileserver[${FILESERVER}] is up"
if [ $LOGLEVEL -eq 2 ]; then logger -t autonfs "Fileserver[${FILESERVER}] is up"; fi
for MOUNT in ${MOUNTS[@]}; do
# Split the share if it has a different remote and local mountpoint
# Both will be the same if the mountpoints are so too
Expand All @@ -78,7 +75,7 @@ while true; do
mount | grep -E "^${FILESERVER}:${RMNTPATH} on .*$" &>/dev/null
if [ $? -ne 0 ]; then
# The actual NFS Share is not mounted, so it will be done now
#logger -t autonfs "NFS-Share[${MOUNT}] not mounted - attempting to mount it from: ${FILESERVER}:${MOUNT}"
if [ $LOGLEVEL -eq 2 ]; then logger -t autonfs "NFS-Share[${MOUNT}] not mounted - attempting to mount it from: ${FILESERVER}:${MOUNT}"; fi
mount -t nfs ${MOUNTOPT} ${FILESERVER}:${RMNTPATH} ${LMNTPATH}
fi
done
Expand Down

0 comments on commit 3031d91

Please sign in to comment.