cron.dinstall 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. #!/bin/bash
  2. # No way I try to deal with a crippled sh just for POSIX foo.
  3. # Copyright (C) 2009-2012 Joerg Jaspert <joerg@debian.org>
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License as
  7. # published by the Free Software Foundation; version 2.
  8. #
  9. # This program is distributed in the hope that it will be useful, but
  10. # WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. # Homer: Are you saying you're never going to eat any animal again? What
  18. # about bacon?
  19. # Lisa: No.
  20. # Homer: Ham?
  21. # Lisa: No.
  22. # Homer: Pork chops?
  23. # Lisa: Dad, those all come from the same animal.
  24. # Homer: Heh heh heh. Ooh, yeah, right, Lisa. A wonderful, magical animal.
  25. # exit on errors
  26. set -e
  27. set -o pipefail
  28. # make sure to only use defined variables
  29. set -u
  30. # ERR traps should be inherited from functions too. (And command
  31. # substitutions and subshells and whatnot, but for us the functions is
  32. # the important part here)
  33. set -E
  34. # import the general variable set.
  35. export SCRIPTVARS=/srv/ftp-master.debian.org/dak/config/debian/vars
  36. . $SCRIPTVARS
  37. ########################################################################
  38. # Functions #
  39. ########################################################################
  40. # common functions are "outsourced"
  41. . "${configdir}/common"
  42. # source the dinstall functions
  43. . "${configdir}/dinstall.functions"
  44. ########################################################################
  45. ########################################################################
  46. # Function to save which stage we are in, so we can restart an interrupted
  47. # dinstall. Or even run actions in parallel, if we dare to, by simply
  48. # backgrounding the call to this function. But that should only really be
  49. # done for things we don't care much about.
  50. #
  51. # This should be called with the first argument being an array, with the
  52. # members
  53. # - FUNC - the function name to call
  54. # - ARGS - Possible arguments to hand to the function. Can be the empty string
  55. # - TIME - The timestamp name. Can be the empty string
  56. # - ERR - if this is the string false, then the call will be surrounded by
  57. # set +e ... set -e calls, so errors in the function do not exit
  58. # dinstall. Can be the empty string, meaning true.
  59. #
  60. # MAKE SURE TO KEEP THIS THE LAST FUNCTION, AFTER ALL THE VARIOUS ONES
  61. # ADDED FOR DINSTALL FEATURES!
  62. function stage() {
  63. ARGS='GO[@]'
  64. local "${!ARGS}"
  65. error=${ERR:-"true"}
  66. ARGS=${ARGS:-""}
  67. log "########## DINSTALL BEGIN: ${FUNC} ${ARGS} ##########"
  68. STAGEFILE="${stagedir}/${FUNC}_${ARGS}"
  69. STAGEFILE=${STAGEFILE// /_}
  70. if [ -f "${STAGEFILE}" ]; then
  71. stamptime=$(/usr/bin/stat -c %Z "${STAGEFILE}")
  72. unixtime=$(date +%s)
  73. difference=$(( $unixtime - $stamptime ))
  74. if [ ${difference} -ge 14400 ]; then
  75. log_error "Did already run ${FUNC}, stagefile exists, but that was ${difference} seconds ago. Please check."
  76. else
  77. log "Did already run ${FUNC}, not calling again..."
  78. fi
  79. return
  80. fi
  81. debug "Now calling function ${FUNC}. Arguments: ${ARGS}. Timestamp: ${TIME}"
  82. # Make sure we are always at the same place. If a function wants to be elsewhere,
  83. # it has to cd first!
  84. cd ${configdir}
  85. # Now redirect the output into $STAGEFILE.log. In case it errors out somewhere our
  86. # errorhandler trap can then mail the contents of $STAGEFILE.log only, instead of a whole
  87. # dinstall logfile. Short error mails ftw!
  88. exec >> "${STAGEFILE}.log" 2>&1
  89. if [ -f "${LOCK_STOP}" ]; then
  90. log "${LOCK_STOP} exists, exiting immediately"
  91. exit 42
  92. fi
  93. if [ "${error}" = "false" ]; then
  94. set +e
  95. fi
  96. ${FUNC} ${ARGS}
  97. # No matter what happened in the function, we make sure we have set -e default state back
  98. set -e
  99. # Make sure we are always at the same place.
  100. cd ${configdir}
  101. # We always use the same umask. If a function wants to do different, fine, but we reset.
  102. umask 022
  103. touch "${STAGEFILE}"
  104. if [ -n "${TIME}" ]; then
  105. ts "${TIME}"
  106. fi
  107. # And the output goes back to the normal logfile
  108. exec >> "$LOGFILE" 2>&1
  109. # Now we should make sure that we have a usable dinstall.log, so append the $STAGEFILE.log
  110. # to it.
  111. cat "${STAGEFILE}.log" >> "${LOGFILE}"
  112. rm -f "${STAGEFILE}.log"
  113. echo "########## DINSTALL END: ${FUNC} ##########"
  114. if [ -f "${LOCK_STOP}" ]; then
  115. log "${LOCK_STOP} exists, exiting immediately"
  116. exit 42
  117. fi
  118. }
  119. ########################################################################
  120. # We need logs.
  121. LOGFILE="$logdir/dinstall.log"
  122. exec >> "$LOGFILE" 2>&1
  123. # And now source our default config
  124. . "${configdir}/dinstall.variables"
  125. # Make sure we start out with a sane umask setting
  126. umask 022
  127. # And use one locale, no matter what the caller has set
  128. export LANG=C
  129. export LC_ALL=C
  130. touch "${DINSTALLSTART}"
  131. ts "startup"
  132. DINSTALLBEGIN="$(date -u +"%a %b %d %T %Z %Y (%s)")"
  133. state "Startup"
  134. lockfile -l 3600 "${LOCK_DAILY}"
  135. trap onerror ERR
  136. trap remove_daily_lock EXIT TERM HUP INT QUIT
  137. touch "${LOCK_BRITNEY}"
  138. GO=(
  139. FUNC="savetimestamp"
  140. TIME=""
  141. ARGS=""
  142. ERR="false"
  143. )
  144. stage $GO
  145. GO=(
  146. FUNC="qa1"
  147. TIME="init"
  148. ARGS=""
  149. ERR="false"
  150. )
  151. stage $GO &
  152. GO=(
  153. FUNC="pg_timestamp"
  154. TIME="pg_dump1"
  155. ARGS="predinstall"
  156. ERR=""
  157. )
  158. stage $GO
  159. GO=(
  160. FUNC="updates"
  161. TIME="External Updates"
  162. ARGS=""
  163. ERR="false"
  164. )
  165. stage $GO
  166. GO=(
  167. FUNC="i18n1"
  168. TIME="i18n 1"
  169. ARGS=""
  170. ERR="false"
  171. )
  172. stage $GO
  173. lockfile "$LOCK_ACCEPTED"
  174. trap remove_all_locks EXIT TERM HUP INT QUIT
  175. GO=(
  176. FUNC="punew"
  177. TIME="p-u-new"
  178. ARGS="stable-new"
  179. ERR="false"
  180. )
  181. stage $GO
  182. GO=(
  183. FUNC="opunew"
  184. TIME="o-p-u-new"
  185. ARGS="oldstable-new"
  186. ERR="false"
  187. )
  188. stage $GO
  189. GO=(
  190. FUNC="backports_policy"
  191. TIME="backports-policy"
  192. ARGS=""
  193. ERR="false"
  194. )
  195. stage $GO
  196. GO=(
  197. FUNC="cruft"
  198. TIME="cruft"
  199. ARGS=""
  200. ERR=""
  201. )
  202. stage $GO
  203. state "indices"
  204. GO=(
  205. FUNC="dominate"
  206. TIME="dominate"
  207. ARGS=""
  208. ERR=""
  209. )
  210. stage $GO
  211. GO=(
  212. FUNC="autocruft"
  213. TIME="autocruft"
  214. ARGS="unstable experimental"
  215. ERR=""
  216. )
  217. stage $GO
  218. GO=(
  219. FUNC="fingerprints"
  220. TIME="import-keyring"
  221. ARGS=""
  222. ERR="false"
  223. )
  224. stage $GO
  225. GO=(
  226. FUNC="overrides"
  227. TIME="overrides"
  228. ARGS=""
  229. ERR=""
  230. )
  231. stage $GO
  232. GO=(
  233. FUNC="mpfm"
  234. TIME="pkg-file-mapping"
  235. ARGS=""
  236. ERR="false"
  237. )
  238. stage $GO
  239. state "packages/contents"
  240. GO=(
  241. FUNC="packages"
  242. TIME="apt-ftparchive"
  243. ARGS=""
  244. ERR=""
  245. )
  246. stage $GO
  247. state "dists/"
  248. GO=(
  249. FUNC="pdiff"
  250. TIME="pdiff"
  251. ARGS=""
  252. ERR=""
  253. )
  254. stage $GO
  255. GO=(
  256. FUNC="gitpdiff"
  257. TIME="gitpdiff"
  258. ARGS=""
  259. ERR=""
  260. )
  261. #stage $GO
  262. GO=(
  263. FUNC="release"
  264. TIME="release files"
  265. ARGS=""
  266. ERR=""
  267. )
  268. stage $GO
  269. GO=(
  270. FUNC="dakcleanup"
  271. TIME="cleanup"
  272. ARGS=""
  273. ERR=""
  274. )
  275. stage $GO
  276. state "scripts"
  277. GO=(
  278. FUNC="mkmaintainers"
  279. TIME="mkmaintainers"
  280. ARGS=""
  281. ERR=""
  282. )
  283. stage $GO
  284. GO=(
  285. FUNC="copyoverrides"
  286. TIME="copyoverrides"
  287. ARGS=""
  288. ERR=""
  289. )
  290. stage $GO
  291. GO=(
  292. FUNC="mklslar"
  293. TIME="mklslar"
  294. ARGS=""
  295. ERR=""
  296. )
  297. stage $GO
  298. GO=(
  299. FUNC="mkfilesindices"
  300. TIME="mkfilesindices"
  301. ARGS=""
  302. ERR=""
  303. )
  304. stage $GO
  305. GO=(
  306. FUNC="mkchecksums"
  307. TIME="mkchecksums"
  308. ARGS=""
  309. ERR=""
  310. )
  311. stage $GO
  312. GO=(
  313. FUNC="mirror"
  314. TIME="mirror hardlinks"
  315. ARGS=""
  316. ERR=""
  317. )
  318. stage $GO
  319. GO=(
  320. FUNC="ddaccess"
  321. TIME="ddaccessible sync"
  322. ARGS=""
  323. ERR="false"
  324. )
  325. stage $GO
  326. remove_all_locks
  327. trap - EXIT TERM HUP INT QUIT
  328. ts "locked part finished"
  329. state "postlock"
  330. GO=(
  331. FUNC="changelogs"
  332. TIME="changelogs"
  333. ARGS=""
  334. ERR="false"
  335. )
  336. stage $GO &
  337. GO=(
  338. FUNC="pg_timestamp"
  339. TIME="pg_dump2"
  340. ARGS="postdinstall"
  341. ERR=""
  342. )
  343. stage $GO
  344. GO=(
  345. FUNC="expire"
  346. TIME="expire_dumps"
  347. ARGS=""
  348. ERR=""
  349. )
  350. stage $GO &
  351. GO=(
  352. FUNC="transitionsclean"
  353. TIME="transitionsclean"
  354. ARGS=""
  355. ERR=""
  356. )
  357. stage $GO &
  358. GO=(
  359. FUNC="dm"
  360. TIME=""
  361. ARGS=""
  362. ERR=""
  363. )
  364. stage $GO &
  365. GO=(
  366. FUNC="bts"
  367. TIME=""
  368. ARGS=""
  369. ERR="false"
  370. )
  371. stage $GO &
  372. GO=(
  373. FUNC="mirrorpush"
  374. TIME="mirrorpush"
  375. ARGS=""
  376. ERR="false"
  377. )
  378. stage $GO &
  379. GO=(
  380. FUNC="mirrorpush-backports"
  381. TIME="mirrorpush-backports"
  382. ARGS=""
  383. ERR="false"
  384. )
  385. stage $GO &
  386. GO=(
  387. FUNC="i18n2"
  388. TIME="i18n 2"
  389. ARGS=""
  390. ERR="false"
  391. )
  392. stage $GO &
  393. GO=(
  394. FUNC="stats"
  395. TIME="stats"
  396. ARGS=""
  397. ERR="false"
  398. )
  399. stage $GO &
  400. GO=(
  401. FUNC="testingsourcelist"
  402. TIME=""
  403. ARGS=""
  404. ERR="false"
  405. )
  406. stage $GO &
  407. rm -f "${LOCK_BRITNEY}"
  408. GO=(
  409. FUNC="cleantransactions"
  410. TIME=""
  411. ARGS=""
  412. ERR=""
  413. )
  414. stage $GO
  415. # we need to wait for the background processes before the end of dinstall
  416. wait
  417. log "Daily cron scripts successful, all done"
  418. exec > "$logdir/afterdinstall.log" 2>&1
  419. GO=(
  420. FUNC="renamelogfile"
  421. TIME=""
  422. ARGS=""
  423. ERR="false"
  424. )
  425. stage $GO
  426. state "all done"
  427. # Now, at the very (successful) end of dinstall, make sure we remove
  428. # our stage files, so the next dinstall run will do it all again.
  429. rm -f ${stagedir}/*
  430. touch "${DINSTALLEND}"