Bug#488275: [Pkg-samba-maint] Bug#488275: samba and winbind: initscript miss 'status' option

2008-07-09 Thread Dustin Kirkland
Here is a patch that provides the status action functionality for nmbd,
smbd, and winbindd.  I developed this against Ubuntu and am submitting
this for inclusion in Debian.  Thanks to Steve for his copious feedback
on IRC.

Note that the hunk dealing with the debian/control file may need to be
tweaked based on the acceptance of the patch for [1] being accepted into
lsb-based and released.

[1] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=490095

-- 
:-Dustin

Dustin Kirkland
Ubuntu Server Developer
Canonical, LTD
[EMAIL PROTECTED]
GPG: 1024D/83A61194
diff -uprN samba.debian.orig/samba-3.0.30/debian/control samba.debian/samba-3.0.30/debian/control
--- samba.debian.orig/samba-3.0.30/debian/control	2008-07-09 18:55:28.0 -0500
+++ samba.debian/samba-3.0.30/debian/control	2008-07-09 19:02:51.0 -0500
@@ -9,7 +9,7 @@ Standards-Version: 3.8.0
 
 Package: samba
 Architecture: any
-Depends: samba-common (= ${binary:Version}), logrotate, ${shlibs:Depends}, ${misc:Depends}, libpam-runtime (= 0.76-13.1), libpam-modules, lsb-base (= 3.0-6), procps, update-inetd, adduser
+Depends: samba-common (= ${binary:Version}), logrotate, ${shlibs:Depends}, ${misc:Depends}, libpam-runtime (= 0.76-13.1), libpam-modules, lsb-base (= 3.2-13), procps, update-inetd, adduser
 Suggests: openbsd-inetd | inet-superserver, smbldap-tools
 Replaces: samba-common (= 2.0.5a-2)
 Description: a LanManager-like file and printer server for Unix
diff -uprN samba.debian.orig/samba-3.0.30/debian/samba.init samba.debian/samba-3.0.30/debian/samba.init
--- samba.debian.orig/samba-3.0.30/debian/samba.init	2008-07-09 18:55:28.0 -0500
+++ samba.debian/samba-3.0.30/debian/samba.init	2008-07-09 19:02:51.0 -0500
@@ -98,8 +98,22 @@ case $1 in
 		sleep 1
 		$0 start
 		;;
+status)
+		status=0
+		NMBD_DISABLED=`testparm -s --parameter-name='disable netbios' 2/dev/null`
+		if [ $NMBD_DISABLED != Yes ]; then
+			status_of_proc -p $NMBDPID /usr/sbin/nmbd nmbd || status=$?
+		fi
+		if [ $RUN_MODE != inetd ]; then
+			status_of_proc -p $SMBDPID /usr/sbin/smbd smbd || status=$?
+		fi
+		if [ $NMBD_DISABLED = Yes -a $RUN_MODE = inetd ]; then
+			status=4
+		fi
+		exit $status
+		;;
 	*)
-		echo Usage: /etc/init.d/samba {start|stop|reload|restart|force-reload}
+		echo Usage: /etc/init.d/samba {start|stop|reload|restart|force-reload|status}
 		exit 1
 		;;
 esac
diff -uprN samba.debian.orig/samba-3.0.30/debian/winbind.init samba.debian/samba-3.0.30/debian/winbind.init
--- samba.debian.orig/samba-3.0.30/debian/winbind.init	2008-07-09 18:55:28.0 -0500
+++ samba.debian/samba-3.0.30/debian/winbind.init	2008-07-09 19:02:51.0 -0500
@@ -16,6 +16,7 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin
 
 DAEMON=/usr/sbin/winbindd
 PIDDIR=/var/run/samba
+WINBINDPID=$PIDDIR/winbindd.pid
 
 # clear conflicting settings from the environment
 unset TMPDIR
@@ -47,8 +48,11 @@ case $1 in
 		$0 stop  sleep 2  $0 start
 		;;
 
+	status)
+		status_of_proc -p $WINBINDPID $DAEMON winbind  exit 0 || exit $?
+
 	*)
-		echo Usage: /etc/init.d/winbind {start|stop|restart|force-reload}
+		echo Usage: /etc/init.d/winbind {start|stop|restart|force-reload|status}
 		exit 1
 		;;
 esac


signature.asc
Description: This is a digitally signed message part


Bug#488275: [Pkg-samba-maint] Bug#488275: samba and winbind: initscript miss 'status' option

2008-07-08 Thread Dustin Kirkland
Hi-

I'm working on a generic status_of_proc() function to be provided
by /lib/lsb/init-functions in the lsb-base package.

This bug is:
 * http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=483285

This function also currently uses /bin/pidof, although eventually, I'd
like at add some improved support for pidfiles as well.  Having this
functionality in a single library function is far more maintainable than
scattering this sort of functionality across dozens/hundreds/thousands
of init scripts.

Although the patch hasn't been accepted in Debian's lsb-base yet, we
have applied it and are working on it in Ubuntu's development tree
(Intrepid) at the moment.  We're tracking this as a single bug at this
moment here:
 * https://bugs.edge.launchpad.net/ubuntu/+source/sysklogd/+bug/203169

I've modified a handful of service init scripts, including Samba to use
this function.  I don't know if it'll (yet) serve your heartbeat needs,
but in my testing, it seems to work perform correctly, telling you if
nmbd/smbd/winbindd are running or not.
 * http://launchpadlibrarian.net/15898919/samba.status.debdiff

Once the status_of_proc() function is in lsb-base, I intend to push this
patch to Debian's samba.

-- 
:-Dustin

Dustin Kirkland
Ubuntu Server Developer
Canonical, LTD
[EMAIL PROTECTED]
GPG: 1024D/83A61194


signature.asc
Description: This is a digitally signed message part


Bug#488275: [Pkg-samba-maint] Bug#488275: samba and winbind: initscript miss 'status' option

2008-07-04 Thread Steve Langasek
On Thu, Jul 03, 2008 at 05:39:31PM +0200, Tim Stoop wrote:

 Op 2-jul-2008, om 5:54 heeft Steve Langasek het volgende geschreven:
 I think it would be better to first fix winbind to use a proper PID
 file,
 then use code similar to that in the smbd/nmbd case.

 I'll spend some time today to see if I can fix that. I guess the --
 make-pidfile option from start-stop-daemon should be used. Will let 
 you
 know when I come up with something that works.

 Ok, thanks for the interest!

 I'm a bit confused about the following part of the winbind init script:

 mkdir -p /var/run/samba/winbindd_privileged || return 1
 chgrp winbindd_priv $PIDDIR/winbindd_privileged/ || return 1
 chmod 0750 $PIDDIR/winbindd_privileged/ || return 1

 I'm guessing it's only used to check if there's already a winbind  
 running? Or is the directory used for anything else? Can I remove this 
 and replace it with the usage of --make-pidfile in start-stop-daemon?

This is to ensure that the /var/run/samba heirarchy is created before use,
in the event that the system uses a tmpfs for /var/run (and therefore
directories don't persist across reboots).

No, this has nothing at all to do with pidfiles - the existing code is
correct and should not be altered.  Nor should the
/var/run/samba/winbindd_privileged directory be used for pidfiles.

(I don't know why we have $PIDDIR used in some cases and not others - that's
an inconsistency that we should correct at some point.)

Cheers,
-- 
Steve Langasek   Give me a lever long enough and a Free OS
Debian Developer   to set it on, and I can move the world.
Ubuntu Developerhttp://www.debian.org/
[EMAIL PROTECTED] [EMAIL PROTECTED]



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Bug#488275: [Pkg-samba-maint] Bug#488275: samba and winbind: initscript miss 'status' option

2008-07-03 Thread Tim Stoop


Op 2-jul-2008, om 5:54 heeft Steve Langasek het volgende geschreven:

I think it would be better to first fix winbind to use a proper PID
file,
then use code similar to that in the smbd/nmbd case.



I'll spend some time today to see if I can fix that. I guess the --
make-pidfile option from start-stop-daemon should be used. Will  
let you

know when I come up with something that works.


Ok, thanks for the interest!


I'm a bit confused about the following part of the winbind init script:

mkdir -p /var/run/samba/winbindd_privileged || return 1
chgrp winbindd_priv $PIDDIR/winbindd_privileged/ || return 1
chmod 0750 $PIDDIR/winbindd_privileged/ || return 1

I'm guessing it's only used to check if there's already a winbind  
running? Or is the directory used for anything else? Can I remove  
this and replace it with the usage of --make-pidfile in start-stop- 
daemon?


--
Kind regards,
Met vriendelijke groet,

Tim Stoop


Kumina bv
www.kumina.nl
kvk nr 14095795




--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Bug#488275: [Pkg-samba-maint] Bug#488275: samba and winbind: initscript miss 'status' option

2008-07-02 Thread Tim Stoop


Op 2-jul-2008, om 5:54 heeft Steve Langasek het volgende geschreven:

There's an example of this already in /etc/init.d/samba.


Ah yes, in testing. Using that version of the init script now for my  
development (seems to work as expected for the version in Etch, too).


Perhaps that check is worth refactoring into a small shell function  
at the

top of the script, perhaps not.


I moved it to the top of the script. Maybe you prefer it otherwise,  
let me know, I'll change it.


I only had time to fix this in the samba init script. Will work on  
winbind later this week (I hope).

diff
Description: Binary data


--
Kind regards,
Met vriendelijke groet,

Tim Stoop


Kumina bv
www.kumina.nl
kvk nr 14095795



Bug#488275: [Pkg-samba-maint] Bug#488275: samba and winbind: initscript miss 'status' option

2008-07-01 Thread Tim Stoop


Op 30-jun-2008, om 23:14 heeft Steve Langasek het volgende geschreven:

Here comes the criticism ;)


I prefer the term constructive remarks ;-)

So the right way to do this is to look at the PID files themselves  
first,
check their contents, and verify that those processes are still  
running.


True that. I'll try your code today and report back with a proper diff.

Note that procps is required for this functionality to work,  
because of the
use of ps.  I don't know that a dependency is actually warranted,  
since this
is optional functionality; anyway, procps is Priority: required, so  
it will

always be present in practice.


Should the script check for the existence of /bin/ps? Or should I  
just leave it as it is?


I don't have a problem with the 'echo' statements myself, though I  
do object

to the use of exclamation marks. :)


Uh... woops? :) Will replace them.

Well, this means that no meaningful status will be returned if one  
of the
daemons is running but the other is not.  Concretely, this means it  
won't

return useful status in the event that smbd is started out of inetd
(RUN_MODE=inetd), or that 'disable netbios' is set, causing nmbd to  
not be

run.


Checking /etc/default/samba is easy, but I'm not sure if I can  
reliably check for the 'disable netbios' option. Any hints on how to  
do this?


I think it would be better to first fix winbind to use a proper PID  
file,

then use code similar to that in the smbd/nmbd case.


I'll spend some time today to see if I can fix that. I guess the -- 
make-pidfile option from start-stop-daemon should be used. Will let  
you know when I come up with something that works.


--
Kind regards,
Met vriendelijke groet,

Tim Stoop


Kumina bv
www.kumina.nl
kvk nr 14095795




--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Bug#488275: [Pkg-samba-maint] Bug#488275: samba and winbind: initscript miss 'status' option

2008-07-01 Thread Steve Langasek
On Tue, Jul 01, 2008 at 10:34:09AM +0200, Tim Stoop wrote:
 Note that procps is required for this functionality to work, because of 
 the
 use of ps.  I don't know that a dependency is actually warranted,  
 since this
 is optional functionality; anyway, procps is Priority: required, so it 
 will
 always be present in practice.

 Should the script check for the existence of /bin/ps? Or should I just 
 leave it as it is?

Well, if I actually pay attention, samba already depends on procps, so it
doesn't matter anyway.

Otherwise, I still think it would've been fine because procps is Priority:
required, which means its always installed - it's just not guaranteed to be
configured at any given moment.

 Well, this means that no meaningful status will be returned if one of 
 the
 daemons is running but the other is not.  Concretely, this means it  
 won't
 return useful status in the event that smbd is started out of inetd
 (RUN_MODE=inetd), or that 'disable netbios' is set, causing nmbd to  
 not be
 run.

 Checking /etc/default/samba is easy, but I'm not sure if I can reliably 
 check for the 'disable netbios' option. Any hints on how to do this?

There's an example of this already in /etc/init.d/samba.

Perhaps that check is worth refactoring into a small shell function at the
top of the script, perhaps not.

 I think it would be better to first fix winbind to use a proper PID  
 file,
 then use code similar to that in the smbd/nmbd case.

 I'll spend some time today to see if I can fix that. I guess the -- 
 make-pidfile option from start-stop-daemon should be used. Will let you 
 know when I come up with something that works.

Ok, thanks for the interest!

Cheers,
-- 
Steve Langasek   Give me a lever long enough and a Free OS
Debian Developer   to set it on, and I can move the world.
Ubuntu Developerhttp://www.debian.org/
[EMAIL PROTECTED] [EMAIL PROTECTED]



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Bug#488275: [Pkg-samba-maint] Bug#488275: samba and winbind: initscript miss 'status' option

2008-06-30 Thread Tim Stoop


Op 28-jun-2008, om 15:25 heeft Christian Perrier het volgende  
geschreven:

I think you're very welcome to propose a patch. We'll review it
(indeed, Steve will criticize it and I'll just look..:-)) and,
hopefully, integrate it.


This is my addition to the initscript for samba:

  status)
SMBRETURN=3
NMBRETURN=3
PIDS_SMBD=`pidof smbd  /dev/null; echo $?`
PIDS_NMBD=`pidof nmbd  /dev/null; echo $?`
if [ $PIDS_SMBD -gt 0 ]
then
  if [ -f $SMBDPID ]
  then
echo smbd not running, pidfile exists!
SMBRETURN=1
  else
echo smbd not running.
  fi
else
  if [ -f $SMBDPID ]
  then
echo smbd running
SMBRETURN=0
  else
echo smbd running, but no pidfile exists!
# No LSB defined return code for this :(
SMBRETURN=0
  fi
fi
if [ $PIDS_NMBD -gt 0 ]
then
  if [ -f $NMBDPID ]
  then
echo nmbd not running, pidfile exists!
NMBRETURN=1
  else
echo nmbd not running.
  fi
else
  if [ -f $NMBDPID ]
  then
echo nmbd running
NMBRETURN=0
  else
echo nmbd running, but no pidfile exists!
# No LSB defined return code for this :(
NMBRETURN=0
  fi
fi
if [ $SMBRETURN -eq 1 ] || [ $SMBRETURN -eq 1 ]
then
  exit 1
elif [ $SMBRETURN -eq $NMBRETURN ]
then
  exit $SMBRETURN
else
  # Apparantly, we have an unknown state, or at least something
  # that we can't fix easily
  return 4
fi
;;

I took some liberties here and it's not really nice code, but it  
seems to work in our setup. I believe it's readable.


The same for winbind (much simpler):

  status)
PIDS_WINBIND=`pidof winbindd  /dev/null; echo $?`
if [ $PIDS_WINBIND -eq 0 ]
then
  echo winbind is running
  exit 0
else
  echo winbind is stopped
  exit 3
fi
;;

Hope this helps you!

--
Kind regards,
Met vriendelijke groet,

Tim Stoop


Kumina bv
www.kumina.nl
kvk nr 14095795




--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Bug#488275: [Pkg-samba-maint] Bug#488275: samba and winbind: initscript miss 'status' option

2008-06-30 Thread Christian Perrier
 This is my addition to the initscript for samba:


I rewrote it to fit the indentation style we use. 

I have no deep advice here, except that:

- the echo stuff add extra noise and are not handled by the LSB init
functions. Not sure whether this is wanted. Actually, the important
stuff are return codes... I'd vote to remove these echo lines.

- I haven't even checked the resulting script..:-)


--- samba.init.old  2008-06-30 19:41:19.661090174 +0200
+++ samba.init  2008-06-30 19:44:20.237089746 +0200
@@ -98,8 +98,65 @@
sleep 1
$0 start
;;
+   status)
+   SMBRETURN=3
+   NMBRETURN=3
+   PIDS_SMBD=`pidof smbd  /dev/null; echo $?`
+   PIDS_NMBD=`pidof nmbd  /dev/null; echo $?`
+   if [ $PIDS_SMBD -gt 0 ]
+   then
+   if [ -f $SMBDPID ]
+   then
+   echo smbd not running, pidfile exists!
+   SMBRETURN=1
+   else
+   echo smbd not running.
+   fi
+   else
+   if [ -f $SMBDPID ]
+   then
+   echo smbd running
+   SMBRETURN=0
+   else
+   echo smbd running, but no pidfile exists!
+   # No LSB defined return code for this :(
+   SMBRETURN=0
+   fi
+   fi
+   if [ $PIDS_NMBD -gt 0 ]
+   then
+   if [ -f $NMBDPID ]
+   then
+   echo nmbd not running, pidfile exists!
+   NMBRETURN=1
+   else
+   echo nmbd not running.
+   fi
+   else
+   if [ -f $NMBDPID ]
+   then
+   echo nmbd running
+   NMBRETURN=0
+   else
+   echo nmbd running, but no pidfile exists!
+   # No LSB defined return code for this :(
+   NMBRETURN=0
+   fi
+   fi
+   if [ $SMBRETURN -eq 1 ] || [ $SMBRETURN -eq 1 ]
+   then
+   exit 1
+   elif [ $SMBRETURN -eq $NMBRETURN ]
+   then
+   exit $SMBRETURN
+   else
+   # Apparantly, we have an unknown state, or at least 
something
+   # that we can't fix easily
+   return 4
+   fi
+   ;;
*)
-   echo Usage: /etc/init.d/samba 
{start|stop|reload|restart|force-reload}
+   echo Usage: /etc/init.d/samba 
{start|stop|reload|restart|force-reload|status}
exit 1
;;
 esac


signature.asc
Description: Digital signature


Bug#488275: [Pkg-samba-maint] Bug#488275: samba and winbind: initscript miss 'status' option

2008-06-30 Thread Tim Stoop


Op 30-jun-2008, om 19:44 heeft Christian Perrier het volgende  
geschreven:

- the echo stuff add extra noise and are not handled by the LSB init
functions. Not sure whether this is wanted. Actually, the important
stuff are return codes... I'd vote to remove these echo lines.


Although I wouldn't mind either way (the exit codes are the important  
stuff for my specific case), I added the echo's to make the status  
option is usable by humans. Also, other packages that implement an  
lsb-compatible status do this too (I checked mysql-server-5.0, nfs- 
kernel-server, nfs-common and nscd). Not sure if you'd want to follow  
their example or not :)


--
Kind regards,
Met vriendelijke groet,

Tim Stoop


Kumina bv
www.kumina.nl
kvk nr 14095795




--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Bug#488275: [Pkg-samba-maint] Bug#488275: samba and winbind: initscript miss 'status' option

2008-06-30 Thread Steve Langasek
On Mon, Jun 30, 2008 at 09:34:17AM +0200, Tim Stoop wrote:

 Op 28-jun-2008, om 15:25 heeft Christian Perrier het volgende  
 geschreven:
 I think you're very welcome to propose a patch. We'll review it
 (indeed, Steve will criticize it and I'll just look..:-)) and,
 hopefully, integrate it.

Here comes the criticism ;)

 This is my addition to the initscript for samba:

   status)
 SMBRETURN=3
 NMBRETURN=3
 PIDS_SMBD=`pidof smbd  /dev/null; echo $?`
 PIDS_NMBD=`pidof nmbd  /dev/null; echo $?`

This is wrong.  'pidof' will check for any running process under this name;
we should be looking for only those processes that are started by this init
script itself, excluding any processes that might randomly have the same
name or that are started by a user outside of this init script (e.g., a
custom set up of samba running on a different port... you'll find that
qemu does this for filesharing, though currently not very successfully on
Debian...)

So the right way to do this is to look at the PID files themselves first,
check their contents, and verify that those processes are still running. 
Something like:

  if [ ! -f $SMBDPID ]; then
  echo smbd not running.
  else
  PIDS_SMBD=`cat $SMBDPID`
  if ps $PIDS_SMBD | grep -q smbd; then
  echo smbd running.
  SMBRETURN=0
  else
  echo smbd running, but pidfile exists.
  SMBRETURN=1
  fi
  fi

Note that procps is required for this functionality to work, because of the
use of ps.  I don't know that a dependency is actually warranted, since this
is optional functionality; anyway, procps is Priority: required, so it will
always be present in practice.

I don't have a problem with the 'echo' statements myself, though I do object
to the use of exclamation marks. :)

 if [ $SMBRETURN -eq 1 ] || [ $SMBRETURN -eq 1 ]
 then
   exit 1
 elif [ $SMBRETURN -eq $NMBRETURN ]
 then
   exit $SMBRETURN
 else
   # Apparantly, we have an unknown state, or at least something
   # that we can't fix easily
   return 4
 fi
 ;;

Well, this means that no meaningful status will be returned if one of the
daemons is running but the other is not.  Concretely, this means it won't
return useful status in the event that smbd is started out of inetd
(RUN_MODE=inetd), or that 'disable netbios' is set, causing nmbd to not be
run.

 The same for winbind (much simpler):

   status)
 PIDS_WINBIND=`pidof winbindd  /dev/null; echo $?`
 if [ $PIDS_WINBIND -eq 0 ]
 then
   echo winbind is running
   exit 0
 else
   echo winbind is stopped
   exit 3
 fi
 ;;

I think it would be better to first fix winbind to use a proper PID file,
then use code similar to that in the smbd/nmbd case.

Cheers,
-- 
Steve Langasek   Give me a lever long enough and a Free OS
Debian Developer   to set it on, and I can move the world.
Ubuntu Developerhttp://www.debian.org/
[EMAIL PROTECTED] [EMAIL PROTECTED]



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Bug#488275: [Pkg-samba-maint] Bug#488275: samba and winbind: initscript miss 'status' option

2008-06-28 Thread Christian Perrier
Quoting Tim Stoop ([EMAIL PROTECTED]):

 I hope you'll see it from that point of view. If so, I created a  
 'status' function in my own samba init script. If you'd like, I can  
 post it here. It's not very good (I'm using pidof...), but it seems  
 to work and maybe can be a starting point for a proper implementation.


I think you're very welcome to propose a patch. We'll review it
(indeed, Steve will criticize it and I'll just look..:-)) and,
hopefully, integrate it.

I have to say that the possibility to have Samba failover being
supported by heartbeat is something that opens interesting
possibilities to me, for once as a user of the samba package, not as
(one of) the maintainer(s)..:-)




signature.asc
Description: Digital signature