File tree 3 files changed +67
-4
lines changed
base/data/docker-entrypoint.d
prod/data/docker-entrypoint.d
3 files changed +67
-4
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ set -o pipefail
13
13
# ## Log to stdout/stderr
14
14
# ##
15
15
log () {
16
+ set -o noglob # prevent message from being expanded
17
+
16
18
local type=" ${1} " # ok, warn or err
17
19
local message=" ${2} " # msg to print
18
20
local debug=" ${3} " # 0: only warn and error, >0: ok and info
@@ -38,7 +40,10 @@ log() {
38
40
else
39
41
printf " ${clr_err} [???] %s${clr_rst} \n" " ${message} " 1>&2 # stdout -> stderr
40
42
fi
43
+
44
+ set +o noglob
41
45
}
46
+ export -f log
42
47
43
48
44
49
# ##
@@ -57,7 +62,7 @@ run() {
57
62
fi
58
63
/bin/sh -c " LANG=C LC_ALL=C ${cmd} "
59
64
}
60
-
65
+ export -f run
61
66
62
67
# ##
63
68
# ## Is argument a positive integer?
@@ -73,7 +78,7 @@ isint() {
73
78
env_set () {
74
79
printenv " ${1} " > /dev/null 2>&1
75
80
}
76
-
81
+ export -f env_set
77
82
78
83
# ##
79
84
# ## Get env variable by name
@@ -91,6 +96,7 @@ env_get() {
91
96
# Just output the env value
92
97
printenv " ${1} "
93
98
}
99
+ export -f env_get
94
100
95
101
96
102
# ###########################################################
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+
3
+ set -e
4
+ set -u
5
+ set -o pipefail
6
+
7
+
8
+ # ##########################################################
9
+ # Functions
10
+ # ###########################################################
11
+
12
+ # add line to devilbox's crontab, if not already there
13
+ # and start cron service
14
+ cron_add () {
15
+ # save the entire line in one variable
16
+ line=" $* "
17
+
18
+ DEBUG_LEVEL=" $( env_get " DEBUG_ENTRYPOINT" " 0" ) "
19
+
20
+ # check if line already exists in crontab
21
+ crontab -l -u devilbox | grep " $line " > /dev/null
22
+ status=$?
23
+
24
+ if [ $status -ne 0 ]
25
+ then
26
+ log " info" " cron: adding line '${line} ' ..." " $DEBUG_LEVEL "
27
+ (crontab -l -u devilbox; echo " $line " ; ) | crontab -u devilbox -
28
+ fi
29
+
30
+ # make sure the cron service is running
31
+ if ! service cron status > /dev/null
32
+ then
33
+ service cron start
34
+ fi
35
+ }
36
+ export -f cron_add
37
+
38
+ cron_remove () {
39
+ # save the entire line in one variable
40
+ line=$*
41
+
42
+ DEBUG_LEVEL=" $( env_get " DEBUG_ENTRYPOINT" " 0" ) "
43
+
44
+ # check if line already exists in crontab
45
+ crontab -l -u devilbox | grep " $line " > /dev/null
46
+ status=$?
47
+
48
+ if [ $status -eq 0 ]; then
49
+ log " info" " cron: removing line '${line} ' ..." " $DEBUG_LEVEL "
50
+ (crontab -l -u devilbox | grep -v " $line " ; ) | crontab -u devilbox -
51
+ fi
52
+ }
53
+ export -f cron_remove
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ set -o pipefail
10
10
# ###########################################################
11
11
12
12
# ##
13
- # ## Execute custom uesr -supplied scripts
13
+ # ## Execute custom user -supplied scripts
14
14
# ##
15
15
execute_custom_scripts () {
16
16
local script_dir=" ${1} "
@@ -27,7 +27,7 @@ execute_custom_scripts() {
27
27
for script_f in ${script_files} ; do
28
28
script_name=" $( basename " ${script_f} " ) "
29
29
log " info" " Executing custom startup script: ${script_name} " " ${debug} "
30
- if ! bash " ${script_f} " ; then
30
+ if ! bash " ${script_f} " " ${debug} " ; then
31
31
log " err" " Failed to execute script" " ${debug} "
32
32
exit 1
33
33
fi
@@ -43,6 +43,10 @@ if ! command -v find >/dev/null 2>&1; then
43
43
echo " find not found, but required."
44
44
exit 1
45
45
fi
46
+ if ! command -v sort > /dev/null 2>&1 ; then
47
+ echo " sort not found, but required."
48
+ exit 1
49
+ fi
46
50
if ! command -v basename > /dev/null 2>&1 ; then
47
51
echo " basename not found, but required."
48
52
exit 1
You can’t perform that action at this time.
0 commit comments