Run 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. #!/bin/bash
  2. # script to set up individual rendering server
  3. LicensesDirectory=XML-Licenses
  4. ERROR()
  5. {
  6. echo error: $*
  7. exit 1
  8. }
  9. USAGE()
  10. {
  11. [ -z "$1" ] || echo error: "$*"
  12. echo usage: $(basename "$0") '<options>'
  13. echo ' --help -h this message'
  14. echo ' --verbose -v more messages'
  15. echo ' --get-index=n -g <n> where to rsync the indices from {1 => render1}'
  16. echo ' --index-only -i only do the index'
  17. echo ' --no-run -n do not run final make'
  18. echo ' --clear -c clear work and dest dirs'
  19. echo ' --re-parse -R clear parse and render stamps'
  20. echo ' --re-render -r clear render stamps'
  21. echo ' --machines=m -m <m> set machine count [${MACHINE_COUNT} or 9]'
  22. echo ' --parallel=n -j <n> set make -j value [${PARALLEL_BUILD} or 3]'
  23. echo ' --language=xx -l <xx> set language [en]'
  24. echo ' --suffix=<s> -s <s> set the directory suffix [pedia]'
  25. echo ' --prefix=name -p <name> set data file prefix [wiki]'
  26. echo ' --work=dir -w <dir> workdir [work]'
  27. echo ' --dest=dir -d <dir> destdir [image]'
  28. echo ' --temp=dir -t <dir> tempdir [/tmp]'
  29. echo ' --farm=n -f <n> manual farm number [from hostname numeric suffix]'
  30. echo ' --compress=<c> -C <c> set compression {low/high} [low]'
  31. echo ' --debug -D print but do not execute make commands'
  32. exit 1
  33. }
  34. # run a command or just print it
  35. RUN()
  36. {
  37. local command log
  38. log=yes
  39. case "$1" in
  40. -n|--no-log)
  41. log=no
  42. shift
  43. ;;
  44. *)
  45. ;;
  46. esac
  47. command="$*"
  48. case "${debug}" in
  49. [yY]|[yY][eE][sS])
  50. echo DEBUG: ${command}
  51. return
  52. ;;
  53. *)
  54. ;;
  55. esac
  56. case "${log}" in
  57. [yY]|[yY][eE][sS])
  58. echo | tee -a "${LogFile}"
  59. echo '===>' $(date '+%Y-%m-%d %H:%M:%S'): ${command} | tee -a "${LogFile}"
  60. eval "time ${command}" 2>&1 | tee -a "${LogFile}"
  61. ;;
  62. *)
  63. eval "${command}"
  64. esac
  65. }
  66. verbose=no
  67. IndexHost=
  68. clear=no
  69. work=work
  70. dest=image
  71. temp=/tmp
  72. run=yes
  73. IndexOnly=no
  74. farm=
  75. debug=no
  76. language=en
  77. suffix=pedia
  78. FilePrefix=wiki
  79. MaximumThreads=64
  80. export MACHINE_COUNT=${MACHINE_COUNT:-9}
  81. export PARALLEL_BUILD=${PARALLEL_BUILD:-3}
  82. compression=low
  83. getopt=/usr/local/bin/getopt
  84. [ -x "${getopt}" ] || getopt=getopt
  85. args=$(${getopt} -o hvg:p:incrRl:s:w:d:t:f:p:j:m:CD: --long=help,verbose,get-index:,index-only,no-run,clear,re-render,re-parse,language:,suffix:,suffix:,work:,dest:,temp:,farm:,prefix:,parallel:,machines:,compress:,debug -- "$@") ||exit 1
  86. # replace the arguments with the parsed values
  87. eval set -- "${args}"
  88. while :
  89. do
  90. case "$1" in
  91. -v|--verbose)
  92. verbose=yes
  93. shift
  94. ;;
  95. -g|--get-index)
  96. IndexHost=$2
  97. shift 2
  98. ;;
  99. -i|--index-only)
  100. IndexOnly=yes
  101. clear=index
  102. shift
  103. ;;
  104. -n|--no-run)
  105. run=no
  106. shift
  107. ;;
  108. -c|--clear)
  109. clear=yes
  110. shift
  111. ;;
  112. -r|--re-render)
  113. clear=render
  114. shift
  115. ;;
  116. -R|--re-parse)
  117. clear=parse
  118. shift
  119. ;;
  120. -l|--language)
  121. language=$2
  122. shift 2
  123. ;;
  124. -s|--suffix)
  125. suffix=$2
  126. shift 2
  127. ;;
  128. -w|--work)
  129. work=$2
  130. shift 2
  131. ;;
  132. -d|--dest)
  133. dest=$2
  134. shift 2
  135. ;;
  136. -t|--temp)
  137. temp=$2
  138. shift 2
  139. ;;
  140. -f|--farm)
  141. farm=$2
  142. shift 2
  143. ;;
  144. -p|--prefix)
  145. FilePrefix=$2
  146. shift 2
  147. ;;
  148. -j|--parallel)
  149. PARALLEL_BUILD=$2
  150. shift 2
  151. ;;
  152. -m|--machines)
  153. MACHINE_COUNT=$2
  154. shift 2
  155. ;;
  156. -C|--compress)
  157. compression=$2
  158. shift 2
  159. ;;
  160. -D|--debug)
  161. debug=yes
  162. shift
  163. ;;
  164. --)
  165. shift
  166. break
  167. ;;
  168. -h|--help)
  169. USAGE
  170. ;;
  171. *)
  172. USAGE invalid option: $1
  173. ;;
  174. esac
  175. done
  176. if [[ $((${MACHINE_COUNT} * ${PARALLEL_BUILD})) > ${MaximumThreads} ]]
  177. then
  178. echo MACHINE_COUNT=${MACHINE_COUNT}
  179. echo PARALLEL_BUILD=${PARALLEL_BUILD}
  180. USAGE too many threads: "${MACHINE_COUNT} * ${PARALLEL_BUILD} > ${MaximumThreads}"
  181. fi
  182. [ -z "${language}" ] && USAGE language is not set
  183. licenses=$(readlink -m "${LicensesDirectory}")
  184. license="${licenses}/${language}/license.xml"
  185. terms="${licenses}/${language}/terms.xml"
  186. articles_link="${language}wiki-pages-articles.xml"
  187. articles=$(readlink -m "${articles_link}")
  188. LogFile="${language}.log"
  189. [ -f "${articles}" ] || USAGE error articles link: ${articles_link} not set correctly
  190. [ -f "${license}" ] || license="${licenses}/en/license.xml"
  191. [ -f "${terms}" ] || terms="${licenses}/en/terms.xml"
  192. xml="${license} ${terms} ${articles}"
  193. # extract numeric suffix from host name
  194. # expect that the rendering hosts are numbered from zero
  195. this_host=$(hostname --short)
  196. this_host_prefix=${this_host%%[0-9]}
  197. this_id=${this_host##*[^0-9]}
  198. [ -z "${this_id}" ] && this_id=0
  199. [ -z "${farm}" ] && farm="farm${this_id}" || farm="farm${farm##*[a-z]}"
  200. # truncate the log file
  201. RUN -n rm -f "${LogFile}"
  202. RUN -n touch "${LogFile}"
  203. # update
  204. RUN git pull --rebase
  205. # set up the make options
  206. common_opts="DESTDIR='${dest}' WORKDIR='${work}' TEMPDIR='${temp}'"
  207. common_opts="${common_opts} WIKI_FILE_PREFIX='${FilePrefix}'"
  208. common_opts="${common_opts} WIKI_LANGUAGE='${language}'"
  209. common_opts="${common_opts} WIKI_DIR_SUFFIX='${suffix}'"
  210. common_opts="${common_opts} XML_FILES='${xml}'"
  211. common_opts="${common_opts} VERBOSE='${verbose}'"
  212. case "${language}" in
  213. en)
  214. case "${compression}" in
  215. [hH][iI][gG][hH])
  216. # Best version for 4GB card
  217. common_opts="${common_opts} ENABLE_LANGUAGES_LINKS=NO"
  218. ## ok
  219. #common_opts="${common_opts} ARTICLES_PER_BLOCK=64"
  220. #common_opts="${common_opts} ARTICLE_BLOCK_SIZE=250000"
  221. ## ok
  222. common_opts="${common_opts} ARTICLES_PER_BLOCK=64"
  223. common_opts="${common_opts} ARTICLE_BLOCK_SIZE=200000"
  224. ;;
  225. *)
  226. # low compression for 8GB card
  227. common_opts="${common_opts} ENABLE_LANGUAGES_LINKS=YES"
  228. common_opts="${common_opts} ARTICLES_PER_BLOCK=1"
  229. common_opts="${common_opts} ARTICLE_BLOCK_SIZE=131072"
  230. ;;
  231. esac
  232. ;;
  233. *)
  234. common_opts="${common_opts} ENABLE_LANGUAGES_LINKS=YES"
  235. common_opts="${common_opts} ARTICLES_PER_BLOCK=1"
  236. common_opts="${common_opts} ARTICLE_BLOCK_SIZE=131072"
  237. ;;
  238. esac
  239. # clean up
  240. case "${clear}" in
  241. [yY]|[yY][eE][sS])
  242. RUN make clean index-clean "${farm}-clean" cleandirs ${common_opts}
  243. ;;
  244. [iI][nN][dD][eE][xX])
  245. RUN make clean index-clean ${common_opts}
  246. ;;
  247. [rR][eE][nN][dD][eE][rR])
  248. RUN make clean "${farm}-render-clean" ${common_opts}
  249. RUN make "${farm}-parse-touch" ${common_opts}
  250. ;;
  251. [pP][aA][rR][sS][eE])
  252. RUN make clean "${farm}-clean" ${common_opts}
  253. ;;
  254. [nN]|[nN][oO])
  255. ;;
  256. *)
  257. ERROR unknown clear action: ${clear}
  258. ;;
  259. esac
  260. # create root directories and fonts
  261. RUN make createdirs ${common_opts}
  262. RUN make fonts ${common_opts}
  263. # copy the index from another machine
  264. #=====================================
  265. #!!! THIS HAS HARD CODED SAMO PATH !!!
  266. #!!! NEED TO FIX THIS !!!
  267. #=====================================
  268. if [ -n "${IndexHost}" ]
  269. then
  270. echo THIS IS BROKEN
  271. exit 99
  272. [ -z "${IndexHost%%[0-9]}" ] && IndexHost="${this_host_prefix}${IndexHost}"
  273. list='templates.db articles.db offsets.db counts.text'
  274. items=
  275. for i in ${list}
  276. do
  277. items="${items} ${IndexHost}:samo/${work}/${i}"
  278. done
  279. RUN rsync -avHx --progress ${items} "${work}"/
  280. RUN touch stamp-r-index # ***THIS IS WRONG need to have a make target for this
  281. fi
  282. # run the build
  283. case "${run}" in
  284. [yY]|[yY][eE][sS])
  285. RUN make farm-index ${common_opts}
  286. case "${IndexOnly}" in
  287. [yY]|[yY][eE][sS])
  288. ;;
  289. *)
  290. RUN make -j${PARALLEL_BUILD} "${farm}" ${common_opts}
  291. ;;
  292. esac
  293. esac