Re: [Freeipa-devel] [PATCH] 519 make ipactl smarter

2010-09-07 Thread Rob Crittenden

Adam Young wrote:

On 08/31/2010 05:32 PM, Rob Crittenden wrote:

ipactl was a quickie thing I threw together at the end of v1 and it
wasn't all too bright. This tries to fix things up and work around
some init script issues.

The init scripts returns a 1 both if the service isn't running and if
it is not running but there is a pid file lying around. I check for
this and make a new return value, 4, to represent stopped.

Using this I can better tell what the current state of affairs is and
just stop/start those services that are actually running.

I added named to the list of services we track.

rob


___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Probably shouldn't be using magic constants. I'd recommend replacing
them with strings. Other than that, Ack


Well, the magic constants are the same as in initscripts and documented 
in-line so I think its probably ok. This is a pretty small script and 
nothing else uses (or probably will use) the values.


Pushed to master

rob

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel


Re: [Freeipa-devel] [PATCH] 519 make ipactl smarter

2010-09-01 Thread Adam Young

On 08/31/2010 05:32 PM, Rob Crittenden wrote:
ipactl was a quickie thing I threw together at the end of v1 and it 
wasn't all too bright. This tries to fix things up and work around 
some init script issues.


The init scripts returns a 1 both if the service isn't running and if 
it is not running but there is a pid file lying around. I check for 
this and make a new return value, 4, to represent stopped.


Using this I can better tell what the current state of affairs is and 
just stop/start those services that are actually running.


I added named to the list of services we track.

rob


___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel
Probably shouldn't be using magic constants.  I'd recommend replacing 
them with strings.  Other than that, Ack
___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

[Freeipa-devel] [PATCH] 519 make ipactl smarter

2010-08-31 Thread Rob Crittenden
ipactl was a quickie thing I threw together at the end of v1 and it 
wasn't all too bright. This tries to fix things up and work around some 
init script issues.


The init scripts returns a 1 both if the service isn't running and if it 
is not running but there is a pid file lying around. I check for this 
and make a new return value, 4, to represent stopped.


Using this I can better tell what the current state of affairs is and 
just stop/start those services that are actually running.


I added named to the list of services we track.

rob
>From 0e161ef6ef08322472dce25da9128bd234b43303 Mon Sep 17 00:00:00 2001
From: Rob Crittenden 
Date: Tue, 31 Aug 2010 17:28:41 -0400
Subject: [PATCH] Make ipactl a lot smarter and have it manage named as well.

ticket 138
---
 install/tools/ipactl |   97 -
 1 files changed, 71 insertions(+), 26 deletions(-)

diff --git a/install/tools/ipactl b/install/tools/ipactl
index e7544cf..fa86511 100755
--- a/install/tools/ipactl
+++ b/install/tools/ipactl
@@ -21,40 +21,85 @@
 # proper order
 # 
 
-function start() {
-/sbin/service dirsrv start
-/sbin/service ntpd start
-/sbin/service krb5kdc start
-/sbin/service ipa_kpasswd start
-/sbin/service httpd start
+# Set IFS so we can do space-embedded lists of services
+IFS=";"
+
+# start and stop are basically a reverse of each other
+services_stop="ipa_kpasswd;httpd;krb5kdc;dirsrv;ntpd;named;pki-cad pki-ca"
+services_start="dirsrv;ntpd;named;krb5kdc;ipa_kpasswd;httpd;pki-cad pki-ca"
+
+function is_running() {
+# $1 = service to check on
+# $2 = optional instance to check on, for dirsrv and pki-cad
 
-if [ -e /var/lib/pki-ca ]; then
-/sbin/service pki-cad start
+# Returns
+#  0 - running
+#  1 - pid but dead service
+#  2 - dead but locked subsys
+#  3 - stopped
+#  4 - no such service
+if [ "$#" = 2 ] ; then
+/sbin/service $1 status $2 > /dev/null 2>&1
+else
+out=`/sbin/service $1 status 2>&1`
 fi
+case "$?" in
+0)
+return 0;;
+1)
+x=`echo $out | grep -c exists`
+if [ $x -eq 1 ] ; then
+return 1
+else
+return 4
+fi
+;;
+2)
+return 2;;
+3)
+return 3;;
+esac
 }
 
-function stop() {
-/sbin/service ipa_kpasswd stop
-/sbin/service httpd stop
-/sbin/service krb5kdc stop
-/sbin/service dirsrv stop
-/sbin/service ntpd stop
+function start() {
+for service in $services_start ; do
+is_running $service
+case "$?" in
+0)  # running
+;;
+4)  # no such service
+;;
+*)  # otherwise not running
+/sbin/service $service start
+;;
+esac
+done
+}
 
-if [ -e /var/lib/pki-ca ]; then
-/sbin/service pki-cad stop
-fi
+function stop() {
+for service in $services_stop ; do
+is_running $service
+case "$?" in
+0)  # running
+/sbin/service $service stop
+;;
+*)  # otherwise not running or doesn't exist
+;;
+esac
+done
 }
 
 function status() {
-/sbin/service ipa_kpasswd status
-/sbin/service httpd status
-/sbin/service krb5kdc status
-/sbin/service dirsrv status
-/sbin/service ntpd status
-
-if [ -e /var/lib/pki-ca ]; then
-/sbin/service pki-cad status
-fi
+for service in $services_start ; do
+is_running $service
+case "$?" in
+4)
+;;
+*)
+/sbin/service $service status
+;;
+esac
+done
 }
 
 case "$1" in
-- 
1.7.2.1

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel