Browse code

Make the check-config script return success or failure

Although primarily a human readable script, it is quite useful
to return success or failure from this script so it can be used
as a basic test.

Fail if any check fails, including some that are optional,
other than the storage driver tests, where only one needs to
succeed, so the system has at least one workable storage driver.

Signed-off-by: Justin Cormack <justin.cormack@docker.com>

Justin Cormack authored on 2016/11/03 08:23:52
Showing 1 changed files
... ...
@@ -1,6 +1,8 @@
1 1
 #!/usr/bin/env bash
2 2
 set -e
3 3
 
4
+EXITCODE=0
5
+
4 6
 # bits of this were adapted from lxc-checkconfig
5 7
 # see also https://github.com/lxc/lxc/blob/lxc-1.0.2/src/lxc/lxc-checkconfig.in
6 8
 
... ...
@@ -90,12 +92,13 @@ check_flag() {
90 90
 		wrap_good "CONFIG_$1" 'enabled (as module)'
91 91
 	else
92 92
 		wrap_bad "CONFIG_$1" 'missing'
93
+		EXITCODE=1
93 94
 	fi
94 95
 }
95 96
 
96 97
 check_flags() {
97 98
 	for flag in "$@"; do
98
-		echo "- $(check_flag "$flag")"
99
+		echo -n "- "; check_flag "$flag"
99 100
 	done
100 101
 }
101 102
 
... ...
@@ -104,6 +107,7 @@ check_command() {
104 104
 		wrap_good "$1 command" 'available'
105 105
 	else
106 106
 		wrap_bad "$1 command" 'missing'
107
+		EXITCODE=1
107 108
 	fi
108 109
 }
109 110
 
... ...
@@ -112,6 +116,7 @@ check_device() {
112 112
 		wrap_good "$1" 'present'
113 113
 	else
114 114
 		wrap_bad "$1" 'missing'
115
+		EXITCODE=1
115 116
 	fi
116 117
 }
117 118
 
... ...
@@ -122,6 +127,7 @@ check_distro_userns() {
122 122
 		grep -q "user_namespace.enable=1" /proc/cmdline || {
123 123
 			# no user namespace support enabled
124 124
 			wrap_bad "  (RHEL7/CentOS7" "User namespaces disabled; add 'user_namespace.enable=1' to boot command line)"
125
+			EXITCODE=1
125 126
 		}
126 127
 	fi
127 128
 }
... ...
@@ -158,6 +164,7 @@ else
158 158
 	else
159 159
 		echo "$(wrap_bad 'cgroup hierarchy' 'nonexistent??')"
160 160
 	fi
161
+	EXITCODE=1
161 162
 	echo "    $(wrap_color '(see https://github.com/tianon/cgroupfs-mount)' yellow)"
162 163
 fi
163 164
 
... ...
@@ -175,6 +182,7 @@ if [ "$(cat /sys/module/apparmor/parameters/enabled 2>/dev/null)" = 'Y' ]; then
175 175
 		else
176 176
 			echo "$(wrap_color '(look for an "apparmor" package for your distribution)')"
177 177
 		fi
178
+		EXITCODE=1
178 179
 	fi
179 180
 fi
180 181
 
... ...
@@ -255,41 +263,56 @@ if ! is_set EXT4_FS || ! is_set EXT4_FS_POSIX_ACL || ! is_set EXT4_FS_SECURITY;
255 255
 fi
256 256
 
257 257
 echo '- Network Drivers:'
258
-{
259
-	echo '- "'$(wrap_color 'overlay' blue)'":'
260
-	check_flags VXLAN | sed 's/^/  /'
261
-	echo '    Optional (for encrypted networks):'
262
-	check_flags CRYPTO CRYPTO_AEAD CRYPTO_GCM CRYPTO_SEQIV CRYPTO_GHASH \
263
-	            XFRM XFRM_USER XFRM_ALGO INET_ESP INET_XFRM_MODE_TRANSPORT | sed 's/^/    /'
264
-	echo '- "'$(wrap_color 'ipvlan' blue)'":'
265
-	check_flags IPVLAN | sed 's/^/  /'
266
-	echo '- "'$(wrap_color 'macvlan' blue)'":'
267
-	check_flags MACVLAN DUMMY | sed 's/^/  /'
268
-} | sed 's/^/  /'
258
+echo '  - "'$(wrap_color 'overlay' blue)'":'
259
+check_flags VXLAN | sed 's/^/    /'
260
+echo '      Optional (for encrypted networks):'
261
+check_flags CRYPTO CRYPTO_AEAD CRYPTO_GCM CRYPTO_SEQIV CRYPTO_GHASH \
262
+            XFRM XFRM_USER XFRM_ALGO INET_ESP INET_XFRM_MODE_TRANSPORT | sed 's/^/      /'
263
+echo '  - "'$(wrap_color 'ipvlan' blue)'":'
264
+check_flags IPVLAN | sed 's/^/    /'
265
+echo '  - "'$(wrap_color 'macvlan' blue)'":'
266
+check_flags MACVLAN DUMMY | sed 's/^/    /'
267
+
268
+# only fail if no storage drivers available
269
+CODE=${EXITCODE}
270
+EXITCODE=0
271
+STORAGE=1
269 272
 
270 273
 echo '- Storage Drivers:'
271
-{
272
-	echo '- "'$(wrap_color 'aufs' blue)'":'
273
-	check_flags AUFS_FS | sed 's/^/  /'
274
-	if ! is_set AUFS_FS && grep -q aufs /proc/filesystems; then
275
-		echo "    $(wrap_color '(note that some kernels include AUFS patches but not the AUFS_FS flag)' bold black)"
276
-	fi
277
-
278
-	echo '- "'$(wrap_color 'btrfs' blue)'":'
279
-	check_flags BTRFS_FS | sed 's/^/  /'
280
-	check_flags BTRFS_FS_POSIX_ACL | sed 's/^/  /'
281
-
282
-	echo '- "'$(wrap_color 'devicemapper' blue)'":'
283
-	check_flags BLK_DEV_DM DM_THIN_PROVISIONING | sed 's/^/  /'
284
-
285
-	echo '- "'$(wrap_color 'overlay' blue)'":'
286
-	check_flags OVERLAY_FS | sed 's/^/  /'
274
+echo '  - "'$(wrap_color 'aufs' blue)'":'
275
+check_flags AUFS_FS | sed 's/^/    /'
276
+if ! is_set AUFS_FS && grep -q aufs /proc/filesystems; then
277
+	echo "      $(wrap_color '(note that some kernels include AUFS patches but not the AUFS_FS flag)' bold black)"
278
+fi
279
+[ "$EXITCODE" = 0 ] && STORAGE=0
280
+EXITCODE=0
281
+
282
+echo '  - "'$(wrap_color 'btrfs' blue)'":'
283
+check_flags BTRFS_FS | sed 's/^/    /'
284
+check_flags BTRFS_FS_POSIX_ACL | sed 's/^/    /'
285
+[ "$EXITCODE" = 0 ] && STORAGE=0
286
+EXITCODE=0
287
+
288
+echo '  - "'$(wrap_color 'devicemapper' blue)'":'
289
+check_flags BLK_DEV_DM DM_THIN_PROVISIONING | sed 's/^/    /'
290
+[ "$EXITCODE" = 0 ] && STORAGE=0
291
+EXITCODE=0
292
+
293
+echo '  - "'$(wrap_color 'overlay' blue)'":'
294
+check_flags OVERLAY_FS | sed 's/^/    /'
295
+[ "$EXITCODE" = 0 ] && STORAGE=0
296
+EXITCODE=0
297
+
298
+echo '  - "'$(wrap_color 'zfs' blue)'":'
299
+echo -n "    - "; check_device /dev/zfs
300
+echo -n "    - "; check_command zfs
301
+echo -n "    - "; check_command zpool
302
+[ "$EXITCODE" = 0 ] && STORAGE=0
303
+EXITCODE=0
304
+
305
+EXITCODE=$CODE
306
+[ "$STORAGE" = 1 ] && EXITCODE=1
287 307
 
288
-	echo '- "'$(wrap_color 'zfs' blue)'":'
289
-	echo "  - $(check_device /dev/zfs)"
290
-	echo "  - $(check_command zfs)"
291
-	echo "  - $(check_command zpool)"
292
-} | sed 's/^/  /'
293 308
 echo
294 309
 
295 310
 check_limit_over()
... ...
@@ -297,6 +320,7 @@ check_limit_over()
297 297
 	if [ $(cat "$1") -le "$2" ]; then
298 298
 		wrap_bad "- $1" "$(cat $1)"
299 299
 		wrap_color "    This should be set to at least $2, for example set: sysctl -w kernel/keys/root_maxkeys=1000000" bold black
300
+		EXITCODE=1
300 301
 	else
301 302
 		wrap_good "- $1" "$(cat $1)"
302 303
 	fi
... ...
@@ -305,3 +329,5 @@ check_limit_over()
305 305
 echo 'Limits:'
306 306
 check_limit_over /proc/sys/kernel/keys/root_maxkeys 10000
307 307
 echo
308
+
309
+exit $EXITCODE