-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathsyno_docker_switch_logger.sh
More file actions
executable file
·77 lines (64 loc) · 1.61 KB
/
syno_docker_switch_logger.sh
File metadata and controls
executable file
·77 lines (64 loc) · 1.61 KB
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
73
74
75
76
77
#!/bin/sh
terminate() {
printf "${RED}${BOLD}%s${NC}\n" "ERROR: $1"
echo
exit 1
}
usage() {
echo "Usage: (as root) $0 [PATH_TO_DOCKERD.JSON]"
echo
echo "This script will modify the logger in the dockerd.json file to 'local'"
echo
}
readonly RED='\e[31m' # Red color
readonly NC='\e[m' # No color / reset
readonly BOLD='\e[1m' # Bold font
DOCKERD_FILE=$1
# Test if script has root privileges, exit otherwise
id=$(id -u)
if [ "${id}" -ne 0 ]; then
usage
terminate "You need to be root to run this script"
fi
# Check if the dockerd.json file path is provided as an argument
if [ -z "$1" ]; then
usage
terminate "no path to dockerd.json provided"
fi
# Check if dockerd.json file exists
if [ ! -f "${DOCKERD_FILE}" ]; then
usage
terminate "no dockerd.json found at provided location"
fi
# Output the original JSON file
echo "Original dockerd.json file:"
echo "----------------------------"
echo
jq < ${DOCKERD_FILE}
echo
# Use jq to safely update the log-driver and merge new log-opts
# add iptables=true
#jq '
# .["group"] = "administrators" |
# .["log-driver"] = "local" |
# .["log-opts"] = {
# "max-file": "5",
# "max-size": "20m"
# } |
# .["iptables"] = true
#' "$DOCKERD_FILE" > "$DOCKERD_FILE.tmp" && mv "$DOCKERD_FILE.tmp" "$DOCKERD_FILE"
jq '
.["group"] = "administrators" |
.["log-driver"] = "local" |
.["log-opts"] = {
"max-file": "5",
"max-size": "20m"
}
' "$DOCKERD_FILE" > "$DOCKERD_FILE.tmp" && mv "$DOCKERD_FILE.tmp" "$DOCKERD_FILE"
# Output the new JSON file
echo "Updated dockerd.json file:"
echo "----------------------------"
echo
jq < ${DOCKERD_FILE}
echo
exit 0