File: systemd-service-test.sh

package info (click to toggle)
nftables 0.9.6-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 8,828 kB
  • sloc: ansic: 38,745; sh: 9,154; yacc: 4,517; python: 1,548; lex: 963; makefile: 266
file content (72 lines) | stat: -rw-r--r-- 1,459 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/sh

set -ex

SERVICE=nftables.service

# The testsuite requires kernel at least 5.x
if [ "$(uname -r | cut -d. -f1)" -lt 5 ] ; then
	: WARNING this testsuite is likely to produce many fails because of old kernel, ending now
	exit 0
fi

systemctl_call()
{
	if systemctl $1 $SERVICE ; then
		return 0
	else
		journalctl -u $SERVICE
		return 1
	fi
}

# package ships service disabled by default
if ! systemctl_call enable ; then
	: WARNING enabling the service failed
fi

if systemctl -q is-active $SERVICE ; then
	: WARNING initial service running, stopping now
	if ! systemctl_call stop ; then
		: ERROR unable to stop the initial service
		exit 1
	fi
fi

if [ $(nft list ruleset | wc -l) -ne 0 ] ; then
	: WARNING initial ruleset is not empty, flushing now
	nft flush ruleset
fi

if ! systemctl_call start ; then
	: ERROR failed to start systemd service
	exit 1
fi
if [ $(nft list ruleset | wc -l) -eq 0 ] ; then
	: ERROR no ruleset loaded after systemd service start
	exit 1
fi

systemctl_call status
nft list ruleset

if ! systemctl_call stop ; then
	: ERROR failed to stop systemd service
	exit 1
fi
if [ $(nft list ruleset | wc -l) -ne 0 ] ; then
	: ERROR ruleset still loaded after systemd service stop
	exit 1
fi

if ! systemctl_call restart ; then
	: ERROR failed to restart systemd service
	exit 1
fi
if [ $(nft list ruleset | wc -l) -eq 0 ] ; then
	: ERROR no ruleset loaded after systemd service restart
	exit 1
fi

: INFO test was OK
exit 0