pbs_mkdirs.in 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. #!/bin/sh
  2. #
  3. # pbs_mkdirs:
  4. #
  5. # This will make the various directories that are needed for PBS
  6. # housekeeping.
  7. #
  8. # Usage:
  9. # pbs_mkdirs [-v] [-c] what
  10. # -v be verbose
  11. # -c allow usage of chk_tree (do not use this within a make install)
  12. # what select from the following list
  13. # conf -- /etc/pbs.conf.new file
  14. # client -- dirs needed by client programs
  15. # server -- dirs needed by pbs_server
  16. # mom -- dirs needed by pbs_mom
  17. # comm -- dirs needed by pbs_comm
  18. # aux -- the aux directory
  19. # default -- the default file
  20. # check -- run chk_tree (turns on -c automatically)
  21. # all -- do all of the above
  22. #
  23. #
  24. #
  25. #
  26. #
  27. # Copyright (C) 1994-2018 Altair Engineering, Inc.
  28. # For more information, contact Altair at www.altair.com.
  29. #
  30. # This file is part of the PBS Professional ("PBS Pro") software.
  31. #
  32. # Open Source License Information:
  33. #
  34. # PBS Pro is free software. You can redistribute it and/or modify it under the
  35. # terms of the GNU Affero General Public License as published by the Free
  36. # Software Foundation, either version 3 of the License, or (at your option) any
  37. # later version.
  38. #
  39. # PBS Pro is distributed in the hope that it will be useful, but WITHOUT ANY
  40. # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  41. # FOR A PARTICULAR PURPOSE.
  42. # See the GNU Affero General Public License for more details.
  43. #
  44. # You should have received a copy of the GNU Affero General Public License
  45. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  46. #
  47. # Commercial License Information:
  48. #
  49. # For a copy of the commercial license terms and conditions,
  50. # go to: (http://www.pbspro.com/UserArea/agreement.html)
  51. # or contact the Altair Legal Department.
  52. #
  53. # Altair’s dual-license business model allows companies, individuals, and
  54. # organizations to create proprietary derivative works of PBS Pro and
  55. # distribute them - whether embedded or bundled with other software -
  56. # under a commercial license agreement.
  57. #
  58. # Use of Altair’s trademarks, including but not limited to "PBS™",
  59. # "PBS Professional®", and "PBS Pro™" and Altair’s logos is subject to Altair's
  60. # trademark licensing policies.
  61. #
  62. #
  63. # check tree should not be called until it is installed since
  64. # only relative paths are used by autoconf.
  65. #
  66. prefix=@prefix@
  67. exec_prefix=@exec_prefix@
  68. CHK_TREE=@bindir@/chk_tree
  69. PBS_SERVER_HOME=@PBS_SERVER_HOME@
  70. PBS_DEFAULT_FILE=@PBS_DEFAULT_FILE@
  71. PBS_DEFAULT_SERVER=@PBS_DEFAULT_SERVER@
  72. PBS_DEFAULT_DATAPORT=@PBS_DEFAULT_DATAPORT@
  73. PBS_CONF_FILE=@PBS_CONF_FILE@
  74. PBS_ENVIRON=@PBS_ENVIRON@
  75. SCP_PATH=@SCP_PATH@
  76. database_dir=@database_dir@
  77. database_user=@database_user@
  78. database_port=@database_port@
  79. core_limit=@core_limit@
  80. PBS_UBIN=@bindir@
  81. PBS_SBIN=@sbindir@
  82. PBS_ETC=@etcdir@
  83. PBS_LIB=@libdir@
  84. PBS_UINC=@includedir@
  85. PBS_UNSUP=@unsupporteddir@
  86. verbose=""
  87. #
  88. # this will create a directory and any chain of parent directories
  89. # that might be needed
  90. # All of this is somewhat lame because install-sh is used
  91. # along with install_dir in various places.
  92. #
  93. install_dir()
  94. {
  95. # use the id_ for namespace disambiguation
  96. id_dname="${IROOT}$1"
  97. id_mode=`test -n "$2" && echo "$2" || echo 755`
  98. id_owner=`test -n "$3" && echo "$3" || echo root`
  99. # dlist will contain a list of directory names to make
  100. id_dlist=""
  101. while [ ! \( -z "$id_dname" -o "$id_dname" = / -o \
  102. "$id_dname" = "." \) ]; do
  103. test -f $id_dname && return 1
  104. test -d $id_dname && break
  105. id_dlist="`basename $id_dname` $id_dlist"
  106. id_dname=`dirname "$id_dname"`
  107. done
  108. id_dir="$id_dname"
  109. for id_d in $id_dlist ""; do
  110. id_dir="$id_dir/$id_d"
  111. test -z "$id_d" && return 0
  112. mkdir $id_dir && chmod $id_mode $id_dir && \
  113. chown $id_owner $id_dir || return 1
  114. done
  115. return 0
  116. }
  117. #
  118. # This will take the name of the variable (not value) and
  119. # make a directory. This is just to stick with the original
  120. # way things were done in the top-level make file in PBS
  121. #
  122. install_dir_by_varname()
  123. {
  124. idv_dvarname="$1"
  125. idv_dname=${IROOT}`eval 'echo $'$idv_dvarname`
  126. idv_mode=`test -n "$2" && echo "$2" || echo 755`
  127. idv_owner=`test -n "$3" && echo "$3" || echo root`
  128. if [ X$idv_dname = X ] ; then
  129. echo $idv_dvarname is not defined 1>&2
  130. return 1
  131. elif [ -f $idv_dname ] ; then
  132. echo $idv_dvarname exists and is not a directory 1>&2
  133. return 1
  134. elif [ -d $idv_dname ] ; then
  135. chmod $idv_mode $idv_dname > /dev/null 2>&1
  136. chown $idv_owner $idv_dname > /dev/null 2>&1
  137. return 0
  138. elif [ ! -d $idv_dname ] ; then
  139. test -n "$verbose" && echo Creating $idv_dname
  140. install_dir `dirname $idv_dname` 755 $idv_owner && \
  141. mkdir $idv_dname && chmod $idv_mode $idv_dname && \
  142. chown $idv_owner $idv_dname || return 1
  143. fi
  144. return 0
  145. }
  146. check_env()
  147. {
  148. test -n "$verbose" && echo Making environment file
  149. if [ ! -f ${IROOT}$PBS_ENVIRON ] ; then
  150. install_dir `dirname $PBS_ENVIRON`
  151. echo "PATH=/bin:/usr/bin" > ${IROOT}$PBS_ENVIRON
  152. if [ X$TZ != X ] ; then
  153. echo "TZ=$TZ" >> ${IROOT}$PBS_ENVIRON
  154. fi
  155. if [ X$LANG != X ] ; then
  156. echo "LANG=$LANG" >> ${IROOT}$PBS_ENVIRON
  157. fi
  158. if [ X$LC_ALL != X ] ; then
  159. echo "LC_ALL=$LC_ALL" >> ${IROOT}$PBS_ENVIRON
  160. fi
  161. if [ X$LC_COLLATE != X ] ; then
  162. echo "LC_COLLATE=$LC_COLLATE" >> ${IROOT}$PBS_ENVIRON
  163. fi
  164. if [ X$LC_CTYPE != X ] ; then
  165. echo "LC_CTYPE=$LC_CTYPE" >> ${IROOT}$PBS_ENVIRON
  166. fi
  167. if [ X$LC_MONETARY != X ] ; then
  168. echo "LC_MONETARY=$LC_MONETARY" >> ${IROOT}$PBS_ENVIRON
  169. fi
  170. if [ X$LC_NUMERIC != X ] ; then
  171. echo "LC_NUMERIC=$LC_NUMERIC" >> ${IROOT}$PBS_ENVIRON
  172. fi
  173. if [ X$LC_TIME != X ] ; then
  174. echo "LC_TIME=$LC_TIME" >> ${IROOT}$PBS_ENVIRON
  175. fi
  176. chmod 644 ${IROOT}$PBS_ENVIRON
  177. fi
  178. }
  179. make_momconfig()
  180. {
  181. test -n "$verbose" && echo Creating Moms config file
  182. if [ ! -f ${IROOT}$PBS_SERVER_HOME/mom_priv/config ] ; then
  183. echo '$logevent 0x1ff' > ${IROOT}$PBS_SERVER_HOME/mom_priv/config
  184. echo \$clienthost $PBS_DEFAULT_SERVER \
  185. >> ${IROOT}$PBS_SERVER_HOME/mom_priv/config
  186. chmod 644 ${IROOT}$PBS_SERVER_HOME/mom_priv/config
  187. fi
  188. }
  189. chk_tree_wrap()
  190. {
  191. test -n "$chktree" && $CHK_TREE $*
  192. }
  193. mk_cli_dirs()
  194. {
  195. test -n "$verbose" && echo Creating Directories required for clients
  196. install_dir_by_varname PBS_UBIN 755 $owner
  197. install_dir_by_varname PBS_SBIN 755 $owner
  198. install_dir_by_varname PBS_LIB 755 $owner
  199. install_dir_by_varname PBS_LIB/pm 755 $owner
  200. install_dir_by_varname PBS_UINC 755 $owner
  201. install_dir_by_varname PBS_ETC 755 $owner
  202. install_dir_by_varname PBS_UNSUP 755 $owner
  203. chk_tree_wrap -d -n ${IROOT}$PBS_UBIN ${IROOT}$PBS_SBIN \
  204. ${IROOT}$PBS_LIB ${IROOT}$PBS_LIB/pm \
  205. ${IROOT}$PBS_UINC ${IROOT}$PBS_ETC \
  206. ${IROOT}$PBS_UNSUP
  207. }
  208. mk_comm_dirs()
  209. {
  210. test -n "$verbose" && echo Creating Directories required for Communication
  211. install_dir $PBS_SERVER_HOME/comm_logs 755 $owner
  212. }
  213. mk_server_dirs()
  214. {
  215. test -n "$verbose" && echo Creating Directories required for the Server
  216. install_dir_by_varname PBS_SERVER_HOME 755 $owner
  217. install_dir $PBS_SERVER_HOME/spool 1777 $owner
  218. install_dir $PBS_SERVER_HOME/server_priv 750 $owner
  219. install_dir $PBS_SERVER_HOME/server_priv/jobs 750 $owner
  220. install_dir $PBS_SERVER_HOME/server_priv/users 750 $owner
  221. install_dir $PBS_SERVER_HOME/server_priv/hooks 750 $owner
  222. install_dir $PBS_SERVER_HOME/server_priv/hooks/tmp 750 $owner
  223. install_dir $PBS_SERVER_HOME/server_priv/accounting 755 $owner
  224. install_dir $PBS_SERVER_HOME/server_logs 755 $owner
  225. install_dir $PBS_SERVER_HOME/sched_priv 750 $owner
  226. install_dir $PBS_SERVER_HOME/sched_logs 755 $owner
  227. test -f ${IROOT}$PBS_ENVIRON || check_env
  228. chk_tree_wrap -d -n ${IROOT}$PBS_SERVER_HOME/server_priv/jobs \
  229. ${IROOT}$PBS_SERVER_HOME/server_priv/users \
  230. ${IROOT}$PBS_SERVER_HOME/server_priv/hooks \
  231. ${IROOT}$PBS_SERVER_HOME/server_priv/hooks/tmp \
  232. ${IROOT}$PBS_SERVER_HOME/server_priv/accounting \
  233. ${IROOT}$PBS_SERVER_HOME/server_logs
  234. chk_tree_wrap -d -n -s ${IROOT}$PBS_SERVER_HOME/spool
  235. chk_tree_wrap -n ${IROOT}$PBS_ENVIRON
  236. }
  237. mk_mom_dirs()
  238. {
  239. test -n "$verbose" && echo Creating Directories required for MOM
  240. install_dir_by_varname PBS_SERVER_HOME 755 $owner
  241. test -d ${IROOT}$PBS_SERVER_HOME/spool || \
  242. install_dir ${IROOT}$PBS_SERVER_HOME/spool 1777 $owner
  243. install_dir $PBS_SERVER_HOME/checkpoint 700 $owner
  244. install_dir $PBS_SERVER_HOME/undelivered 1777 $owner
  245. install_dir $PBS_SERVER_HOME/mom_priv 751 $owner
  246. install_dir $PBS_SERVER_HOME/mom_priv/jobs 751 $owner
  247. install_dir $PBS_SERVER_HOME/mom_priv/hooks 750 $owner
  248. install_dir $PBS_SERVER_HOME/mom_priv/hooks/tmp 750 $owner
  249. install_dir $PBS_SERVER_HOME/mom_logs 755 $owner
  250. test -f ${IROOT}$PBS_ENVIRON || check_env
  251. test -f ${IROOT}$PBS_SERVER_HOME/mom_priv/config || make_momconfig
  252. chk_tree_wrap -d -n ${IROOT}$PBS_SERVER_HOME/checkpoint \
  253. ${IROOT}$PBS_SERVER_HOME/mom_priv/jobs \
  254. ${IROOT}$PBS_SERVER_HOME/mom_priv/hooks \
  255. ${IROOT}$PBS_SERVER_HOME/mom_priv/hooks/tmp \
  256. ${IROOT}$PBS_SERVER_HOME/mom_logs
  257. chk_tree_wrap -d -n -s ${IROOT}$PBS_SERVER_HOME/spool \
  258. ${IROOT}$PBS_SERVER_HOME/undelivered
  259. chk_tree_wrap -n ${IROOT}$PBS_ENVIRON
  260. }
  261. mk_default_file()
  262. {
  263. test -n "$verbose" && echo Making default server file
  264. install_dir `dirname ${IROOT}$PBS_DEFAULT_FILE`
  265. rm -f ${IROOT}$PBS_DEFAULT_FILE > /dev/null 2>&1
  266. echo $PBS_DEFAULT_SERVER > ${IROOT}$PBS_DEFAULT_FILE && \
  267. chmod 644 ${IROOT}$PBS_DEFAULT_FILE
  268. chk_tree_wrap -n ${IROOT}$PBS_DEFAULT_FILE
  269. }
  270. mk_aux_dir()
  271. {
  272. install_dir $PBS_SERVER_HOME/aux 755
  273. chk_tree_wrap -d -n ${IROOT}$PBS_SERVER_HOME/aux
  274. }
  275. do_check_tree()
  276. {
  277. chk_tree_wrap -d ${IROOT}$PBS_SERVER_HOME/server_priv/jobs \
  278. ${IROOT}$PBS_SERVER_HOME/server_priv/users \
  279. ${IROOT}$PBS_SERVER_HOME/server_priv/hooks \
  280. ${IROOT}$PBS_SERVER_HOME/server_priv/hooks/tmp \
  281. ${IROOT}$PBS_SERVER_HOME/server_priv/accounting \
  282. ${IROOT}$PBS_SERVER_HOME/server_logs
  283. chk_tree_wrap -d ${IROOT}$PBS_SERVER_HOME/checkpoint \
  284. ${IROOT}$PBS_SERVER_HOME/mom_priv/jobs \
  285. ${IROOT}$PBS_SERVER_HOME/mom_priv/hooks \
  286. ${IROOT}$PBS_SERVER_HOME/mom_priv/hooks/tmp \
  287. ${IROOT}$PBS_SERVER_HOME/mom_logs
  288. chk_tree_wrap -d -s ${IROOT}$PBS_SERVER_HOME/spool \
  289. ${IROOT}$PBS_SERVER_HOME/undelivered
  290. chk_tree_wrap -d ${IROOT}$PBS_SERVER_HOME/aux
  291. chk_tree_wrap ${IROOT}$PBS_DEFAULT_FILE
  292. }
  293. # mk_conf_file() will make /etc/pbs.conf.new with basic info
  294. # as server/remom files are added the start entries for those daemons are added
  295. mk_conf_file()
  296. {
  297. test -n "$verbose" && echo Making global config file
  298. install_dir `dirname ${IROOT}${PBS_CONF_FILE}`
  299. if [ -f ${IROOT}${PBS_CONF_FILE} ] ; then
  300. target="${IROOT}${PBS_CONF_FILE}.`date +%s`"
  301. echo Moving existing ${IROOT}${PBS_CONF_FILE} to ${target}
  302. mv ${IROOT}${PBS_CONF_FILE} ${target}
  303. fi
  304. echo PBS_EXEC=$exec_prefix > ${IROOT}${PBS_CONF_FILE}
  305. echo PBS_HOME=$PBS_SERVER_HOME >> ${IROOT}${PBS_CONF_FILE}
  306. echo PBS_START_SERVER=0 >> ${IROOT}${PBS_CONF_FILE}
  307. echo PBS_START_MOM=0 >> ${IROOT}${PBS_CONF_FILE}
  308. echo PBS_START_SCHED=0 >> ${IROOT}${PBS_CONF_FILE}
  309. echo PBS_START_COMM=0 >> ${IROOT}${PBS_CONF_FILE}
  310. echo PBS_SERVER=$PBS_DEFAULT_SERVER >> ${IROOT}${PBS_CONF_FILE}
  311. echo PBS_ENVIRONMENT=$PBS_ENVIRON >> ${IROOT}${PBS_CONF_FILE}
  312. echo PBS_CORE_LIMIT=$core_limit >> ${IROOT}${PBS_CONF_FILE}
  313. if [ -n "$SCP_PATH" ] ; then
  314. echo PBS_SCP=$SCP_PATH >> ${IROOT}${PBS_CONF_FILE}
  315. fi
  316. if [ "$database_port" != "$PBS_DEFAULT_DATAPORT" ]; then
  317. echo PBS_DATA_SERVICE_PORT=$database_port >> ${IROOT}${PBS_CONF_FILE}
  318. fi
  319. chmod 644 ${IROOT}${PBS_CONF_FILE}
  320. }
  321. # mk_dirs() will generate the set of directories needed
  322. # for server and mom execution.
  323. mk_dirs()
  324. {
  325. chktree=yes
  326. mk_cli_dirs
  327. mk_server_dirs
  328. mk_mom_dirs
  329. mk_comm_dirs
  330. mk_default_file
  331. mk_aux_dir
  332. }
  333. while true; do
  334. case "$1" in
  335. -v) verbose=yes ; shift; continue ;;
  336. -c) chktree=yes ; shift; continue ;;
  337. -d) shift; PBS_SERVER_HOME=$1; shift; continue;;
  338. conf) mk_conf_file ; break ;;
  339. cli*) mk_cli_dirs ; break ;;
  340. serv*) mk_server_dirs ; break ;;
  341. mom*) mk_mom_dirs ; break ;;
  342. com*) mk_comm_dirs ; break ;;
  343. aux*) mk_aux_dir ; break ;;
  344. default*) mk_default_file ; break ;;
  345. check*) chktree=yes; do_check_tree ; break ;;
  346. all*) mk_dirs ; break ;;
  347. esac
  348. done