[packages/netdata] add initscripts

glen glen at pld-linux.org
Fri Apr 15 10:43:16 CEST 2016


commit 1aa35efdc94f4a95169a0d492799f8a53013efe3
Author: Elan Ruusamäe <glen at delfi.ee>
Date:   Fri Apr 15 10:46:40 2016 +0300

    add initscripts

 netdata.init    | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 netdata.service | 16 ++++++++++
 netdata.spec    | 46 +++++++++++++++++----------
 3 files changed, 143 insertions(+), 17 deletions(-)
---
diff --git a/netdata.spec b/netdata.spec
index f81e8c5..841d88b 100644
--- a/netdata.spec
+++ b/netdata.spec
@@ -1,17 +1,18 @@
 #
 # Conditional build:
-%bcond_without	systemd		# systemd
 %bcond_with	nfacct		# build with nfacct plugin
 
 Summary:	Linux real time system monitoring, over the web
 Name:		netdata
 Version:	1.0.0
-Release:	0.12
+Release:	0.15
 License:	GPL v3+
 Group:		Applications/System
 Source0:	https://github.com/firehol/netdata/archive/v%{version}/%{name}-%{version}.tar.gz
 # Source0-md5:	53a432f8849da6bd49b0853dd79551c5
 Source1:	%{name}.conf
+Source2:	%{name}.init
+Source3:	%{name}.service
 Patch0:		nodejs.patch
 URL:		http://netdata.firehol.org/
 BuildRequires:	autoconf
@@ -19,18 +20,22 @@ BuildRequires:	automake
 %{?with_nfacct:BuildRequires:	libmnl-devel}
 %{?with_nfacct:BuildRequires:	libnetfilter_acct-devel}
 BuildRequires:	pkgconfig
-BuildRequires:	rpmbuild(macros) >= 1.202
+BuildRequires:	rpmbuild(macros) >= 1.647
 BuildRequires:	zlib-devel
-Suggests:	%{name}-charts
-Suggests:	%{name}-nodejs
 Provides:	group(netdata)
 Provides:	user(netdata)
+Requires(post,preun):	/sbin/chkconfig
+Requires(post,preun,postun):	systemd-units >= 38
 Requires(postun):	/usr/sbin/groupdel
 Requires(postun):	/usr/sbin/userdel
 Requires(pre):	/bin/id
 Requires(pre):	/usr/bin/getgid
 Requires(pre):	/usr/sbin/groupadd
 Requires(pre):	/usr/sbin/useradd
+Requires:	rc-scripts
+Requires:	systemd-units >= 0.38
+Suggests:	%{name}-charts
+Suggests:	%{name}-nodejs
 BuildRoot:	%{tmpdir}/%{name}-%{version}-root-%(id -u -n)
 
 %define		_libexecdir	%{_prefix}/lib
@@ -105,42 +110,49 @@ rm -rf $RPM_BUILD_ROOT
 %{__make} install \
 	DESTDIR=$RPM_BUILD_ROOT
 
+install -d $RPM_BUILD_ROOT{/etc/rc.d/init.d,%{systemdunitdir}}
+
 cp -p %{SOURCE1} $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/%{name}.conf
+install -p %{SOURCE2} $RPM_BUILD_ROOT/etc/rc.d/init.d/%{name}
+cp -p %{SOURCE3} $RPM_BUILD_ROOT%{systemdunitdir}/%{name}.service
 
 %{__rm} $RPM_BUILD_ROOT/var/{cache,log}/netdata/.keep
 
 install -d $RPM_BUILD_ROOT%{systemdunitdir}
 cp -p system/netdata-systemd $RPM_BUILD_ROOT%{systemdunitdir}/netdata.service
 
+%clean
+rm -rf $RPM_BUILD_ROOT
+
 %pre
 %groupadd -g 329 netdata
 %useradd -u 329 -g netdata -c netdata -s /sbin/nologin -d / netdata
 
-%postun
-if [ "$1" = "0" ]; then
-	%userremove netdata
-	%groupremove netdata
-fi
-
-%if 0
 %post
+/sbin/chkconfig --add netdata
+%service netdata restart
 %systemd_post netdata.service
 
 %preun
+if [ "$1" = "0" ]; then
+	%service -q netdata stop
+	/sbin/chkconfig --del netdata
+fi
 %systemd_preun netdata.service
 
 %postun
-%systemd_postun_with_restart netdata.service
-%endif
-
-%clean
-rm -rf $RPM_BUILD_ROOT
+if [ "$1" = "0" ]; then
+	%userremove netdata
+	%groupremove netdata
+fi
+%systemd_reload
 
 %files
 %defattr(644,root,root,755)
 %dir %{_sysconfdir}/%{name}
 %config(noreplace) %verify(not md5 mtime size) %{_sysconfdir}/%{name}/apps_groups.conf
 %config(noreplace) %verify(not md5 mtime size) %{_sysconfdir}/%{name}/netdata.conf
+%attr(754,root,root) /etc/rc.d/init.d/netdata
 %attr(755,root,root) %{_sbindir}/%{name}
 %{_datadir}/%{name}
 %dir %{_libexecdir}/%{name}
diff --git a/netdata.init b/netdata.init
new file mode 100755
index 0000000..2956ac9
--- /dev/null
+++ b/netdata.init
@@ -0,0 +1,98 @@
+#!/bin/sh
+#
+# netdata	Real-time charts for system monitoring
+# chkconfig:	345 99 01
+# description:  Netdata is a daemon that collects data in realtime (per second)
+#               and presents a web site to view and analyze them. The presentation
+#               is also real-time and full of interactive charts that precisely
+#               render all collected values.
+# processname:	netdata
+#
+
+# Source function library
+. /etc/rc.d/init.d/functions
+
+# Get network config
+. /etc/sysconfig/network
+
+# 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 "Netdata Daemon"
+		exit 1
+	fi
+else
+	exit 0
+fi
+
+# Set defaults
+PIDFILE=/var/run/netdata/netdata.pid
+
+# Get service config - may override defaults
+[ -f /etc/sysconfig/netdata ] && . /etc/sysconfig/netdata
+
+start() {
+	# Check if the service is already running?
+	if [ -f /var/lock/subsys/netdata ]; then
+		msg_already_running "Netdata Daemon"
+		return
+	fi
+
+	msg_starting "Netdata Daemon"
+	daemon /usr/sbin/netdata
+	RETVAL=$?
+	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/netdata
+}
+
+stop() {
+	if [ ! -f /var/lock/subsys/netdata ]; then
+		msg_not_running "Netdata Daemon"
+		return
+	fi
+
+	# Stop daemons.
+	msg_stopping "Netdata Daemon"
+	killproc --pidfile $PIDFILE netdata -TERM
+	rm -f /var/lock/subsys/netdata
+}
+
+condrestart() {
+	if [ ! -f /var/lock/subsys/netdata ]; then
+		msg_not_running "Netdata Daemon"
+		RETVAL=$1
+		return
+	fi
+
+	stop
+	start
+}
+
+RETVAL=0
+# See how we were called.
+case "$1" in
+  start)
+	start
+	;;
+  stop)
+	stop
+	;;
+  restart)
+	stop
+	start
+	;;
+  try-restart)
+	condrestart 0
+	;;
+  force-reload)
+	condrestart 7
+	;;
+  status)
+	status --pidfile $PIDFILE netdata
+	RETVAL=$?
+	;;
+  *)
+	msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
+	exit 3
+esac
+
+exit $RETVAL
diff --git a/netdata.service b/netdata.service
new file mode 100644
index 0000000..7033cef
--- /dev/null
+++ b/netdata.service
@@ -0,0 +1,16 @@
+[Unit]
+Description=netdata
+After=network.target httpd.service squid.service nfs-server.service mysqld.service named.service postfix.service
+
+[Service]
+Type=forking
+WorkingDirectory=/tmp
+User=root
+Group=root
+PIDFile=/var/run/netdata/netdata.pid
+ExecStart=/usr/sbin/netdata
+ExecStop=/bin/kill -SIGTERM $MAINPID
+TimeoutStopSec=30
+
+[Install]
+WantedBy=multi-user.target
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/netdata.git/commitdiff/1aa35efdc94f4a95169a0d492799f8a53013efe3



More information about the pld-cvs-commit mailing list