]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-scripts: Improve service PID check
authorMartin Schwenke <mschwenke@ddn.com>
Fri, 10 May 2024 07:46:58 +0000 (17:46 +1000)
committerVolker Lendecke <vl@samba.org>
Thu, 30 May 2024 11:42:30 +0000 (11:42 +0000)
No need to grovel around in /proc.  ps will happily tell us the
command.

Factor out the actual check into a separate function that can be used
elsewhere.

Signed-off-by: Martin Schwenke <mschwenke@ddn.com>
Reviewed-by: Volker Lendecke <vl@samba.org>
ctdb/doc/examples/nfs-ganesha-callout

index f08dc49562622f75bf72ee1524c0a02aba566dbd..c09bec6781d5b3f44914fb75f562f7f9bc6a6fc6 100755 (executable)
@@ -232,6 +232,22 @@ create_ganesha_recdirs()
        esac
 }
 
+is_ganesha_running()
+{
+       # Check that NFS Ganesha is running, according to PID file
+       _pidfile="/var/run/ganesha/ganesha.pid"
+       _ganesha="ganesha.nfsd"
+       if ! {
+               read -r _pid <"$_pidfile" &&
+                       [ "$(ps -p "$_pid" -o comm=)" = "$_ganesha" ]
+       } >/dev/null 2>&1; then
+
+               return 1
+       fi
+
+       return 0
+}
+
 service_check()
 {
        create_ganesha_recdirs
@@ -242,14 +258,7 @@ service_check()
                return 0
        fi
 
-       # Check that NFS Ganesha is running, according to PID file
-       _pidfile="/var/run/ganesha/ganesha.pid"
-       _ganesha="/usr/bin/ganesha.nfsd"
-       if ! {
-               read -r _pid <"$_pidfile" &&
-                       grep "$_ganesha" "${procfs}/${_pid}/cmdline"
-       } >/dev/null 2>&1; then
-
+       if ! is_ganesha_running; then
                echo "ERROR: NFS Ganesha not running according to PID file"
                return 1
        fi