Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply several fixes to NFS service #313

Merged
merged 6 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 68 additions & 14 deletions tools/json/config.system.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,33 +130,87 @@
},
{
"id": "NFS01",
"description": "Install network filesystem (NFS) daemon",
"description": "Enable Network filesystem (NFS) support",
"command": [
"module_nfsd install"
"module_nfs install"
],
"status": "Stable",
"author": "@igorpecovnik",
"condition": "! module_nfsd status"
"condition": "! pkg_installed nfs-common"
},
{
"id": "NFS02",
"description": "Configure network filesystem (NFS) daemon",
"description": "Disable Network filesystem (NFS) support",
"command": [
"module_nfsd manage"
"module_nfs remove"
],
"status": "Stable",
"author": "@igorpecovnik",
"condition": "module_nfsd status"
"condition": "pkg_installed nfs-common"
},
{
"id": "NFS03",
"description": "Remove network filesystem (NFS) daemon",
"command": [
"module_nfsd uninstall"
],
"status": "Stable",
"author": "@igorpecovnik",
"condition": "module_nfsd status"
"id": "NFS05",
"description": "Manage NFS Server",
"condition": "pkg_installed nfs-common",
"sub": [
{
"id": "NFS06",
"description": "Enable network filesystem (NFS) daemon",
"command": [
"module_nfsd install"
],
"status": "Stable",
"author": "@igorpecovnik",
"condition": "! module_nfsd status"
},
{
"id": "NFS07",
"description": "Configure network filesystem (NFS) daemon",
"command": [
"module_nfsd manage"
],
"status": "Stable",
"author": "@igorpecovnik",
"condition": "module_nfsd status"
},
{
"id": "NFS08",
"description": "Remove network filesystem (NFS) daemon",
"command": [
"module_nfsd remove"
],
"status": "Stable",
"author": "@igorpecovnik",
"condition": "module_nfsd status"
},
{
"id": "NFS09",
"description": "Show network filesystem (NFS) daemon clients",
"command": [
"module_nfsd clients"
],
"status": "Stable",
"author": "@igorpecovnik",
"condition": "module_nfsd status && [[ ${NFS_CLIENTS_NUMBER} -gt 0 ]]"
}
]
},
{
"id": "NFS20",
"description": "Manage NFS Client",
"condition": "pkg_installed nfs-common",
"sub": [
{
"id": "NFS21",
"description": "Find NFS servers in subnet and mount shares",
"command": [
"module_nfs servers"
],
"status": "Stable",
"author": "@igorpecovnik",
"condition": "pkg_installed nfs-common"
}
]
}
]
},
Expand Down
18 changes: 18 additions & 0 deletions tools/modules/functions/service.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# service.sh

declare -A module_options
module_options+=(
["service,author"]="@dimitry-ishenko"
["service,desc"]="Wrapper for service manipulation"
["service,example"]="service install some.service"
["service,feature"]="service"
["service,status"]="active"
)

function service()
{
# ignore these commands, if running inside container
[[ "$1" =~ ^(reload|restart|start|status|stop)$ ]] && systemd-detect-virt -qc && return 0
systemctl daemon-reload
systemctl "$@"
}
1 change: 1 addition & 0 deletions tools/modules/runtime/config.runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ fi

update_sub_submenu_data "System" "Storage" "SY220" "$(module_zfs zfs_version)"
update_sub_submenu_data "System" "Storage" "SY221" "$(module_zfs zfs_installed_version)"
update_sub_submenu_data "System" "Storage" "NFS04" "$NFS_CLIENTS_NUMBER"
update_sub_submenu_data "Software" "Database" "DAT002" "Server: $LOCALIPADD"
update_sub_submenu_data "Software" "Database" "DAT006" "http://$LOCALIPADD:${module_options["module_phpmyadmin,port"]}"
update_sub_submenu_data "Software" "Media" "MED006" "http://$LOCALIPADD:${module_options["module_stirling,port"]}"
Expand Down
99 changes: 99 additions & 0 deletions tools/modules/system/module_nfs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
module_options+=(
["module_nfs,author"]="@igorpecovnik"
["module_nfs,feature"]="module_nfs"
["module_nfs,desc"]="Install nfs client"
["module_nfs,example"]="install remove servers help"
["module_nfs,port"]=""
["module_nfs,status"]="Active"
["module_nfs,arch"]=""
)
#
# Module nfs client
#
function module_nfs () {
local title="nfs"
local condition=$(which "$title" 2>/dev/null)?

local commands
IFS=' ' read -r -a commands <<< "${module_options["module_nfs,example"]}"

nfs_BASE="${SOFTWARE_FOLDER}/nfs"

case "$1" in
"${commands[0]}")
pkg_install nfs-common
;;
"${commands[1]}")
pkg_remove nfs-common
;;
"${commands[2]}")

if ! pkg_installed nmap; then
pkg_install nmap
fi

LIST=($(nmap -oG - -p2049 ${LOCALSUBNET} | grep '/open/' | cut -d' ' -f2 | grep -v "${LOCALIPADD}"))
LIST_LENGTH=$((${#LIST[@]}))
if nfs_server=$(dialog --no-items \
--title "Network filesystem (NFS) servers in subnet" \
--menu "" \
$((${LIST_LENGTH} + 6)) \
80 \
$((${LIST_LENGTH})) \
${LIST[@]} 3>&1 1>&2 2>&3); then
# verify if we can connect there
LIST=($(showmount -e "${nfs_server}" | tail -n +2 | cut -d" " -f1 | sort))
VERIFIED_LIST=()
local tempfolder=$(mktemp -d)
local alreadymounted=$(df | grep $nfs_server | cut -d" " -f1 | xargs)
for i in "${LIST[@]}"; do
mount -n -t nfs $nfs_server:$i ${tempfolder} 2>/dev/null
if [[ $? -eq 0 ]]; then
if echo "${alreadymounted}" | grep -vq $i; then
VERIFIED_LIST+=($i)
fi
umount ${tempfolder}
fi
done
VERIFIED_LIST_LENGTH=$((${#VERIFIED_LIST[@]}))
if shares=$(dialog --no-items \
--title "Network filesystem (NFS) shares on ${nfs_server}" \
--menu "" \
$((${VERIFIED_LIST_LENGTH} + 6)) \
80 \
$((${VERIFIED_LIST_LENGTH})) \
${VERIFIED_LIST[@]} 3>&1 1>&2 2>&3)
then
if mount_folder=$(dialog --title \
"Where do you want to mount $shares ?" \
--inputbox "" \
6 80 "/armbian" 3>&1 1>&2 2>&3); then
if mount_options=$(dialog --title \
"Which mount options do you want to use?" \
--inputbox "" \
6 80 "auto,noatime 0 0" 3>&1 1>&2 2>&3); then
mkdir -p ${mount_folder}
sed -i '\?^'$nfs_server:$shares'?d' /etc/fstab
echo "${nfs_server}:${shares} ${mount_folder} nfs ${mount_options}" >> /etc/fstab
systemctl daemon-reload
mount ${mount_folder}
show_message <<< $(mount -t nfs4 | cut -d" " -f1)
fi
fi
fi
fi
;;
"${commands[3]}")
echo -e "\nUsage: ${module_options["module_nfs,feature"]} <command>"
echo -e "Commands: ${module_options["module_nfs,example"]}"
echo "Available commands:"
echo -e "\tinstall\t- Install $title."
echo -e "\tremove\t- Remove $title."
echo -e "\tservers\t- Find and mount shares $title."
echo
;;
*)
${module_options["module_nfs,feature"]} ${commands[3]}
;;
esac
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module_options+=(
["module_nfsd,author"]="@igorpecovnik"
["module_nfsd,feature"]="module_nfsd"
["module_nfsd,desc"]="Install nfsd server"
["module_nfsd,example"]="install remove manage add status help"
["module_nfsd,example"]="install remove manage add status clients servers help"
["module_nfsd,port"]=""
["module_nfsd,status"]="Active"
["module_nfsd,arch"]=""
Expand All @@ -14,6 +14,8 @@ function module_nfsd () {
local title="nfsd"
local condition=$(which "$title" 2>/dev/null)?

local service_name=nfs-server.service

# we will store our config in subfolder
mkdir -p /etc/exports.d/

Expand All @@ -27,7 +29,7 @@ function module_nfsd () {
pkg_install nfs-common nfs-kernel-server
# add some exports
${module_options["module_nfsd,feature"]} ${commands[2]}
systemctl restart nfs-server.service
service restart $service_name
;;
"${commands[1]}")
pkg_remove nfs-kernel-server
Expand Down Expand Up @@ -65,7 +67,7 @@ function module_nfsd () {
break
fi
done
systemctl restart nfs-server.service
service restart $service_name
;;
"${commands[3]}")
# choose between most common options
Expand Down Expand Up @@ -96,13 +98,69 @@ function module_nfsd () {
fi
;;
"${commands[4]}")
if systemctl is-active --quiet nfs-server.service; then
return 0
else
return 1
fi
pkg_installed nfs-kernel-server
;;
"${commands[5]}")
show_message <<< $(printf '%s\n' "${NFS_CLIENTS_CONNECTED[@]}")
;;
"${commands[6]}")

if ! pkg_installed nmap; then
pkg_install nmap
fi

LIST=($(nmap -oG - -p2049 ${LOCALSUBNET} | grep '/open/' | cut -d' ' -f2 | grep -v "${LOCALIPADD}"))
LIST_LENGTH=$((${#LIST[@]}))
if nfs_server=$(dialog --no-items \
--title "Network filesystem (NFS) servers in subnet" \
--menu "" \
$((${LIST_LENGTH} + 6)) \
80 \
$((${LIST_LENGTH})) \
${LIST[@]} 3>&1 1>&2 2>&3); then
# verify if we can connect there
LIST=($(showmount -e "${nfs_server}" | tail -n +2 | cut -d" " -f1 | sort))
VERIFIED_LIST=()
local tempfolder=$(mktemp -d)
local alreadymounted=$(df | grep $nfs_server | cut -d" " -f1 | xargs)
for i in "${LIST[@]}"; do
mount -n -t nfs $nfs_server:$i ${tempfolder} 2>/dev/null
if [[ $? -eq 0 ]]; then
if echo "${alreadymounted}" | grep -vq $i; then
VERIFIED_LIST+=($i)
fi
umount ${tempfolder}
fi
done
VERIFIED_LIST_LENGTH=$((${#VERIFIED_LIST[@]}))
if shares=$(dialog --no-items \
--title "Network filesystem (NFS) shares on ${nfs_server}" \
--menu "" \
$((${VERIFIED_LIST_LENGTH} + 6)) \
80 \
$((${VERIFIED_LIST_LENGTH})) \
${VERIFIED_LIST[@]} 3>&1 1>&2 2>&3)
then
if mount_folder=$(dialog --title \
"Where do you want to mount $shares ?" \
--inputbox "" \
6 80 "/armbian" 3>&1 1>&2 2>&3); then
if mount_options=$(dialog --title \
"Which mount options do you want to use?" \
--inputbox "" \
6 80 "auto,noatime 0 0" 3>&1 1>&2 2>&3); then
mkdir -p ${mount_folder}
read
sed -i '\?^'$nfs_server:$shares'?d' /etc/fstab
echo "${nfs_server}:${shares} ${mount_folder} nfs ${mount_options}" >> /etc/fstab
systemctl daemon-reload
mount ${mount_options}
fi
fi
fi
fi
;;
"${commands[7]}")
echo -e "\nUsage: ${module_options["module_nfsd,feature"]} <command>"
echo -e "Commands: ${module_options["module_nfsd,example"]}"
echo "Available commands:"
Expand All @@ -114,7 +172,7 @@ function module_nfsd () {
echo
;;
*)
${module_options["module_nfsd,feature"]} ${commands[5]}
${module_options["module_nfsd,feature"]} ${commands[7]}
;;
esac
}
Loading