commit:     18bb804ba9d4daf364b9e740735b8576f6c78e76
Author:     Christian W. Zuckschwerdt <christian <AT> zuckschwerdt <DOT> org>
AuthorDate: Mon Jun 14 15:57:55 2021 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Dec  3 00:05:40 2021 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=18bb804b

net-firewall/nfacct: add init script

Closes: https://bugs.gentoo.org/796707
Signed-off-by: Christian W. Zuckschwerdt <christian <AT> zuckschwerdt.org>
Closes: https://github.com/gentoo/gentoo/pull/21237
Signed-off-by: Sam James <sam <AT> gentoo.org>

 net-firewall/nfacct/files/nfacct.confd             |  7 ++++
 net-firewall/nfacct/files/nfacct.initd             | 42 ++++++++++++++++++++++
 ...{nfacct-1.0.2.ebuild => nfacct-1.0.2-r1.ebuild} |  8 +++++
 3 files changed, 57 insertions(+)

diff --git a/net-firewall/nfacct/files/nfacct.confd 
b/net-firewall/nfacct/files/nfacct.confd
new file mode 100644
index 000000000000..b695251ebb03
--- /dev/null
+++ b/net-firewall/nfacct/files/nfacct.confd
@@ -0,0 +1,7 @@
+# /etc/conf.d/nfacct
+
+# Location for nfacct initscript to save and restore the counters
+NFACCT_SAVE="/var/lib/nfacct/counters-save"
+
+# Save counters on stopping nfacct
+SAVE_ON_STOP="yes"

diff --git a/net-firewall/nfacct/files/nfacct.initd 
b/net-firewall/nfacct/files/nfacct.initd
new file mode 100644
index 000000000000..ac5eeaa33aba
--- /dev/null
+++ b/net-firewall/nfacct/files/nfacct.initd
@@ -0,0 +1,42 @@
+#!/sbin/openrc-run
+# Copyright 1999-2021 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+extra_commands="save"
+
+NFACCT_SAVE=${NFACCT_SAVE:-/var/lib/nfacct/counters-save}
+
+depend() {
+       before iptables ip6tables
+}
+
+checkconfig() {
+       if [ ! -f "${NFACCT_SAVE}" ] ; then
+               eerror "Not starting ${SVCNAME}. First create some counters 
then run:"
+               eerror "/etc/init.d/${SVCNAME} save"
+               return 1
+       fi
+       return 0
+}
+
+start() {
+       checkconfig || return 1
+       ebegin "Loading nfacct counters"
+       nfacct restore < "${NFACCT_SAVE}"
+       eend $?
+}
+
+stop() {
+       if [ "${SAVE_ON_STOP}" = "yes" ] ; then
+               save || return 1
+       fi
+       ebegin "Removing nfacct counters"
+       nfacct flush
+       eend $?
+}
+
+save() {
+       ebegin "Saving nfacct counters"
+       nfacct list > "${NFACCT_SAVE}"
+       eend $?
+}

diff --git a/net-firewall/nfacct/nfacct-1.0.2.ebuild 
b/net-firewall/nfacct/nfacct-1.0.2-r1.ebuild
similarity index 78%
rename from net-firewall/nfacct/nfacct-1.0.2.ebuild
rename to net-firewall/nfacct/nfacct-1.0.2-r1.ebuild
index e8f02e4ce7f0..1feb53596a4b 100644
--- a/net-firewall/nfacct/nfacct-1.0.2.ebuild
+++ b/net-firewall/nfacct/nfacct-1.0.2-r1.ebuild
@@ -22,3 +22,11 @@ DEPEND="
 "
 
 CONFIG_CHECK="~NETFILTER_NETLINK_ACCT"
+
+src_install() {
+       default_src_install
+
+       keepdir /var/lib/nfacct
+       newinitd "${FILESDIR}"/${PN}.initd nfacct
+       newconfd "${FILESDIR}"/${PN}.confd nfacct
+}

Reply via email to