OpenSDE Framework (without history before r20070)
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.

122 lines
3.2 KiB

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