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.

148 lines
3.3 KiB

  1. #!/bin/sh
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: lib/init/formats/tail.in
  6. # Copyright (C) 2008 The OpenSDE Project
  7. # Copyright (C) 2004 - 2006 The T2 SDE Project
  8. #
  9. # More information can be found in the files COPYING and README.
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; version 2 of the License. A copy of the
  14. # GNU General Public License can be found in the file COPYING.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. # T2 Automated Init Language - Tail
  17. # http://wiki.t2-project.org/index.cgi?TailFormat
  18. # Alejandro Mery <amery@geeks.cl>
  19. tail_read() {
  20. local verbose=1 file= output= query=
  21. local query= count=2
  22. if [ "$1" = "-q" ]; then
  23. verbose=
  24. shift
  25. fi
  26. file="$1"; shift
  27. while [ $# -gt 1 ]; do
  28. query="${query}$1 "
  29. shift;
  30. (( count++ ))
  31. done
  32. query="${query}$1\\( \\|\$\\)"
  33. output="$( grep -e "^$query" $file | cut -f$count- )"
  34. [ "$verbose" ] && echo "$output"
  35. grep -q -e "^$query" $file
  36. }
  37. tail_install() {
  38. local style=$1 tailfile="$2"
  39. local x= y= z=
  40. shift 2
  41. case "$style" in
  42. runit)
  43. local servicedir=$( echo `eval echo $1` )
  44. local runprefix=
  45. mkdir -vp "$servicedir"
  46. rm -f /tmp/tail.$$
  47. # run /tailrun/ options
  48. #
  49. eval "`tail_read $tailfile tailrun $style`"
  50. # ./env/
  51. #
  52. if tail_read -q $tailfile env; then
  53. mkdir -p "$servicedir/env"
  54. runprefix="$runprefix${runprefix:+ }envdir ./env"
  55. tail_read $tailfile env | while read x y; do
  56. echo "TAIL: ./env/$x = $y"
  57. echo "$y" | rock_substitute > $servicedir/env/$x
  58. done
  59. fi
  60. # ./run
  61. #
  62. cat <<-EOT > /tmp/tail.$$
  63. #!/bin/sh
  64. exec 2>&1
  65. EOT
  66. if tail_read -q $tailfile input; then
  67. echo "exec < $( tail_read $tailfile input )" >> /tmp/tail.$$
  68. fi
  69. if tail_read -q $tailfile user; then
  70. runprefix="$runprefix${runprefix:+ }envuidgid $( tail_read $tailfile user )"
  71. fi
  72. echo "exec $runprefix${runprefix:+ }$( tail_read $tailfile run )" >> /tmp/tail.$$
  73. rock_substitute /tmp/tail.$$ > $servicedir/run
  74. chmod +x $servicedir/run
  75. # ./conffile
  76. #
  77. for x in `tail_read $tailfile conf | cut -f1 | sort -u`; do
  78. y="$x"
  79. echo "TAIL: $x ..."
  80. if [ "${y%/*}" != "$y" ]; then
  81. if [ "${y:0:1}" != "/" ]; then
  82. y="$servicedir/$y"
  83. fi
  84. mkdir -vp ${y%/*}
  85. fi
  86. rm -vf $y
  87. tail_read $tailfile conf $x | rock_substitute > $y
  88. done
  89. # ./log/
  90. #
  91. if tail_read -q $tailfile log; then
  92. mkdir -vp "$servicedir/log/main"
  93. if [ -z "$logdir" ]; then
  94. if [ "${localstatedir%$pkg}" != "$localstatedir" ]; then
  95. logdir=$localstatedir/log
  96. else
  97. logdir=$localstatedir/log/$pkg
  98. fi
  99. fi
  100. z=
  101. for x in `tail_read $tailfile log | cut -f1 | sort -u`; do
  102. echo "TAIL: ./log/$x"
  103. mkdir -vp $root/$logdir/$x
  104. chown 9:9 $root/$logdir/$x
  105. ln -vnfs $logdir/$x $servicedir/log/main/
  106. z="$z main/$x"
  107. y="`tail_read $tailfile log $x`"
  108. [ "$y" ] && echo "$y" > $root/$logdir/$x/config || true
  109. done
  110. cat <<-EOT > "$servicedir/log/run"
  111. #!/bin/sh
  112. exec 2>&1
  113. exec setuidgid log svlogd -t $z
  114. EOT
  115. chmod +x "$servicedir/log/run"
  116. fi
  117. ;;
  118. *)
  119. abort "tail_install: unknown style '$style' for $tailfile."
  120. ;;
  121. esac
  122. }