[packages/graylog-collector-sidecar] pldize initscript

glen glen at pld-linux.org
Fri Feb 9 15:07:15 CET 2018


commit 470427d3cf0424443207773dff5a7fe64c2c8d91
Author: Elan Ruusamäe <glen at pld-linux.org>
Date:   Fri Feb 9 16:02:41 2018 +0200

    pldize initscript

 collector-sidecar.init         | 166 ++++++++++++++++++++---------------------
 graylog-collector-sidecar.spec |  20 ++++-
 2 files changed, 101 insertions(+), 85 deletions(-)
---
diff --git a/graylog-collector-sidecar.spec b/graylog-collector-sidecar.spec
index e39ba56..b1da133 100644
--- a/graylog-collector-sidecar.spec
+++ b/graylog-collector-sidecar.spec
@@ -4,14 +4,18 @@
 Summary:	Manage log collectors through Graylog
 Name:		graylog-collector-sidecar
 Version:	0.1.4
-Release:	0.3
+Release:	0.4
 License:	GPL v3
 Group:		Applications
 Source0:	https://github.com/Graylog2/collector-sidecar/releases/download/%{version}/collector-sidecar-%{version}.tar.gz
 # Source0-md5:	8728b5e9310210e91f9a1f5c46160d8d
 Source1:	collector_sidecar.yml
+Source2:	collector-sidecar.init
 URL:		https://github.com/Graylog2/collector-sidecar
+BuildRequires:	rpmbuild(macros) >= 1.228
 ExclusiveArch:	%{ix86} %{x8664}
+Requires(post,preun):	/sbin/chkconfig
+Requires:	rc-scripts
 BuildRoot:	%{tmpdir}/%{name}-%{version}-root-%(id -u -n)
 
 %description
@@ -34,16 +38,28 @@ cp -p %{SOURCE1} .
 
 %install
 rm -rf $RPM_BUILD_ROOT
-install -d $RPM_BUILD_ROOT{%{_sysconfdir}/graylog/collector-sidecar,%{_sbindir}}
+install -d $RPM_BUILD_ROOT{%{_sysconfdir}/graylog/collector-sidecar,/etc/rc.d/init.d,%{_sbindir}}
 install -p graylog-collector-sidecar $RPM_BUILD_ROOT%{_sbindir}
 cp -p collector_sidecar.yml $RPM_BUILD_ROOT%{_sysconfdir}/graylog/collector-sidecar
+install -p %{SOURCE2} $RPM_BUILD_ROOT/etc/rc.d/init.d/collector-sidecar
 
 %clean
 rm -rf $RPM_BUILD_ROOT
 
+%post
+/sbin/chkconfig --add collector-sidecar
+%service collector-sidecar restart
+
+%preun
+if [ "$1" = "0" ]; then
+	%service -q collector-sidecar stop
+	/sbin/chkconfig --del collector-sidecar
+fi
+
 %files
 %defattr(644,root,root,755)
 %dir %{_sysconfdir}/graylog
 %dir %{_sysconfdir}/graylog/collector-sidecar
 %config(noreplace) %verify(not md5 mtime size) %{_sysconfdir}/graylog/collector-sidecar/collector_sidecar.yml
+%attr(754,root,root) /etc/rc.d/init.d/collector-sidecar
 %attr(755,root,root) %{_sbindir}/graylog-collector-sidecar
diff --git a/collector-sidecar.init b/collector-sidecar.init
index 0926070..8278bbc 100755
--- a/collector-sidecar.init
+++ b/collector-sidecar.init
@@ -1,96 +1,96 @@
 #!/bin/sh
-# For RedHat and cousins:
-# chkconfig: - 99 01
+#
+# Wrapper service for Graylog controlled collector
+#
+# chkconfig:	345 99 01
 # description: Wrapper service for Graylog controlled collector
-# processname: /usr/sbin/graylog-collector-sidecar
+# processname:	graylog-collector-sidecar
+# config: /etc/graylog/collector-sidecar/collector_sidecar.yml
+# pidfile: /var/run/collector-sidecar.pid
 
-### BEGIN INIT INFO
-# Provides:          /usr/sbin/graylog-collector-sidecar
-# Required-Start:
-# Required-Stop:
-# Default-Start:     2 3 4 5
-# Default-Stop:      0 1 6
-# Short-Description: Graylog collector sidecar
-# Description:       Wrapper service for Graylog controlled collector
-### END INIT INFO
+# Source function library
+. /etc/rc.d/init.d/functions
 
-cmd="/usr/sbin/graylog-collector-sidecar"
+# Get network config
+. /etc/sysconfig/network
 
-name=$(basename $(readlink -f $0))
-pid_file="/var/run/$name.pid"
-stdout_log="/var/log/$name.log"
-stderr_log="/var/log/$name.err"
+# Check that networking is up.
+if is_yes "${NETWORKING}"; then
+	if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
+		msg_network_down "Graylog collector sidecar"
+		exit 1
+	fi
+else
+	exit 0
+fi
 
-[ -e /etc/sysconfig/$name ] && . /etc/sysconfig/$name
+# Get service config - may override defaults
+[ -f /etc/sysconfig/collector-sidecar ] && . /etc/sysconfig/collector-sidecar
 
-get_pid() {
-    cat "$pid_file"
+pidfile="/var/run/collector-sidecar.pid"
+
+start() {
+	# Check if the service is already running?
+	if [ -f /var/lock/subsys/collector-sidecar ]; then
+		msg_already_running "Graylog collector sidecar"
+		return
+	fi
+
+	msg_starting "Graylog collector sidecar"
+	daemon --fork --pidfile "$pidfile" --makepid /usr/sbin/graylog-collector-sidecar
+	RETVAL=$?
+	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/collector-sidecar
 }
 
-is_running() {
-    [ -f "$pid_file" ] && ps $(get_pid) > /dev/null 2>&1
+stop() {
+	if [ ! -f /var/lock/subsys/collector-sidecar ]; then
+		msg_not_running "Graylog collector sidecar"
+		return
+	fi
+
+	# Stop daemons.
+	msg_stopping "Graylog collector sidecar"
+	killproc --pidfile $pidfile graylog-collector-sidecar -TERM
+	rm -f /var/lock/subsys/collector-sidecar
 }
 
+condrestart() {
+	if [ ! -f /var/lock/subsys/collector-sidecar ]; then
+		msg_not_running "Graylog collector sidecar"
+		RETVAL=$1
+		return
+	fi
+
+	stop
+	start
+}
+
+RETVAL=0
+# See how we were called.
 case "$1" in
-    start)
-        if is_running; then
-            echo "Already started"
-        else
-            echo "Starting $name"
-            
-            $cmd >> "$stdout_log" 2>> "$stderr_log" &
-            echo $! > "$pid_file"
-            if ! is_running; then
-                echo "Unable to start, see $stdout_log and $stderr_log"
-                exit 1
-            fi
-        fi
-    ;;
-    stop)
-        if is_running; then
-            echo -n "Stopping $name.."
-            kill $(get_pid)
-            for i in {1..10}
-            do
-                if ! is_running; then
-                    break
-                fi
-                echo -n "."
-                sleep 1
-            done
-            echo
-            if is_running; then
-                echo "Not stopped; may still be shutting down or shutdown may have failed"
-                exit 1
-            else
-                echo "Stopped"
-                if [ -f "$pid_file" ]; then
-                    rm "$pid_file"
-                fi
-            fi
-        else
-            echo "Not running"
-        fi
-    ;;
-    restart)
-        $0 stop
-        if is_running; then
-            echo "Unable to stop, will not attempt to start"
-            exit 1
-        fi
-        $0 start
-    ;;
-    status)
-        if is_running; then
-            echo "Running"
-        else
-            echo "Stopped"
-            exit 1
-        fi
-    ;;
-    *)
-    echo "Usage: $0 {start|stop|restart|status}"
-    exit 1
-    ;;
+  start)
+	start
+	;;
+  stop)
+	stop
+	;;
+  restart)
+	stop
+	start
+	;;
+  try-restart)
+	condrestart 0
+	;;
+  force-reload)
+	condrestart 7
+	;;
+  status)
+	status --pidfile $pidfile collector-sidecar graylog-collector-sidecar
+	RETVAL=$?
+	;;
+  *)
+	msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
+	exit 3
 esac
-exit 0
+
+exit $RETVAL
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/graylog-collector-sidecar.git/commitdiff/fed25cf8d4e33ceb06c146b8511bcf43a95b8439



More information about the pld-cvs-commit mailing list