Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2012
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.59 KB | None | 0 0
  1. > pastebin apache2
  2. pastebin: command not found
  3.  
  4. > cat apache2
  5. #!/bin/sh
  6. #
  7. # Copyright (c) 1996, 1997, 1998 S.u.S.E. GmbH
  8. # Copyright (c) 1998, 1999, 2000, 2001 SuSE GmbH
  9. # Copyright (c) 2002, 2003, (2004?) SuSE Linux AG
  10. # Copyright (c) 2004(?), 2005, 2006, 2007, 2008 SUSE Linux Products GmbH
  11. #
  12. # Authors: Rolf Haberrecker <[email protected]>, 2001
  13. # Peter Poeml <[email protected]>, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011.
  14. # Roman Drahtmueller <[email protected]>, 2010, 2011, 2012.
  15. #
  16. #
  17. # /etc/init.d/apache2
  18. #
  19. ### BEGIN INIT INFO
  20. # Provides: apache apache2 httpd
  21. # Required-Start: $local_fs $remote_fs $network
  22. # Should-Start: $named $time postgresql sendmail mysql ypclient dhcp radiusd
  23. # Should-Stop: $named $time postgresql sendmail mysql ypclient dhcp radiusd
  24. # Required-Stop: $local_fs $remote_fs $network
  25. # Default-Start: 3 5
  26. # Default-Stop: 0 1 2 6
  27. # X-Interactive: true
  28. # Short-Description: Apache 2.2 HTTP Server
  29. # Description: Start the Apache HTTP daemon
  30. ### END INIT INFO
  31.  
  32. pname=apache2
  33. : ${sysconfdir:=/etc/$pname}
  34. : ${apache_link:=/usr/sbin/httpd2}
  35. : ${sysconfig_apache:=/etc/sysconfig/$pname}
  36. : ${pidfile:=/var/run/httpd2.pid}
  37. : ${logdir:=/var/log/$pname}
  38. : ${homedir:=/var/lib/$pname}
  39.  
  40. #
  41. # load the configuration
  42. #
  43.  
  44. #
  45. # Note about ulimits:
  46. # if you want to set ulimits, e.g. to increase the max number of open file handle,
  47. # or to allow core files, you can do so by editing /etc/sysconfig/apache2 and
  48. # simply write the ulimit commands into that file.
  49. # Example:
  50. # ulimit -n 16384
  51. # ulimit -H -n 16384
  52. # ulimit -c unlimited
  53. # See the output of "help ulimit" in the bash, or "man 1 ulimit".
  54. #
  55. test -s /etc/rc.status && . /etc/rc.status && rc_reset
  56.  
  57. . /usr/share/$pname/load_configuration
  58. export ${!APACHE_*}
  59.  
  60. httpd_conf=${APACHE_HTTPD_CONF:-$sysconfdir/httpd.conf}
  61.  
  62. apache_bin=$(/usr/share/$pname/find_mpm 2>/dev/null)
  63.  
  64. test -L $apache_link && apache_bin=$(readlink $apache_link)
  65.  
  66. if [ -z "$APACHE_MPM" ]; then
  67. APACHE_MPM=${apache_bin##*-}
  68. fi
  69.  
  70. if ! [ -x $apache_bin ]; then
  71. echo >&2 ${warn}$apache_bin-$APACHE_MPM is not a valid httpd2 binary.
  72. echo >&2 Check your APACHE_MPM setting in /etc/sysconfig/$pname. $norm
  73. rc_failed 5
  74. rc_status -v1
  75. rc_exit
  76. fi
  77.  
  78. # a proper home should be set, otherwise the server might end up
  79. # with HOME=/root and some script might try to use that
  80. HOME=$homedir
  81.  
  82. get_server_flags()
  83. {
  84. unset server_flags
  85. case "$action" in startssl) server_flags="-DSSL";; esac
  86. for i in $APACHE_SERVER_FLAGS; do
  87. case $i in
  88. -D) ;;
  89. -D*) server_flags="$server_flags $i";;
  90. *) server_flags="$server_flags -D$i";;
  91. esac
  92. done
  93. }
  94.  
  95. action="$1"
  96. case "$action" in
  97. stop|try-restart|*status*|probe)
  98. ;;
  99. *)
  100. shift; get_server_flags
  101. ${get_module_list_done:=false} || /usr/share/$pname/get_module_list && export get_module_list_done=true
  102. ${get_includes:=false} || /usr/share/$pname/get_includes && export get_includes_done=true
  103. ;;
  104. esac
  105.  
  106. #
  107. # main part
  108. #
  109. case "$action" in
  110. start*)
  111. if [ -e $pidfile ]; then
  112. $0 status &>/dev/null
  113. ret=$?
  114. if [ $ret = 1 ]; then
  115. echo "Warning: found stale pidfile (unclean shutdown?)"
  116. elif [ $ret = 0 ]; then
  117. echo "Apache is already running ($pidfile)"
  118. rc_failed $ret
  119. rc_status -v1
  120. rc_exit
  121. fi
  122. fi
  123.  
  124. echo -n "Starting httpd2 (${APACHE_MPM:-${apache_bin#*-}}) "
  125. cmdline=$(echo $apache_bin -f $httpd_conf $server_flags "$@")
  126. if eval $cmdline -t > $logdir/rc$pname.out 2>&1 ; then
  127. export -n ${!APACHE_*}
  128. eval startproc -f -t ${APACHE_START_TIMEOUT:-2} $cmdline
  129. ret=$?
  130.  
  131. if test -t 1 && stty -a 2>/dev/null | grep -q -- -echo\ ; then
  132. # this means that apache was still waiting for a passphrase to be entered
  133. stty echo 2>/dev/null
  134. echo;echo
  135. echo >&2 An SSL passphrase has not been entered within ${APACHE_START_TIMEOUT:-<not set>} seconds.
  136. echo >&2 To increase this timeout, adjust APACHE_START_TIMEOUT in $sysconfig_apache .
  137. # this surely means that apache won't start, despite it looked good to startproc
  138. killall $apache_bin
  139. echo >&2 "Trying to start the server without SSL (-D NOSSL)."
  140. $0 start "$@" -D NOSSL
  141. # rc_failed 1
  142. # rc_status -v1
  143. # rc_exit
  144. else
  145. rc_failed $ret
  146. rc_status -v
  147. fi
  148. else
  149. if [ "$link" = "$base" ] ; then
  150. cat $logdir/rc$pname.out
  151. echo >&2
  152. echo >&2 The command line was:
  153. echo >&2 $cmdline
  154. echo >&2
  155. else
  156. echo -e -n "\nsee $logdir/rc$pname.out for details\n";
  157. fi
  158. rc_failed 1
  159. rc_status -v1
  160. fi
  161. ;;
  162. stop)
  163. echo -n "Shutting down httpd2 "
  164. if [ ! -f $pidfile -a -f $pidfile.rpmsave ]; then mv $pidfile.rpmsave $pidfile; fi
  165. if ! [ -f $pidfile ]; then
  166. echo -n "(not running)"
  167. else
  168. pid=$(<$pidfile)
  169. # re-read exe symlink, it could be (deleted) in the meanwhile.
  170. apache_bin=$(readlink /proc/$pid/exe 2>/dev/null)
  171. kill -TERM $pid 2>/dev/null
  172. case $? in
  173. 1) echo -n "(not running)";;
  174. 0) # wait until the processes are gone (the parent is the last one)
  175. echo -n "(waiting for all children to terminate) "
  176. for ((wait=0; wait<120; wait++)); do
  177. if test -f $pidfile; then
  178. usleep 500000
  179. continue
  180. fi
  181. if ! test -f /proc/$pid/exe; then
  182. break
  183. fi
  184. if test "$(readlink /proc/$pid/exe 2>/dev/null)" = "$apache_bin"; then
  185. usleep 500000
  186. else
  187. break
  188. fi
  189.  
  190. done
  191. ;;
  192. esac
  193. fi
  194.  
  195. rc_status -v
  196. ;;
  197. stop-graceful)
  198. echo "Shutting down httpd2 gracefully (SIGWINCH)"
  199. if ! [ -f $pidfile ]; then
  200. echo -n "(not running)"
  201. else
  202. pid=$(<$pidfile)
  203. kill -WINCH $pid 2>/dev/null
  204. case $? in
  205. 1) echo -n "(not running)";;
  206. 0) # wait until the pidfile is gone. The parent stays there, but closes the listen ports.
  207. echo -n "(waiting for parent to close listen ports and remove pidfile) "
  208. for ((wait=0; wait<120; wait++)); do
  209. if test -f $pidfile; then
  210. usleep 500000
  211. continue
  212. else
  213. break
  214. fi
  215. done
  216. ;;
  217. esac
  218. fi
  219.  
  220. rc_status -v
  221. ;;
  222. try-restart)
  223. ## Do a restart only if the service was active before.
  224. ## Note: try-restart is now part of LSB (as of 1.9).
  225. ## RH has a similar command named condrestart.
  226. $0 status
  227. if test $? = 0; then
  228. $0 restart
  229. else
  230. rc_reset # Not running is not a failure.
  231. fi
  232. # Remember status and be quiet
  233. rc_status
  234. ;;
  235. restart)
  236. $0 configtest "$@" || { rc_failed $?; rc_exit; }
  237.  
  238. if $0 status &>/dev/null; then
  239. $0 stop
  240. fi
  241. $0 start "$@"
  242. # Remember status and be quiet
  243. rc_status
  244. ;;
  245. restart-hup)
  246. $0 configtest "$@" || { rc_failed $?; rc_exit; }
  247.  
  248. if $0 status &>/dev/null; then
  249. echo -n "Restarting httpd2 (SIGHUP)"
  250. kill -HUP $(<$pidfile) || return=$rc_failed
  251. else
  252. $0 start "$@"
  253. fi
  254. # Remember status and be quiet
  255. rc_status -v
  256. ;;
  257. restart-graceful)
  258. $0 configtest "$@" || { rc_failed $?; rc_exit; }
  259.  
  260. if $0 status &>/dev/null; then
  261. $0 stop-graceful "$@"
  262. $0 start "$@"
  263. else
  264. $0 start "$@"
  265. fi
  266. # Remember status and be quiet
  267. rc_status
  268. ;;
  269. reload|force-reload|graceful)
  270. # check if there is a deleted binary. If there is, then logrotate
  271. # or other occasions will fail to reload, as dlopen(3) of apache
  272. # modules is prone to fail due to symbol mismatches.
  273. # in this case, we only complain and fail.
  274. if [ ! -f $pidfile -a -f $pidfile.rpmsave ]; then mv $pidfile.rpmsave $pidfile; fi
  275. executable=$( readlink /proc/$(cat $pidfile)/exe 2> /dev/null )
  276. case "$executable" in
  277. *httpd*delete*)
  278. echo -n "Reload httpd2 after package update: ignoring request. Please do a manual restart explicitly! "
  279. rc_failed 1
  280. rc_status -v
  281. rc_exit
  282. ;;
  283. *)
  284. ;;
  285. esac
  286.  
  287. echo -n "Reload httpd2 (graceful restart)"
  288.  
  289. cmdline=$(echo $apache_bin -f $httpd_conf $server_flags "$@")
  290. if eval $cmdline -t &> $logdir/rc$pname.out; then
  291. killproc -USR1 $apache_bin || return=$rc_failed
  292. rc_status -v
  293. else
  294. if [ "$link" = "$base" ] ; then
  295. echo -e -n "\n\n"
  296. cat $logdir/rc$pname.out
  297. echo >&2
  298. echo >&2 The command line was:
  299. echo >&2 $cmdline
  300. echo >&2
  301. else
  302. echo -e -n "\nsee $logdir/rc$pname.out for details\n";
  303. fi
  304. rc_failed 6
  305. rc_status -v1
  306. fi
  307. ;;
  308. status)
  309. if [ ! -f $pidfile -a -f $pidfile.rpmsave ]; then mv $pidfile.rpmsave $pidfile; fi
  310. echo -n "Checking for httpd2: "
  311. # we don't use checkproc here since it is confused when we exchange the binaries
  312. if ! [ -f $pidfile ]; then
  313. # not running
  314. rc_failed 3
  315. elif [ -s $pidfile -a -d /proc/$(<$pidfile) ]; then
  316. # running
  317. :
  318. else
  319. # stale pid file
  320. rc_failed 1
  321. #rm -f $pidfile
  322. fi
  323. rc_status -v
  324. ;;
  325. probe)
  326. ## Optional: Probe for the necessity of a reload,
  327. ## give out the argument which is required for a reload.
  328.  
  329. for i in $httpd_conf \
  330. $APACHE_CONF_INCLUDE_FILES \
  331. $APACHE_CONF_INCLUDE_DIRS
  332. do
  333. if [ $i -nt $pidfile ]; then
  334. echo reload
  335. break
  336. fi
  337. done
  338. ;;
  339.  
  340. conf*|test|syntax|check)
  341. cmdline=$(echo $apache_bin -f $httpd_conf $server_flags "$@")
  342. eval $cmdline -t
  343. rc_failed $?
  344. rc_exit
  345. ;;
  346.  
  347. extr*)
  348. cmdline=$(echo $apache_bin -f $httpd_conf $server_flags "$@")
  349. out=$(su - nobody -c "$cmdline" 2>&1)
  350. case $out in
  351. *make_sock:\ could\ not\ bind\ to\ address*) echo Syntax: OK; rc_failed=0;;
  352. *) echo Syntax: NOT OK:; echo $out; rc_failed=1;;
  353. esac
  354. rc_exit
  355. ;;
  356.  
  357. server-status)
  358. apache2ctl status
  359. ;;
  360.  
  361. full-server-status|fullstatus)
  362. apache2ctl fullstatus
  363. ;;
  364.  
  365. *)
  366. cat >&2 <<-EOF
  367. Usage: $0 <command> <server flags>
  368.  
  369. where <command> is one of:
  370. start - start httpd
  371. startssl - start httpd with -DSSL
  372. stop - stop httpd (sending SIGTERM to parent)
  373. try-restart - stop httpd and if this succeeds (i.e. if
  374. it was running before), start it again.
  375.  
  376. status - check whether httpd is running
  377.  
  378. restart - stop httpd if running; start httpd
  379. restart-graceful - stop httpd gracefully if running; start httpd
  380. reload|graceful - do a graceful restart by sending a SIGUSR1, or
  381. start if not running
  382. stop-graceful - stop httpd (sending SIGWINCH to parent)
  383.  
  384. configtest - do a configuration syntax test
  385. extreme-configtest - try to run httpd as nobody (detects more errors
  386. by actually loading the configuration, but cannot
  387. read SSL certificates)
  388. probe - probe for the necessity of a reload, give
  389. out the argument which is required for a reload.
  390. (by comparing conf files with pidfile timestamp)
  391.  
  392. full-server-status - dump a full status screen; requires lynx or w3m
  393. and mod_status enabled
  394. server-status - dump a short status screen; requires lynx or w3m
  395. and mod_status enabled
  396.  
  397. help - this screen
  398.  
  399. optional server flags are passed through to httpd.
  400.  
  401. EOF
  402. exit 1
  403. esac
  404.  
  405.  
  406. # Inform the caller not only verbosely and set an exit status.
  407. rc_exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement