Make zfs.gentoo init script more gentoo style.
* Improved compatibility with openrc * Removed LOCKFILE * Improved checksystem() function * Remove /etc/mtab check for / * General cleanup
This commit is contained in:
parent
c91d229809
commit
04c22478a7
|
@ -7,85 +7,59 @@ depend()
|
||||||
{
|
{
|
||||||
before net
|
before net
|
||||||
after udev
|
after udev
|
||||||
|
keyword -lxc -openvz -prefix -vserver
|
||||||
}
|
}
|
||||||
|
|
||||||
CACHEFILE=/etc/zfs/zpool.cache
|
CACHEFILE=/etc/zfs/zpool.cache
|
||||||
ZPOOL=/usr/sbin/zpool
|
ZPOOL=/usr/sbin/zpool
|
||||||
ZFS=/usr/sbin/zfs
|
ZFS=/usr/sbin/zfs
|
||||||
ZFS_MODULE=zfs
|
ZFS_MODULE=zfs
|
||||||
LOCKFILE=/var/lock/zfs/zfs_lockfile
|
|
||||||
|
|
||||||
checksystem()
|
checksystem() {
|
||||||
{
|
if [ -c /dev/zfs ]; then
|
||||||
/sbin/modinfo $ZFS_MODULE &>/dev/null
|
einfo "ZFS modules already loaded"
|
||||||
if [[ $? -ne 0 ]]
|
return 0
|
||||||
then
|
else
|
||||||
eerror "$ZFS_MODULE not found. Is the ZFS package installed?"
|
einfo "Checking if ZFS modules present"
|
||||||
return 1
|
if [ -e $(modprobe -l $ZFS_MODULE | grep -q $ZFS_MODULE) ]; then
|
||||||
fi
|
eerror "$ZFS_MODULE not found. Is the ZFS package installed?"
|
||||||
if [[ ! -x $ZPOOL ]]
|
return 1
|
||||||
then
|
fi
|
||||||
eerror "$ZPOOL binary not found."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
if [[ ! -x $ZFS ]]
|
|
||||||
then
|
|
||||||
eerror "$ZFS binary not found."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# create the lockdir if not there
|
|
||||||
lockdir=$(dirname ${LOCKFILE})
|
|
||||||
if [[ ! -d ${lockdir} ]]
|
|
||||||
then
|
|
||||||
mkdir -p ${lockdir} &>/dev/null
|
|
||||||
fi
|
fi
|
||||||
|
einfo "Checking if zfs userspace tools present"
|
||||||
|
if [ ! -x $ZPOOL ]; then
|
||||||
|
eerror "$ZPOOL binary not found."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
if [ ! -x $ZFS ]; then
|
||||||
|
eerror "$ZFS binary not found."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
start()
|
start() {
|
||||||
{
|
|
||||||
if [[ -f $LOCKFILE ]]
|
|
||||||
then
|
|
||||||
einfo "ZFS already running, please stop it first. Delete $LOCKFILE if its not so."
|
|
||||||
eend 3
|
|
||||||
return 3
|
|
||||||
fi
|
|
||||||
ebegin "Starting ZFS"
|
ebegin "Starting ZFS"
|
||||||
checksystem || return 1
|
checksystem || return 1
|
||||||
if ! grep -q $ZFS_MODULE /proc/modules
|
if [ ! -c /dev/zfs ]; then
|
||||||
then
|
modprobe $ZFS_MODULE
|
||||||
/sbin/modprobe $ZFS_MODULE &>/dev/null
|
|
||||||
rv=$?
|
rv=$?
|
||||||
if [[ $rv -ne 0 ]]
|
if [ $rv -ne 0 ]; then
|
||||||
then
|
|
||||||
eerror "Failed to load the $ZFS_MODULE module, check 'dmesg|tail'."
|
eerror "Failed to load the $ZFS_MODULE module, check 'dmesg|tail'."
|
||||||
eend $rv
|
eend $rv
|
||||||
return $rv
|
return $rv
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ensure / exists in /etc/mtab, if not update mtab accordingly.
|
|
||||||
# This should be handled by rc.sysinit but lets be paranoid.
|
|
||||||
awk '$2 == "/" { exit 1 }' /etc/mtab
|
|
||||||
RETVAL=$?
|
|
||||||
if [[ $RETVAL -eq 0 ]]
|
|
||||||
then
|
|
||||||
/bin/mount -f /
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Import all pools described by the cache file, and then mount
|
# Import all pools described by the cache file, and then mount
|
||||||
# all filesystem based on their properties.
|
# all filesystem based on their properties.
|
||||||
if [[ -f $CACHEFILE ]]
|
if [ -f $CACHEFILE ]; then
|
||||||
then
|
|
||||||
einfo "Importing ZFS pools"
|
einfo "Importing ZFS pools"
|
||||||
|
|
||||||
# as per fedora script, import can fail if all pools are already imported
|
# as per fedora script, import can fail if all pools are already imported
|
||||||
# The check for $rv makes no sense...but someday, it will work right.
|
# The check for $rv makes no sense...but someday, it will work right.
|
||||||
$ZPOOL import -c $CACHEFILE -aN 2>/dev/null || true
|
$ZPOOL import -c $CACHEFILE -aN 2>/dev/null || true
|
||||||
rv=$?
|
rv=$?
|
||||||
if [[ $rv -ne 0 ]]
|
if [ $rv -ne 0 ]; then
|
||||||
then
|
|
||||||
eerror "Failed to import not-yet imported pools."
|
eerror "Failed to import not-yet imported pools."
|
||||||
eend $rv
|
eend $rv
|
||||||
return $rv
|
return $rv
|
||||||
|
@ -95,8 +69,7 @@ start()
|
||||||
einfo "Mounting ZFS filesystems"
|
einfo "Mounting ZFS filesystems"
|
||||||
$ZFS mount -a
|
$ZFS mount -a
|
||||||
rv=$?
|
rv=$?
|
||||||
if [[ $rv -ne 0 ]]
|
if [ $rv -ne 0 ]; then
|
||||||
then
|
|
||||||
eerror "Failed to mount ZFS filesystems."
|
eerror "Failed to mount ZFS filesystems."
|
||||||
eend $rv
|
eend $rv
|
||||||
return $rv
|
return $rv
|
||||||
|
@ -113,39 +86,23 @@ start()
|
||||||
done
|
done
|
||||||
cd "$savepwd"
|
cd "$savepwd"
|
||||||
|
|
||||||
touch $LOCKFILE
|
|
||||||
eend 0
|
eend 0
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
stop()
|
stop()
|
||||||
{
|
{
|
||||||
if [[ ! -f $LOCKFILE ]]
|
|
||||||
then
|
|
||||||
einfo "ZFS is not started, remove $LOCKFILE if its not so."
|
|
||||||
eend 3
|
|
||||||
return 3
|
|
||||||
fi
|
|
||||||
ebegin "Unmounting ZFS filesystems"
|
ebegin "Unmounting ZFS filesystems"
|
||||||
sync
|
|
||||||
$ZFS umount -a
|
$ZFS umount -a
|
||||||
if [[ $rv -ne 0 ]]
|
if [ $rv -ne 0 ]; then
|
||||||
then
|
|
||||||
eerror "Failed to umount ZFS filesystems."
|
eerror "Failed to umount ZFS filesystems."
|
||||||
fi
|
fi
|
||||||
rm -f $LOCKFILE
|
|
||||||
eend $rv
|
eend $rv
|
||||||
}
|
}
|
||||||
|
|
||||||
status()
|
status()
|
||||||
{
|
{
|
||||||
if [[ ! -f $LOCKFILE ]]
|
|
||||||
then
|
|
||||||
einfo "ZFS is not started, remove $LOCKFILE if its not so."
|
|
||||||
eend 3
|
|
||||||
return 3
|
|
||||||
fi
|
|
||||||
|
|
||||||
# show pool status and list
|
# show pool status and list
|
||||||
$ZPOOL status && echo && $ZPOOL list
|
$ZPOOL status && echo && $ZPOOL list
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue