Skip to content

Commit bec60a7

Browse files
committed
fix: create log file if doesn't exist
1 parent e2532d8 commit bec60a7

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

src/run-cron

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ test_env=$(get_env "TEST_ENV" false)
1212

1313
echo "$cron_time backup >> /var/log/backup.log" > /etc/crontabs/root
1414

15-
if [ "$test_env" = false ]; then
16-
echo "Launching cron service..."
17-
tail -F /var/log/backup.log &
18-
exec crond -f -L /var/log/cron.log
15+
echo "Launching cron service..."
16+
17+
if [ ! -f "/var/log/backup.log" ]; then
18+
touch /var/log/backup.log
19+
fi
20+
21+
if [ "$test_env" = true ]; then
22+
timeout 1 run-cron-service
23+
else
24+
run-cron-service
1925
fi

src/run-cron-service

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
tail -F /var/log/backup.log &
6+
exec crond -f -L /var/log/cron.log

test/functional/run_cron.bats

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
@test "run-cron command runs without error" {
2+
export TEST_ENV=true
3+
4+
run run-cron
5+
[ "$status" -eq 124 ]
6+
[ "${lines[0]}" = "Launching cron service..." ]
7+
[ "${#lines[@]}" -eq 1 ]
8+
}
9+
110
@test "run-cron command creates default cron entry" {
211
export TEST_ENV=true
312

413
run run-cron
5-
[ "$status" -eq 0 ]
14+
[ "$status" -eq 124 ]
615
[ "$(cat /etc/crontabs/root)" = "0 0 * * * backup >> /var/log/backup.log" ]
716
}
817

@@ -11,7 +20,7 @@
1120
export CRON_MINUTE=12
1221

1322
run run-cron
14-
[ "$status" -eq 0 ]
23+
[ "$status" -eq 124 ]
1524
[ "$(cat /etc/crontabs/root)" = "12 0 * * * backup >> /var/log/backup.log" ]
1625
}
1726

@@ -20,7 +29,7 @@
2029
export CRON_HOUR=5
2130

2231
run run-cron
23-
[ "$status" -eq 0 ]
32+
[ "$status" -eq 124 ]
2433
[ "$(cat /etc/crontabs/root)" = "0 5 * * * backup >> /var/log/backup.log" ]
2534
}
2635

@@ -29,6 +38,6 @@
2938
export CRON_TIME="*/10 9 * * sun"
3039

3140
run run-cron
32-
[ "$status" -eq 0 ]
41+
[ "$status" -eq 124 ]
3342
[ "$(cat /etc/crontabs/root)" = "*/10 9 * * sun backup >> /var/log/backup.log" ]
3443
}

0 commit comments

Comments
 (0)