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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
#!/bin/sh
# report about status of build master - according to mysql database
# shellcheck source=conf/default.conf
. "${0%/*}/../conf/default.conf"
# TODO: add all (necessary) features from build-master-status
tmp_dir=$(mktemp -d 'tmp.build-master-status-from-mysql.XXXXXXXXXX' --tmpdir)
trap 'rm -rf --one-file-system "${tmp_dir}"' EXIT
# do not block if locked
exec 9> "${sanity_check_lock_file}"
if ! flock -n 9; then
>&2 echo 'Mysql-Sanity check skipped, cannot acquire lock.'
exit
fi
# shellcheck disable=SC2119
mysql_cleanup
# shellcheck disable=SC2016
{
printf 'SELECT DISTINCT `package_sources`.`pkgbase`,`package_sources`.`git_revision`,`package_sources`.`mod_git_revision`,`upstream_repositories`.`name`'
printf ' FROM `package_sources`'
mysql_join_package_sources_upstream_repositories
mysql_join_package_sources_build_assignments
mysql_join_build_assignments_binary_packages
mysql_join_binary_packages_repositories
printf ' WHERE `repositories`.`name`="build-list"'
} | \
mysql_run_query | \
tr '\t' ' ' | \
sort > \
"${tmp_dir}/build-list.mysql"
sort "${work_dir}/build-list" > \
"${tmp_dir}/build-list.file"
# shellcheck disable=SC2016
{
printf 'SELECT DISTINCT `package_sources`.`pkgbase`'
printf ' FROM `package_sources`'
mysql_join_package_sources_build_assignments
mysql_join_build_assignments_binary_packages
mysql_join_binary_packages_repositories
printf ' WHERE `repositories`.`name`="deletion-list"'
printf ' OR `binary_packages`.`is_to_be_deleted`;\n'
} | \
mysql_run_query | \
sort > \
"${tmp_dir}/deletion-list.mysql"
sort "${work_dir}/deletion-list" > \
"${tmp_dir}/deletion-list.file"
{
mysql_sanity_check || true
diff -u \
"${tmp_dir}/build-list.file" \
"${tmp_dir}/build-list.mysql" || \
true
diff -u \
"${tmp_dir}/deletion-list.file" \
"${tmp_dir}/deletion-list.mysql" || \
true
} | \
sed '
s,^-.*$,<font color="#FF0000">\0</font>,
s,^+.*$,<font color="#00FF00">\0</font>,
s/$/<br>/
1 i <html><head><title>sanity of the buildmaster'"'"'s mysql database</title></head><body>
$ a </body></html>
' | \
sponge "${webserver_directory}/mysql-sanity.html"
if [ -s "${webserver_directory}/mysql-sanity.html" ] && \
[ ! -s "${work_dir}/build-master-sanity" ]; then
printf 'girls, my database is dirty again ...\n' | \
irc_say
echo 'build master is insane' > \
"${work_dir}/build-master-sanity"
fi
if [ ! -s "${work_dir}/build-master-sanity" ]; then
# shellcheck disable=SC2016
{
printf 'INSERT IGNORE INTO `statistics` ('
printf '`%s`,' \
'date' \
'stable_packages_count' \
'pending_tasks_count' \
'pending_packages_count' \
'staging_packages_count' \
'testing_packages_count' \
'tested_packages_count' \
'broken_tasks_count' \
'dependency_loops_count' \
'dependency_looped_tasks_count' \
'locked_tasks_count' \
'blocked_tasks_count' \
'next_tasks_count' | \
sed 's/,$//'
printf ') VALUES ('
# date
printf 'NOW(),'
# stable_packages_count
printf '(SELECT COUNT(DISTINCT `binary_packages`.`id`) FROM'
printf ' `binary_packages`'
mysql_join_binary_packages_repositories
mysql_join_repositories_repository_stabilities
printf ' WHERE `repository_stabilities`.`name`="stable"),'
# pending_tasks_count
printf '(SELECT COUNT(DISTINCT `build_assignments`.`id`) FROM'
printf ' `build_assignments`'
mysql_join_build_assignments_binary_packages
mysql_join_binary_packages_repositories
printf ' WHERE `repositories`.`name`="build-list"),'
# pending_packages_count
printf '(SELECT COUNT(DISTINCT `binary_packages`.`id`) FROM'
printf ' `binary_packages`'
mysql_join_binary_packages_repositories
printf ' WHERE `repositories`.`name`="build-list"),'
# staging_packages_count
printf '(SELECT COUNT(DISTINCT `binary_packages`.`id`) FROM'
printf ' `binary_packages`'
mysql_join_binary_packages_repositories
mysql_join_repositories_repository_stabilities
printf ' WHERE `repository_stabilities`.`name`="staging"),'
# testing_packages_count
printf '(SELECT COUNT(DISTINCT `binary_packages`.`id`) FROM'
printf ' `binary_packages`'
mysql_join_binary_packages_repositories
mysql_join_repositories_repository_stabilities
printf ' WHERE `repository_stabilities`.`name`="testing"'
printf ' AND NOT `binary_packages`.`is_tested`),'
# tested_packages_count
printf '(SELECT COUNT(DISTINCT `binary_packages`.`id`) FROM'
printf ' `binary_packages`'
mysql_join_binary_packages_repositories
mysql_join_repositories_repository_stabilities
printf ' WHERE `repository_stabilities`.`name`="testing"'
printf ' AND `binary_packages`.`is_tested`),'
# broken_tasks_count
printf '(SELECT COUNT(DISTINCT `build_assignments`.`id`) FROM'
printf ' `build_assignments`'
mysql_join_build_assignments_binary_packages
mysql_join_binary_packages_repositories
printf ' WHERE `repositories`.`name`="build-list"'
printf ' AND `build_assignments`.`is_broken`),'
# dependency_loops_count
printf '(SELECT COUNT(DISTINCT `build_dependency_loops`.`loop`) FROM'
printf ' `build_dependency_loops`),'
# dependency_looped_tasks_count
printf '(SELECT COUNT(DISTINCT `build_dependency_loops`.`build_assignment`) FROM'
printf ' `build_dependency_loops`),'
# locked_tasks_count
printf '(SELECT COUNT(DISTINCT `build_slaves`.`currently_building`) FROM'
printf ' `build_slaves`'
mysql_join_build_slaves_build_assignments
mysql_join_build_assignments_binary_packages
mysql_join_binary_packages_repositories
printf ' WHERE `repositories`.`name`="build-list"),'
# blocked_tasks_count
printf '(SELECT COUNT(DISTINCT `build_assignments`.`id`) FROM'
printf ' `build_assignments`'
mysql_join_build_assignments_binary_packages
mysql_join_binary_packages_repositories
printf ' WHERE `repositories`.`name`="build-list"'
printf ' AND `build_assignments`.`is_blocked` IS NOT NULL),'
# next_tasks_count
printf '(SELECT COUNT(DISTINCT `build_assignments`.`id`) FROM'
printf ' `build_assignments`'
mysql_join_build_assignments_binary_packages
mysql_join_binary_packages_repositories
printf ' WHERE `repositories`.`name`="build-list"'
printf ' AND NOT EXISTS ('
printf 'SELECT * FROM `dependencies`'
mysql_join_dependencies_dependency_types
printf ' AND `dependency_types`.`relevant_for_binary_packages`'
mysql_join_dependencies_install_target_providers
mysql_join_install_target_providers_binary_packages '' 'prov_bp'
mysql_join_binary_packages_repositories 'prov_bp' 'prov_r'
printf ' WHERE `prov_r`.`name`="build-list"'
printf ' AND `dependencies`.`dependent`=`binary_packages`.`id`'
printf '))'
printf ');\n'
} | \
mysql_run_query
fi
|