mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
3.5 KiB

  1. #!/bin/bash
  2. #
  3. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  4. #
  5. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  6. # Please add additional copyright information _after_ the line containing
  7. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  8. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  9. #
  10. # ROCK Linux: rock-src/scripts/Build-Job
  11. # ROCK Linux is Copyright (C) 1998 - 2003 Clifford Wolf
  12. #
  13. # This program is free software; you can redistribute it and/or modify
  14. # it under the terms of the GNU General Public License as published by
  15. # the Free Software Foundation; either version 2 of the License, or
  16. # (at your option) any later version. A copy of the GNU General Public
  17. # License can be found at Documentation/COPYING.
  18. #
  19. # Many people helped and are helping developing ROCK Linux. Please
  20. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  21. # file for details.
  22. #
  23. # --- ROCK-COPYRIGHT-NOTE-END ---
  24. config=default
  25. xdaemon=0
  26. daemon=0
  27. while [ "$1" ] ; do
  28. case "$1" in
  29. -daemon)
  30. daemon=1 ; shift ;;
  31. -xdaemon)
  32. xdaemon=1 ; shift ;;
  33. -cfg)
  34. config=$2 ; shift ; shift ;;
  35. -*)
  36. echo "Usage: $0 [ -cfg config ] { -daemon | job(s) }"
  37. exit 1 ;;
  38. *)
  39. break ;;
  40. esac
  41. done
  42. . ./scripts/parse-config
  43. qdir="build/$ROCKCFG_ID/queue"
  44. build_logs="build/$ROCKCFG_ID/logs"
  45. mkdir -p "${build_logs}"
  46. if [ $daemon = 1 ] ; then
  47. if [ -f $qdir/queue.txt ] ; then
  48. if [ -f $qdir/use_build_job_daemon ] ; then
  49. nohup $0 -cfg $config -xdaemon > /dev/null &
  50. sleep 1 ; exit 0
  51. else
  52. echo
  53. echo "The build has been configured to use a command for"
  54. echo "adding jobs (useing another job scheduler)."
  55. echo
  56. exit 1
  57. fi
  58. else
  59. echo
  60. echo "$qdir:"
  61. echo "Queue not found! Please start 'Build-Target -cfg $config'"
  62. echo "first on the master node ..."
  63. echo
  64. exit 1
  65. fi
  66. fi
  67. if [ $xdaemon = 1 ] ; then
  68. echo "Writing output to $build_logs/build_job_${HOSTNAME}_$$.log." >&2
  69. exec > "$build_logs/build_job_${HOSTNAME}_$$.log" 2>&1 < /dev/null
  70. echo -e "Build-Job (daemon mode)\trunning on ${HOSTNAME} with PID $$" \
  71. > "$qdir/build_job_${HOSTNAME}_$$.stat"
  72. date "+%H:%M ${HOSTNAME} new build-job daemon with PID $$" \
  73. >> $qdir/1_$qid.msg
  74. while [ -f $qdir/queue.txt -a -f $qdir/use_build_job_daemon -a \
  75. -f "$qdir/build_job_${HOSTNAME}_$$.stat" ] ; do
  76. didsomething=0
  77. while read next && [ "$next" ] ; do
  78. set $next ; qid="$1-$6"
  79. if [ -f $qdir/$qid.job -a ! -f $qdir/$qid.lock ] ; then
  80. $0 -cfg $config $qid
  81. didsomething=1 ; break
  82. fi
  83. done < $qdir/queue.txt
  84. [ $didsomething = 1 ] || sleep 3
  85. done
  86. rm -f "$qdir/build_job_${HOSTNAME}_$$.stat"
  87. if [ -f $qdir/queue.txt ] ; then
  88. date "+%H:%M ${HOSTNAME}%tbuild-job daemon ended ($$)" \
  89. >> $qdir/8_$qid.msg
  90. fi
  91. echo "Queue has been removed. exit now."
  92. exit 0
  93. fi
  94. for qid ; do
  95. if [ -f $qdir/$qid.job ] ; then
  96. if ! mv $qdir/$qid.todo $qdir/$qid.lock 2> /dev/null ; then
  97. echo "Job locked by other build proc:" \
  98. "$qid ($qdir/$qid.lock)!"
  99. exit 1
  100. fi
  101. . $qdir/$qid.job
  102. date "+Job $qid%t$HOSTNAME ($PPID) since %H:%M %Y-%m-%d" \
  103. > $qdir/$qid.lock
  104. date "+%H:%M ${HOSTNAME}:%tbuilding job '$qid' ($PPID) .." \
  105. >> $qdir/6_$qid.msg
  106. pkgloop_package $next
  107. if [ -f "${build_root}/var/adm/logs/$qid.log" ] ; then
  108. date "+%H:%M ${HOSTNAME}:%tfinished job '$qid' `
  109. `(ok)" >> $qdir/3_$qid.msg
  110. else
  111. date "+%H:%M ${HOSTNAME}:%tfinished job '$qid' `
  112. `(ERROR)" >> $qdir/3_$qid.msg
  113. fi
  114. rm -f $qdir/$qid.lock $qdir/$qid.job
  115. else
  116. echo "No such job: $qid ($qdir/$qid.job)!" ; exit 1
  117. fi
  118. done