Skip to content

Commit 329880f

Browse files
Configure culling before enabling cachefilesd
The nocull option needs to be set before the cachefilesd service is enabled. Move the configure-culling step to before creating the cache. Defer starting the custom culling service until after cachefilesd has been started to ensure the cache's directory structure has been created. Change-Id: Ib06dfa81dbaf282381e41c748e371e3ce3b957fa
1 parent 77b7a87 commit 329880f

File tree

3 files changed

+50
-17
lines changed

3 files changed

+50
-17
lines changed

deployment/terraform-module-knfsd/resources/proxy-startup.sh

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ function create-fs-cache() {
278278
else
279279
echo "Persistent Disk is already formatted."
280280
fi
281-
281+
282282
echo "Mounting /dev/disk/by-id/google-pd-fscache to FS-Cache directory (/var/cache/fscache)..."
283283
mount -o discard,defaults /dev/disk/by-id/google-pd-fscache /var/cache/fscache
284284
echo "Finished mounting /dev/disk/by-id/google-pd-fscache to FS-Cache directory (/var/cache/fscache)"
@@ -352,7 +352,7 @@ function start-fs-cache() {
352352

353353
MOUNT_OPTIONS="${MOUNT_OPTIONS},fsc"
354354
echo "FS-Cache started."
355-
355+
356356
}
357357

358358
function export-map() {
@@ -453,23 +453,16 @@ function configure-culling() (
453453
}
454454

455455
sed -i '/^nocull/d' /etc/cachefilesd.conf
456-
457456
if [[ "$CULLING" == "none" ]] || [[ "$CULLING" == "custom" ]]; then
458457
echo "nocull" >>/etc/cachefilesd.conf
459458
fi
460459

460+
: >/etc/knfsd-cull.conf
461461
if [[ "$CULLING" == "custom" ]]; then
462-
: >/etc/knfsd-cull.conf
463462
fmt last-access "$CULLING_LAST_ACCESS" >>/etc/knfsd-cull.conf
464463
fmt threshold "$CULLING_THRESHOLD" >>/etc/knfsd-cull.conf
465464
fmt interval "$CULLING_INTERVAL" >>/etc/knfsd-cull.conf
466465
fmt quiet-period "$CULLING_QUIET_PERIOD" >>/etc/knfsd-cull.conf
467-
468-
echo "Starting Custom Culling Agent..."
469-
start-services knfsd-cull
470-
echo "Finished starting Custom Culling Agent."
471-
else
472-
echo "Custom Culling Agent disabled. Skipping..."
473466
fi
474467
)
475468

@@ -509,6 +502,14 @@ function start-nfs() {
509502
echo "Knfsd Agent disabled. Skipping..."
510503
fi
511504

505+
if [[ "$CULLING" == "custom" ]]; then
506+
echo "Starting Custom Culling Agent..."
507+
start-services knfsd-cull
508+
echo "Finished starting Custom Culling Agent."
509+
else
510+
echo "Custom Culling Agent disabled. Skipping..."
511+
fi
512+
512513
# Start NFS Server
513514
echo "Starting nfs-kernel-server..."
514515
start-services portmap nfs-kernel-server
@@ -541,6 +542,9 @@ function cleanup() {
541542

542543
function main() {
543544
init
545+
546+
# culling needs to be configured before cachefilesd is started
547+
configure-culling
544548
create-fs-cache
545549

546550
echo "Mount options : ${MOUNT_OPTIONS}"
@@ -552,7 +556,6 @@ function main() {
552556

553557
configure-read-ahead
554558
configure-nfs
555-
configure-culling
556559
configure-metrics
557560

558561
start-nfs

deployment/terraform-module-knfsd/resources/tests/configure-culling.bats

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ function assert_nocull() {
4545
run configure-culling
4646
assert_success
4747
assert_nocull
48-
49-
# check no services were started
50-
assert_equal "$(cat /tmp/systemctl)" ""
5148
}
5249

5350
@test "culling custom sets nocull" {
@@ -57,9 +54,6 @@ function assert_nocull() {
5754
assert_success
5855
assert_nocull
5956

60-
# check custom culling agent started
61-
assert_equal "$(cat /tmp/systemctl)" "start knfsd-cull"
62-
6357
# run a second time to check it doesn't add a duplicate nocull
6458
run configure-culling
6559
assert_success
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
function setup() {
2+
source /opt/bats/lib/bats-support/load.bash
3+
source /opt/bats/lib/bats-assert/load.bash
4+
load ./common.bash
5+
load ../proxy-startup.sh
6+
7+
cp "$BATS_TEST_DIRNAME"/cachefilesd.conf.example /etc/cachefilesd.conf
8+
}
9+
10+
@test start_basic {
11+
run start-nfs
12+
assert_success
13+
assert_equal "$(cat /tmp/systemctl)" "start portmap nfs-kernel-server"
14+
}
15+
16+
@test start_with_agent {
17+
ENABLE_KNFSD_AGENT=true
18+
run start-nfs
19+
assert_success
20+
assert_equal "$(cat /tmp/systemctl)" "$(cat <<-EOT
21+
start knfsd-agent
22+
start portmap nfs-kernel-server
23+
EOT
24+
)"
25+
}
26+
27+
@test start_with_custom_culling {
28+
CULLING=custom
29+
run start-nfs
30+
assert_success
31+
assert_equal "$(cat /tmp/systemctl)" "$(cat <<-EOT
32+
start knfsd-cull
33+
start portmap nfs-kernel-server
34+
EOT
35+
)"
36+
}

0 commit comments

Comments
 (0)