[[email protected]: minit (A Gmake-based init system) patch]

Nick Moffitt <[email protected]> Sat, 1 May 2004 12:43:21 -0700
Newsgroups gmane.linux.bbc.devel
Message-ID <[email protected]>
Sweet!  I'm encouraged that there are developers out there who take an
interest in:

	A: minit
	B: The LSB

The patch is inline because of the way mutt forwards attachments.
Nate, you may want to make your goose archive official for minit, and
push a mirror to gargoyle or something.  Just a thought.

----- Forwarded message from Claus Klein <[email protected]> -----

Hi Nate,

I am working with the GAR build system to build an linux root file system for 
an embedded ppc based board and found your minit great.

While testing the newest version minit-0.99.13 I changed a view things:

+# changelog:
+# - prevent subshells in some targets
+# - rem the pid file too if the process can't be stopped
+# - default changed from reload to: RELOAD_SCRIPTS ?= SIGHUP

and added new targets according to the spec for a LSB compatible service control script; 
see too http://www.linuxbase.org/spec/

Perhaps you will use my patch for the gar or your minit system?

PS:

To cross-compile, I had to change most gar Makefile's to at least something like that:

CONFIGURE_ARGS +=  --build=$(GARBUILD) --host=$(GARHOST)

If you want more infos or a full patch, send my a mail.


claus klein

diff --speed-large-files --minimal -Nru work/main.d/minit-0.99.13/init.mk.in Tmp/minit-0.99.13/init.mk.in
--- work/main.d/minit-0.99.13/init.mk.in	2003-03-14 14:04:05.000000000 +0100
+++ Tmp/minit-0.99.13/init.mk.in	2004-04-30 18:35:07.000000000 +0200
@@ -8,6 +8,42 @@
 # Public License (readily available).
 #
 # This is an initscript library for the LNX-BBC.
+#
+# changelog:
+# - prevent subshells in some targets
+# - rem the pid file too if the process can't be stopped
+# - default changed from reload to: RELOAD_SCRIPTS ?= SIGHUP
+# [email protected]
+#
+# spec for a LSB compatible service control script; see http://www.linuxbase.org/spec/
+
+# Note on runlevels: 
+# 0 - halt/poweroff                     6 - reboot
+# 1 - single user                       2 - multiuser without network exported
+# 3 - multiuser w/ network (text mode)  5 - multiuser w/ network and X11 (xdm)
+# 
+# Note on script names:
+# http://www.linuxbase.org/spec/refspecs/LSB_1.2.0/gLSB/scrptnames.html
+# A registry has been set up to manage the init script namespace.
+# http://www.lanana.org/
+# Please use the names already registered or register one or use a
+# vendor prefix.
+
+# Return values acc. to LSB for all commands but status:
+# 0       - success
+# 1       - generic or unspecified error
+# 2       - invalid or excess argument(s)
+# 3       - unimplemented feature (e.g. "reload")
+# 4       - user had insufficient privileges
+# 5       - program is not installed
+# 6       - program is not configured
+# 7       - program is not running
+# 8--199  - reserved (8--99 LSB, 100--149 distrib, 150--199 appl)
+# 
+# Note that starting an already running service, stopping
+# or restarting a not-running service as well as the restart
+# with force-reload (in case signaling is not supported) are
+# considered a success.
 
 prefix = @prefix@
 
@@ -26,8 +62,18 @@
 DESCRIPTION ?= No description for this script.
 
 # default rule for numbnutses
-all:
-	@echo Usage: $0 \(start\|stop\|restart\|reload\|status\|disable\|enable\|help\)
+all: help
+	@echo ; \
+	echo Usage: $(INITNAME) \(start\|stop\|restart\|try-restart\|reload\|force-reload\|status\|disable\|enable\|help\); \
+	echo ; \
+	echo start          start the service; \
+	echo stop           stop the service; \
+	echo restart        stop and restart the service if the service is already running, otherwise start the service; \
+	echo try-restart    restart the service if the service is already running; \
+	echo reload         cause the configuration of the service to be reloaded without actually stopping and restarting the service; \
+	echo force-reload   cause the configuration to be reloaded if the service supports this, otherwise restart the service if it is running; \
+	echo status         print the current status of the service; \
+	echo
 
 ##### START RULES #####
 
@@ -65,8 +111,8 @@
 	@$(TERMINA)
 
 $(RUNNINGDIR)/% $(DEPDIR)/%:
-	@mkdir -p $(DEPDIR) $(RUNNINGDIR)
-	@if test -f $(DISABLEDDIR)/$*; then \
+	@mkdir -p $(DEPDIR) $(RUNNINGDIR); \
+	if test -f $(DISABLEDDIR)/$*; then \
 		echo "Cannot start $*: service disabled" ;\
 		exit 3 ;\
 	fi ;\
@@ -92,7 +138,7 @@
 
 start-nohup:
 	@if test -x $$(which $(DAEMON)); then \
-	  nohup $(DAEMON) $(DAEMON_OPTIONS) & \
+	  nohup $(DAEMON) $(DAEMON_OPTIONS) > /dev/null 2>&1 & \
 	  pid=$$! ;\
 	else \
 	  echo "Cannot execute $(DAEMON)."; \
@@ -108,7 +154,7 @@
 announce-stop:
 	@if test -z "$(NOANNOUNCE)"; then echo -n "Stopping $(INITNAME): "; fi
 
-STOP_DEPS = $(addprefix stopdep-,$(strip $(shell if test -f $(DEPDIR)/$(INITNAME); then cat $(DEPDIR)/$(INITNAME); fi)))
+STOP_DEPS = $(addprefix stopdep-,$(strip $(shell if test -f $(DEPDIR)/$(INITNAME); then cat $(DEPDIR)/$(INITNAME) | uniq; fi)))
 STOP_TARGETS = $(addprefix stop-,$(STOP_SCRIPTS))
 
 ifdef NOSTOP
@@ -122,8 +168,8 @@
 	@$(TERMINA)
 
 stop-SIG%:
-	@if test -f $(PIDFILE) ; then kill -SIG$* $$(cat $(PIDFILE)); fi
-	@rm -f $(PIDFILE)
+	@- if test -f $(PIDFILE) ; then kill -SIG$* $$(cat $(PIDFILE)); fi; \
+	rm -f $(PIDFILE)
 
 stop-cookies:
 	@rm -f $(RUNNINGDIR)/$(INITNAME) $(DEPDIR)/$(INITNAME)
@@ -131,16 +177,24 @@
 endif
 
 ##### STATUS RULES #####
+## Check if process is running
+# Return value is slightly different for the status command:
+# 0 - service up and running
+# 1 - service dead, but /var/run/  pid  file exists
+# 2 - service dead, but /var/lock/ lock file exists
+# 3 - service not running (unused)
+# 4 - service status unknown :-(
+# 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.)
 
 announce-status:
-	@echo "Status for $(INITNAME): "
+	@echo -n "Status for $(INITNAME): "
 
 STATUS_SCRIPTS ?= $(INITNAME)
 STATUS_TARGETS = $(addprefix status-,$(STATUS_SCRIPTS))
 
 status-$(INITNAME):
-	@echo -n "$(INITNAME) is "
-	@if test -f $(DISABLEDDIR)/$(INITNAME); then \
+	@echo -n "$(INITNAME) is "; \
+	if test -f $(DISABLEDDIR)/$(INITNAME); then \
 	    echo "disabled" ;\
 	elif test -f $(RUNNINGDIR)/$(INITNAME); then \
 		echo "running" ;\
@@ -152,47 +206,71 @@
 	@$(DONADA)
 
 ##### RESTART RULES #####
+## Stop the service and regardless of whether it was
+## running or not, start it again.
 
 restart: stop start
 	@$(DONADA)
 
+## Do a restart only if the service was active before.
+try-restart:
+	@if test -f $(RUNNINGDIR)/$(INITNAME); then \
+		$(MINITDIR)/$(INITNAME) restart ;\
+	else \
+	    echo "$(INITNAME) is not running" ;\
+	fi
+	@$(DONADA)
+
 ##### RELOAD RULES #####
+## Like force-reload, but if daemon does not support
+## signaling, do nothing (!)
 
 announce-reload:
 	@echo -n "Reloading $(INITNAME): "
 
-RELOAD_SCRIPTS ?= restart
+RELOAD_SCRIPTS ?= SIGHUP
 RELOAD_TARGETS = $(addprefix reload-,$(RELOAD_SCRIPTS))
 
 reload: $(RELOAD_TARGETS)
 	@$(TERMINA)
 
 reload-restart: announce-reload restart
-	@true
+	@$(DONADA)
 
-reload-SIG%:
+reload-SIG%: announce-reload
 	@if test -f $(PIDFILE) ; then kill -SIG$* $$(cat $(PIDFILE)); fi
 
+##### FORCE-RELOAD RULES #####
+## Signal the daemon to reload its config. Most daemons
+## do this on signal 1 (SIGHUP).
+## If it does not support it, restart.
+force-reload: $(RELOAD_TARGETS)
+	@$(TERMINA)
+
 ##### ENABLE/DISABLE RULES #####
 
 announce-enable:
 	@if test -z "$(NOANNOUNCE)"; then echo -n "Enabling $(INITNAME): " ; fi
 
 enable: announce-enable
-	rm -f $(DISABLEDDIR)/$(INITNAME)
+	@rm -f $(DISABLEDDIR)/$(INITNAME); \
 	echo "$(INITNAME)"
 
 announce-disable:
 	@if test -z "$(NOANNOUNCE)"; then echo -n "Disabling $(INITNAME): " ; fi
 
 disable: stop announce-disable
-	mkdir -p $(DISABLEDDIR)
-	touch $(DISABLEDDIR)/$(INITNAME)
+	@mkdir -p $(DISABLEDDIR); \
+	touch $(DISABLEDDIR)/$(INITNAME); \
 	echo "$(INITNAME)"
 
 ##### MISC RULES #####
 
-help:
+help: 
 	echo "$(DESCRIPTION)"
 
-.PHONY: announce-start announce-stop start stop restart reload status enable disable help
+MAIN_TARGETS  := start stop restart reload status enable disable 
+PHONY_TARGETS  = all help start-nohup start-daemon force-reload try-restart
+PHONY_TARGETS += $(addprefix announce-,$(MAIN_TARGETS))
+
+.PHONY: $(MAIN_TARGETS) $(PHONY_TARGETS)
--- work/main.d/minit-0.99.13/rc.in	2003-03-14 14:32:12.000000000 +0100
+++ Tmp/minit-0.99.13/rc.in	2004-04-30 18:37:21.000000000 +0200
@@ -9,7 +9,7 @@
 # between runlevels.
 
 # Strip trailing slash from prefix (gotten via autoconf)
-prefix = $(echo @prefix@ | sed -e 's~/$~~')
+prefix=$(echo @prefix@ | sed -e 's~/$~~')
 
 test -f @localstatedir@/run/init.d/prompt-mode && MINIT_PROMPT="yes"
 


----- End forwarded message -----

-- 
Arch really is simple to use:                                Nick Moffitt
    tla register-archive http://www.lnx-bbc.org/arch        [email protected]
    tla get [email protected]/lnx-bbc--stable
See?