if sed \
-e 's#[@]localstatedir_POST@#$(localstatedir)#g' \
-e 's#[@]sbindir_POST@#$(sbindir)#g' \
+ -e 's#[@]sysconfdir_POST@#$(sysconfdir)#g' \
$< > $@.tmp; then \
mv "$@.tmp" "$@"; \
else \
if [[ ${PV} == "9999" ]] ; then
EGIT_REPO_URI="git://github.com/firehol/${PN}.git"
- EGIT_BRANCH="master"
inherit git-r3 autotools
SRC_URI=""
KEYWORDS=""
else
SRC_URI="http://firehol.org/download/${PN}/releases/v${PV}/${P}.tar.xz"
+ KEYWORDS="~amd64 ~x86"
fi
-DESCRIPTION="Linux real time system monitoring, over the web!"
-HOMEPAGE="https://github.com/firehol/netdata"
+DESCRIPTION="Linux real time system monitoring, done right!"
+HOMEPAGE="https://github.com/firehol/netdata http://netdata.firehol.org/"
-LICENSE="GPL-3+"
+LICENSE="GPL-3+ MIT BSD"
SLOT="0"
-KEYWORDS="~amd64 ~x86"
-IUSE="+zlib nfacct nodejs"
+IUSE="+compression nfacct nodejs"
# most unconditional dependencies are for plugins.d/charts.d.plugin:
-RDEPEND=">=app-shells/bash-4
- sys-apps/sed
- sys-apps/grep
- virtual/awk
+RDEPEND="
+ >=app-shells/bash-4:0
net-misc/curl
net-misc/wget
-
- zlib? ( sys-libs/zlib )
-
+ virtual/awk
+ compression? ( sys-libs/zlib )
nfacct? (
net-firewall/nfacct
net-libs/libmnl
)
-
nodejs? (
net-libs/nodejs
)"
~KSM
"
+: ${NETDATA_USER:=netdata}
+
pkg_setup() {
linux-info_pkg_setup
enewuser ${PN} -1 -1 / ${PN}
}
-src_unpack() {
- if [[ ${PV} == "9999" ]] ; then
- git-r3_src_unpack
- fi
- default
-}
-
src_prepare() {
- if [[ ${PV} == "9999" ]] ; then
- eautoreconf
- fi
default
+ [[ ${PV} == "9999" ]] && eautoreconf
}
src_configure() {
econf \
--localstatedir=/var \
+ --with-user=${NETDATA_USER} \
$(use_enable nfacct plugin-nfacct) \
- $(use_with zlib) \
- --with-user=${PN} \
- || die "configure failed"
+ $(use_with compression zlib)
}
src_install() {
default
- fowners ${PN} /var/log/netdata
+ fowners ${NETDATA_USER} /var/log/netdata
+
+ chown -Rc ${NETDATA_USER} "${ED}"/usr/share/${PN} || die
+
+ cat >> "${T}"/${PN}-sysctl <<- EOF
+ kernel.mm.ksm.run = 1
+ kernel.mm.ksm.sleep_millisecs = 1000
+ EOF
+
+ dodoc "${T}"/${PN}-sysctl
newinitd system/netdata-openrc ${PN}
systemd_dounit system/netdata.service
}
+
+pkg_postinst() {
+ if [[ -e "/sys/kernel/mm/ksm/run" ]]; then
+ elog "INFORMATION:"
+ echo ""
+ elog "I see you have kernel memory de-duper (called Kernel Same-page Merging,"
+ elog "or KSM) available, but it is not currently enabled."
+ echo ""
+ elog "To enable it run:"
+ echo ""
+ elog "echo 1 >/sys/kernel/mm/ksm/run"
+ elog "echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs"
+ echo ""
+ elog "If you enable it, you will save 20-60% of netdata memory."
+ else
+ elog "INFORMATION:"
+ echo ""
+ elog "I see you do not have kernel memory de-duper (called Kernel Same-page"
+ elog "Merging, or KSM) available."
+ echo ""
+ elog "To enable it, you need a kernel built with CONFIG_KSM=y"
+ echo ""
+ elog "If you can have it, you will save 20-60% of netdata memory."
+ fi
+
+}
#
MAINTAINERCLEANFILES= $(srcdir)/Makefile.in
CLEANFILES = \
+ netdata-openrc \
netdata.service \
$(NULL)
SUFFIXES = .in
nodist_noinst_DATA = \
+ netdata-openrc \
netdata.service \
$(NULL)
dist_noinst_DATA = \
- netdata-openrc \
+ netdata-openrc.in \
netdata.service.in \
$(NULL)
+++ /dev/null
-#!/sbin/runscript
-
-# The path netdata has been installed.
-# Leave it empty if netdata is installed in /
-NETDATA_INSTALL_PATH=${NETDATA_INSTALL_PATH-}
-
-# The user netdata is configured to run as.
-# If you edit its configuration file to set a different
-# user, set it here too, to have its files switch ownership
-NETDATA_OWNER=${NETDATA_OWNER-netdata:netdata}
-
-# The URL to download netdata config.
-NETDATA_CONFIG_URL=${NETDATA_CONFIG_URL-http://localhost:19999/netdata.conf}
-
-# The timeout in seconds to wait for netdata
-# to save its database on disk and exit.
-NETDATA_WAIT_EXIT_TIMEOUT=${NETDATA_WAIT_EXIT_TIMEOUT-15}
-
-# When set to 1, if netdata does not exit in
-# NETDATA_WAIT_EXIT_TIMEOUT, we will force it
-# to exit.
-NETDATA_FORCE_EXIT=${NETDATA_FORCE_EXIT-0}
-
-# Netdata will use these services, only if they
-# are enabled to start.
-NETDATA_START_AFTER_SERVICES="${NETDATA_START_AFTER_SERVICES-apache2 squid nginx mysql named opensips upsd hostapd postfix lm_sensors}"
-
-extra_started_commands="getconf"
-pidfile="/var/run/netdata/netdata.pid"
-command="${NETDATA_INSTALL_PATH}/usr/sbin/netdata"
-command_background="yes"
-
-depend() {
- use logger
- need net
-
- local x
- for x in ${NETDATA_START_AFTER_SERVICES}
- do
- if [ -f /etc/runlevels/default/${x} ]
- then
- use ${x}
- fi
- done
-}
-
-start() {
- local ret
-
- if [ ! -d ${NETDATA_INSTALL_PATH}/var/cache/netdata ]
- then
- ebegin "Creating ${NETDATA_INSTALL_PATH}/var/cache/netdata"
- mkdir -p ${NETDATA_INSTALL_PATH}/var/cache/netdata
- chown ${NETDATA_OWNER} ${NETDATA_INSTALL_PATH}/var/cache/netdata
- echo "${NETDATA_OWNER}" >${NETDATA_INSTALL_PATH}/var/cache/netdata/.last_owner
- eend $?
- fi
-
- if [ "$(cat ${NETDATA_INSTALL_PATH}/var/cache/netdata/.last_owner 2>/dev/null)" != "${NETDATA_OWNER}" ]
- then
- ebegin "Switching ownership of ${NETDATA_INSTALL_PATH}/var/cache/netdata"
- chown -R ${NETDATA_OWNER} ${NETDATA_INSTALL_PATH}/var/cache/netdata
- echo "${NETDATA_OWNER}" >${NETDATA_INSTALL_PATH}/var/cache/netdata/.last_owner
- eend 0
- fi
-
- ebegin "Starting netdata"
- start-stop-daemon --start --quiet --pidfile ${pidfile} --exec ${command} -- ${NETDATA_EXTRA_ARGS}
- ret=$?
- eend $ret
-
- if [ $ret -eq 0 -a ! -f ${NETDATA_INSTALL_PATH}/etc/netdata/netdata.conf ]
- then
- ebegin "Downloading default configuration to ${NETDATA_INSTALL_PATH}/etc/netdata/netdata.conf"
- sleep 2
- curl -s -o ${NETDATA_INSTALL_PATH}/etc/netdata/netdata.conf.new "${NETDATA_CONFIG_URL}"
- ret=$?
- if [ $ret -eq 0 -a -s ${NETDATA_INSTALL_PATH}/etc/netdata/netdata.conf.new ]
- then
- mv ${NETDATA_INSTALL_PATH}/etc/netdata/netdata.conf.new ${NETDATA_INSTALL_PATH}/etc/netdata/netdata.conf
- else
- ret=1
- rm ${NETDATA_INSTALL_PATH}/etc/netdata/netdata.conf.new 2>/dev/null
- fi
- eend $ret
- fi
-}
-
-stop() {
- local result ret=0 count=0 sigkill=0
-
- ebegin "Stopping netdata"
- start-stop-daemon --stop --quiet --pidfile ${pidfile}
- result=$?
- eend $result
-
- ebegin "Waiting for netdata to save its database"
- while [ -f "${pidfile}" ]
- do
- if [ $count -gt ${NETDATA_WAIT_EXIT_TIMEOUT} ]
- then
- sigkill=1
- break
- fi
-
- count=$[count + 1]
- kill -0 $(cat ${pidfile}) 2>/dev/null
- ret=$?
- test $ret -eq 0 && sleep 1
- done
- eend $sigkill
-
- if [ $sigkill -eq 1 -a -f "${pidfile}" ]
- then
- ebegin "Netdata is taking too long to exit, forcing it to quit"
- kill -SIGKILL $(cat ${pidfile}) 2>/dev/null
- eend $?
- fi
-}
-
-getconf() {
- ebegin "Downloading configuration from netdata to /tmp/netdata.conf"
- curl -o /tmp/netdata.conf "${NETDATA_CONFIG_URL}"
- eend $?
-}
--- /dev/null
+#!/sbin/runscript
+
+# The user netdata is configured to run as.
+# If you edit its configuration file to set a different
+# user, set it here too, to have its files switch ownership
+: ${NETDATA_OWNER:=netdata:netdata}
+
+# The URL to download netdata config.
+: ${NETDATA_CONFIG_URL:=http://localhost:19999/netdata.conf}
+
+# The timeout in seconds to wait for netdata
+# to save its database on disk and exit.
+: ${NETDATA_WAIT_EXIT_TIMEOUT:=15}
+
+# When set to 1, if netdata does not exit in
+# NETDATA_WAIT_EXIT_TIMEOUT, we will force it
+# to exit.
+: ${NETDATA_FORCE_EXIT:=0}
+
+# Netdata will use these services, only if they
+# are enabled to start.
+: ${NETDATA_START_AFTER_SERVICES:=apache2 squid nginx mysql named opensips upsd hostapd postfix lm_sensors}
+
+extra_started_commands="getconf"
+pidfile="/run/netdata/netdata.pid"
+command="${NETDATA_INSTALL_PATH}/usr/sbin/netdata"
+command_background="yes"
+command_args="${NETDATA_EXTRA_ARGS}"
+start_stop_daemon_args="-u ${NETDATA_OWNER}"
+
+depend() {
+ use logger
+ need net
+ after ${NETDATA_START_AFTER_SERVICES}
+
+ checkpath -o ${NETDATA_OWNER} -d @localstatedir_POST@/cache/netdata /run/netdata
+}
+
+start_post() {
+ if [[ ! -f @sysconfdir_POST@/netdata/netdata.conf ]]; then
+ ebegin "Downloading default configuration to @sysconfdir_POST@/netdata/netdata.conf"
+ sleep 2
+ curl -s -o @sysconfdir_POST@/netdata/netdata.conf.new "${NETDATA_CONFIG_URL}"
+ ret=$?
+ if [[ $ret -eq 0 && -s @sysconfdir_POST@/netdata/netdata.conf.new ]]; then
+ mv @sysconfdir_POST@/netdata/netdata.conf{.new,}
+ else
+ ret=1
+ rm @sysconfdir_POST@/netdata/netdata.conf.new 2>/dev/null
+ fi
+ eend $ret
+ fi
+}
+
+stop_post() {
+ local result ret=0 count=0 sigkill=0
+
+ ebegin "Waiting for netdata to save its database"
+ while [[ -f "${pidfile}" ]]; do
+ if [[ $count -gt ${NETDATA_WAIT_EXIT_TIMEOUT} ]]; then
+ sigkill=1
+ break
+ fi
+
+ count=$[count + 1]
+ kill -0 $(cat ${pidfile}) 2>/dev/null
+ ret=$?
+ test $ret -eq 0 && sleep 1
+ done
+ eend $sigkill
+
+ if [[ $sigkill -eq 1 && -f "${pidfile}" ]]; then
+ ebegin "Netdata is taking too long to exit, forcing it to quit"
+ kill -SIGKILL $(cat ${pidfile}) 2>/dev/null
+ eend $?
+ fi
+}
+
+getconf() {
+ ebegin "Downloading configuration from netdata to /tmp/netdata.conf"
+ curl -o /tmp/netdata.conf "${NETDATA_CONFIG_URL}"
+ eend $?
+}