home *** CD-ROM | disk | FTP | other *** search
/ linuxmafia.com 2016 / linuxmafia.com.tar / linuxmafia.com / pub / linux / security / mkchroot < prev    next >
Text File  |  2003-09-18  |  18KB  |  658 lines

  1. #!/bin/sh
  2.  
  3. ### This script can help create chrooted environment. 
  4. ### It was tested ONLY WITH APACHE (with mod_ssl) AND PERL,
  5. ### but at the end of
  6. ### it you will find big section "apllication specific".
  7. ### So if you will chroot something else (proftpd, ldap,
  8. ### or what you want) you can add aplication specific 
  9. ### part to the end of this script (if needed).
  10. ### In example apache needs /etc/mime.types to be copied
  11. ### but this is NOT a part of apache package. So at the
  12. ### end script just tests if package name is apache, and copies
  13. ### this file to new chroot.
  14. ###
  15. ### It works ONLY WITH DEBIAN (because of package system),
  16. ### and was tested ONLY WITH DEBIAN 3.0 (because I have no other :-).
  17. ### Use it on your own risk.
  18. ### 
  19. ### What it does. It takes two arguments:
  20. ### debian package name;
  21. ### chroot directory.
  22. ### It makes some tests and asks you about configuration.
  23. ### Then it copies some files, libraries and devices to
  24. ### new chroot (you can add or remove if needed [lines 302-309]).
  25. ### When package files are copied, script looks what libraries are 
  26. ### needed. After libraries are copied it goes to application
  27. ### specific section. For apache it can create startup script
  28. ### which you may copy to /etc/init.d/apache *(real path, not
  29. ### a chroot)*, so your chrooted apache can start at startup.
  30. ###
  31. ### USAGE NOTES
  32. ###
  33. ### Usage: this_script package_name chroot_dir
  34. ### I.e. if you need chrooted apache, do:
  35. ### dpkg -l | grep apache
  36. ### and look what packages you need.
  37. ### I took apache, apache-common, libapache-mod-ssl.
  38. ### (./mkchroot apache /var/chroot/apache
  39. ###  ./mkchroot apache-common /var/chroot/apache
  40. ###  ./mkchroot libapache-mod-ssl /var/chroot/apache )
  41. ### 
  42. ### So you MUST run this scipt for EACH package once.
  43. ### For perl I took perl-base and perl.
  44. ### 
  45. ### UPGRADES OF CHROOTED APPLICATIONS
  46. ###
  47. ### You can upgrade (apt-get upgrade package) package you need
  48. ### BUT BE SURE, YOU HAVE EXACT WORKING CONFIGURATION OUTSIDE
  49. ### THE JAIL. In other case, configuration, ssl-keys, etc. will
  50. ### be OVERWRITTEN!
  51. ###
  52. ### LICENCE. You can use, modify, distribute this script, 
  53. ### but leave my name in authors section.
  54. ### 
  55. ###
  56. ### Written by Martynas Domarkas (OTPABA) md@hansa.lt 2003 01 05.
  57. ###
  58. ### I DO NOT SUPPORT ANY SOFTWARE, so I'm not sure I'll answer
  59. ### your questions :-)
  60. ###
  61. ### Last note: this script does NOT check any package dependencies.
  62. ### The point is, that i.e. if you want a chrooted apache, debian package
  63. ### depends on perl. But if you find perl buggy or just hate it (like I do)
  64. ### you will not use cgi's written in perl, and no mod_perl of course. 
  65. ### Then you need no perl package in your chroot! ;-)
  66.  
  67. ### 2003 09 19     changed function file_list_for_tar(). There was a bug when copying
  68. ###        targets of symlinks.
  69. ###        Reported by Marc Lubarsky.
  70.  
  71. ### 2003 09 19    added copying of /etc/hosts.
  72.  
  73.  
  74.  
  75.  
  76. CHRPACK=$1
  77. CHROOTD=$2
  78. clear
  79. ### Function "Print how to use" ###
  80. usage() {
  81. echo "
  82.     Usage:
  83.     $0 package_name chroot_dir
  84. "
  85. }
  86. #################################
  87.  
  88. ### Check for command invocation syntax ###
  89. if [ "$CHRPACK" == "" ] || [ "$CHROOTD" == "" ]; then
  90. usage   # Function from above
  91. exit 1
  92. fi
  93. ###########################################
  94.  
  95.  
  96. ### Ask some stupid questions, but it's better than README ;-)) ###
  97. echo "
  98.     1) Did you read what is written in head of this file?
  99.  
  100.     2) Package you are chrooting is installed using debian tools
  101.     and *CONFIGURED* ? 
  102.         (if you upgrade your system and try mkchroot
  103.     again without actual configuration you currently have in chroot
  104.         YOU WILL LOSE YOUR CONFIGURATION!)
  105.         
  106.     3) Is this machine running Linux Debian 3.0 ?
  107.     4) Do you know what does it mean \"chroot\" at all?
  108.     5) Do you have dpkg, gawk (awk), tar, file, grep, egrep, ldd, mkdir in your PATH?
  109.  
  110.     If all 5 answers was \"YES!!!!\", then press ENTER. If not, better press ctrl-C
  111.     and read beggining of this script.
  112. "
  113. read junk
  114. ##############################################################
  115.  
  116. ### Check for user ###
  117. if [ `id -u` -ne 0 ]; then
  118. echo "
  119. You are not root. 
  120. It is possible, that you will not be able access some files."
  121. echo -n "
  122. Do you want to continue? [y/n] : "
  123.     read ANS
  124.     if [ "$ANS" != "y" ]; then
  125.     echo "OK, exiting..."
  126.     exit 0
  127.     fi
  128. fi
  129. #####################
  130.  
  131.  
  132. #################### FUNCTIONS ####################
  133.  
  134. ### Function for checking of command existence ###
  135. ### It will be used to be sure that we can continue running this script ###
  136. cmd_exist() {
  137. which $1 > /dev/null
  138. if [ $? -ne 0 ]; then
  139. echo "Command \"$1\" not found"
  140. echo "Exiting..."
  141. exit 1
  142. fi
  143. }
  144.  
  145. ### Function for getting needed libraries for package ###
  146. ### It uses list of files given by "dpkg -L $PACKAGE" looks for executables and prints out 
  147. ### file names of needed libraries
  148. get_libs_for_pack() {
  149. dpkg -L $CHRPACK | while read GLFP
  150. do
  151. if [ ! -d $GLFP ]; then
  152. file $GLFP|egrep "(ELF.*executable|ELF.*shared obj)" > /dev/null
  153. if [ $? -eq 0 ]; then
  154. ldd $GLFP | $AWK '{ print $3 }'; fi; fi; done | sort -u
  155. }
  156. #########################################################
  157.  
  158. ### Function for getting needed libraries for file 
  159. ### (same as above but this takes as argument just one file
  160. get_libs_for_file() {
  161. file $1 | egrep "(ELF.*executable|ELF.*shared obj)" > /dev/null
  162. if [ $? -eq 0 ]; then
  163. ldd $1 | $AWK '{ print $3 }'; fi
  164. }
  165. ######################################################
  166.  
  167. ### Function for checking if library does NOT exist in chroot ###
  168. check_lib_for_exsist() {
  169. while read CLFN
  170. do
  171. if [ ! -e $CHROOTD/$CLFN ]; then
  172. echo $CLFN
  173. fi
  174. done
  175. }
  176. #################################################################
  177.  
  178. ### Function to prepare list of files for tar ###
  179. ### It checks for symlinks, targets and it's output is one single space separated line ###
  180.  
  181. file_list_for_tar() {
  182. while read FLFT
  183. do
  184.  
  185. # Check for accidental newline
  186. if [ ! -z $FLFT ]; then
  187.  
  188. # You will ask me why I cycle again. It is because I like "break" more than "else" :-)
  189. file $FLFT | while read LO
  190. do
  191.  
  192. # Check if the file exist
  193. if [ ! -f "$FLFT" ]; then
  194. break
  195. fi
  196.  
  197. # Output filename to stdout (other functions will read this)
  198. echo -n "$FLFT "
  199.  
  200. # Is it a symlink?
  201. echo $LO | grep "sym.*link" > /dev/null
  202. if [ $? -eq 0 ]; then
  203.  
  204. # Symlinks often are made with realative path. So we need know WHERE the symlink is.
  205. prefdir=`dirname $FLFT`
  206. TG=`echo $LO | $AWK '{ print $NF }'`
  207. # Is the path absolute (absolute paths allways begisn with a "/")
  208. echo "$TG" | grep "^/" > /dev/null
  209.     if [ $? -eq 0 ]; then
  210.     TGF=$TG
  211.     else
  212.     # Path to target was realative - adding directory prefix.
  213.     TGF=$prefdir/$TG
  214.     fi
  215.     
  216.     # Shit happens... :-)
  217.     if [ ! -f "$FLFT" ]; then
  218.     break
  219.     fi
  220.     
  221. echo -n "$TGF "
  222. fi
  223. done
  224.  
  225. fi
  226. done
  227. }
  228.  
  229. ### Old one. Buggy.
  230. #file_list_for_tar() {
  231. #while read FLFT
  232. #do
  233. #file $FLFT | $AWK '{ gsub(/:$/, "", $1); print }' | while read LO
  234. #    do
  235. #    prefdir=`echo $LO | $AWK -F"/" '{ ORS=""; for(i=2; i<NF; i++) { print "/" $i } } END { print "/" }'`
  236. #    echo $LO|grep "sym.*link" > /dev/null
  237. #        if [ $? -eq 0 ]; then
  238. #        echo $LO | $AWK '{ ORS=" "; print $1 }'
  239. #        TG=`echo $LO | $AWK '{ print $NF }'`
  240. #        TGF=`find "$prefdir" -name "$TG"`
  241. #        echo -n "$TGF "
  242. #        else
  243. #        echo $LO | $AWK '{ ORS=" "; print $1 }'
  244. #        fi
  245. #    done
  246. #done
  247. #}
  248. ###################################################################################
  249.  
  250. ### Function for copy given files to chroot ###
  251. cp_to_chroot() {
  252. read CTC
  253. if [ ! -z "$CTC" ]; then
  254. cd $CHROOTD
  255. tar cvf - $CTC | tar xf -
  256. fi
  257. }
  258. ##############################################
  259.  
  260. ### Function to copy single commands (binaries) with libraries to chroot ###
  261. cp_cmd_to_chroot() {
  262. CMD=$1
  263. if [ ! -z "$CMD" ]; then
  264.     if [ -f "$CMD" ]; then
  265.     get_libs_for_file $CMD | check_lib_for_exsist | file_list_for_tar | cp_to_chroot
  266.         if [ ! -f $CHROOTD/$CMD ]; then
  267.         cd $CHROOTD
  268.         tar cvf - "$CMD" | tar xf -
  269.         fi
  270.     else
  271.     echo "$CMD does not exist"
  272.     exit 1
  273.     fi
  274. else
  275. echo "Error"
  276. exit 1
  277. fi
  278. }
  279.  
  280. ############### END OF FUNCTIONS ####################
  281.  
  282. ### OK lets begin! ###
  283.  
  284. ### Looking for needed software ###
  285. ### GAWK: ###
  286. which gawk > /dev/null
  287. if [ $? -ne 0 ]; then
  288.     which awk > /dev/null
  289.     if [ $? -ne 0 ]; then
  290.     echo "gawk or awk not found in your PATH"
  291.     echo "Exiting..."
  292.     exit 1
  293.     else
  294.     echo "Found awk instead of gawk. I'll try to use it..."
  295.     AWK=`which awk`
  296.     fi
  297. else
  298. #echo "gawk found. Excelent!"
  299. AWK=`which gawk`
  300. fi
  301.  
  302. cmd_exist file
  303. cmd_exist ldd
  304. cmd_exist dpkg
  305. cmd_exist grep
  306. cmd_exist egrep
  307. cmd_exist mkdir
  308. cmd_exist tar
  309. cmd_exist dirname
  310.  
  311. ### At this point we should be sure, that we found all software needed ###
  312.  
  313. ### Looking for package beeing chrooted ###
  314. dpkg -L $CHRPACK > /dev/null 2>&1
  315. if [ $? -ne 0 ]; then
  316. echo "
  317.     dpkg can not find package \"$CHRPACK\".
  318.     If you mistyped command, start $0 again with correct arguments
  319.     Be sure you installed it using usual Debian way (apt-get, dpkg -i, tasksel, dselect...)
  320.     Exiting..."
  321. exit 1
  322. fi
  323. ###########################################
  324.  
  325. ### Create new chroot or use an existing directory? ###
  326. if [ -e $CHROOTD ]; then
  327.     if [ ! -d $CHROOTD ]; then
  328.     echo "$CHROOTD exist and it is NOT a directory"
  329.     echo "Exiting..."
  330.     exit 1
  331.     else
  332.     echo -n "$CHROOTD exist. Should I use it? [y/n] : "
  333.         read ANS
  334.         if [ "$ANS" != "y" ]; then
  335.         echo "Exiting..."
  336.         exit 1
  337.         fi
  338.     fi
  339. else
  340. mkdir -p $CHROOTD
  341. fi
  342. ########################################################
  343.  
  344.  
  345. ### Minimal set of files so you can do 'chroot /your/dir' ###
  346. ### (ls, cat, tail, strace, less is also added for debuging) ###
  347.  
  348. echo "
  349. Creating minimal chroot environment...
  350. "
  351. cp_cmd_to_chroot /bin/sh
  352. cp_cmd_to_chroot /bin/bash
  353. cp_cmd_to_chroot /bin/ls
  354. cp_cmd_to_chroot /bin/cat
  355. cp_cmd_to_chroot /usr/bin/strace
  356. cp_cmd_to_chroot /usr/bin/less
  357. cp_cmd_to_chroot /usr/bin/tail
  358.  
  359. ### Little stupid hack. Without "libnss_files.so" apache can not read /etc/passwd for "User" directive 
  360. ### but no binaries or modules ar linked with it...
  361. echo /lib/libnss_files.so.2 | check_lib_for_exsist | file_list_for_tar | cp_to_chroot
  362.  
  363. ### Some directories and files that we will need ###
  364. mkdir -p $CHROOTD/var/run
  365. mkdir -p $CHROOTD/var/lock
  366. mkdir -p $CHROOTD/var/log
  367. mkdir -p $CHROOTD/proc
  368. mkdir -p $CHROOTD/dev
  369. mkdir -p $CHROOTD/etc
  370.  
  371. cp -apR /dev/null $CHROOTD/dev
  372. cp -apR /dev/random $CHROOTD/dev
  373. cp -apR /dev/urandom $CHROOTD/dev
  374. cp -apR /dev/zero $CHROOTD/dev
  375. cp -ap /etc/hosts $CHROOTD/etc
  376.  
  377. ############## END OF MINIMAL CHROOT ####################
  378.  
  379. ### We also need an /etc/passwd and /etc/group ###
  380. ### At this moment we add user root to $CHROOTD/etc/passwd 
  381. ### and group root to $CHROOTD/etc/group
  382. ### You will be asked later for application specific user and group 
  383. if [ ! -f $CHROOTD/etc/passwd ]; then
  384. grep "^root:" /etc/passwd > $CHROOTD/etc/passwd
  385. else
  386. grep "^root:" $CHROOTD/etc/passwd > /dev/null
  387.     if [ $? -ne 0 ]; then
  388.     echo "No entry for user root found in your chrooted /etc/passwd"
  389.     echo -n "Do you want me to add one? [y/n] : "
  390.     read ANS
  391.         if [ "$ANS" != "y" ]; then
  392.         echo "OK, no root - no problems"
  393.         else
  394.         grep "^root:" /etc/passwd >> $CHROOTD/etc/passwd
  395.         fi
  396.     fi
  397. fi
  398.  
  399. if [ ! -f $CHROOTD/etc/group ]; then
  400. grep "^root:" /etc/group > $CHROOTD/etc/group
  401. else
  402. grep "^root:" $CHROOTD/etc/group > /dev/null
  403.     if [ $? -ne 0 ]; then
  404.     echo "No entry for user root found in your chrooted /etc/group"
  405.     echo -n "Do you want me to add one? [y/n] : " 
  406.     read ANS
  407.         if [ "$ANS" != "y" ]; then
  408.         echo "OK, no root - no problems"
  409.         else
  410.         grep "^root:" /etc/group >> $CHROOTD/etc/group
  411.         fi
  412.     fi
  413. fi
  414. ##################################################
  415.  
  416. ### We have passwd and group files. Now we need copy some system users and groups to jail ###
  417. while [ true ]
  418. do
  419. sleep 1
  420. clear
  421.  
  422. echo "
  423.     You will need a part of /etc/passwd for your software to run.
  424.     In most cases apache run under www-data, bind under bind. But I have no idea
  425.     what is your setup. So, now you can enter username you need in chroot and
  426.     press ENTER. 
  427.     
  428.     If you DO NOT need any user enter NoMore.
  429. "
  430. echo -n "User to add to $CHROOTD/etc/passwd : "
  431.  
  432. read USRN
  433. if [ ! -z "$USRN" ]; then
  434.     if [ "$USRN" != "NoMore" ]; then
  435.         grep "^$USRN:" /etc/passwd > /dev/null
  436.         if [ $? -eq 0 ]; then
  437.             grep "^$USRN:" $CHROOTD/etc/passwd 1>/dev/null 2>/dev/null
  438.             if [ $? -ne 0 ]; then
  439.             grep "^$USRN:" /etc/passwd >> $CHROOTD/etc/passwd
  440.             echo ""
  441.             echo -e "\tUser $USRN added"
  442.             echo ""
  443.             echo -e "\tPress ENTER to continue"
  444.             read junk
  445.             else
  446.             echo ""
  447.             echo -e "\t$USRN already is in your $CHROOTD/etc/passwd"
  448.             echo ""
  449.             echo -e "\tPress ENTER to continue"
  450.             read junk
  451.             fi
  452.         else
  453.         echo ""
  454.         echo -e "\t$USRN does not exist in your system"
  455.         echo ""
  456.         echo -e "\tPress ENTER to continue"
  457.         read junk 
  458.         fi
  459.     else
  460.     echo "OK... Continuing"
  461.     break
  462.     fi
  463. else
  464. echo -e "
  465. \tEnter an existing system user or NoMore if you wan't quit adding users to chroot"
  466. echo -e "
  467. \tPress ENTER to continue"
  468. read junk 
  469. fi
  470. done
  471.  
  472.  
  473. while [ true ]
  474. do
  475. sleep 1
  476. clear
  477.  
  478. echo "
  479.     OK, for we have user file. Now repeat the same with groups.
  480.     
  481.     Now you can enter groupname you need in chroot and
  482.     press ENTER. 
  483.     
  484.     If you DO NOT need any group enter NoMore.
  485. "
  486. echo -n "Group to add to $CHROOTD/etc/group : "
  487.  
  488. read GRPN
  489. if [ ! -z "$GRPN" ]; then
  490.     if [ "$GRPN" != "NoMore" ]; then
  491.         grep "^$GRPN:" /etc/group > /dev/null
  492.         if [ $? -eq 0 ]; then
  493.             grep "^$GRPN:" $CHROOTD/etc/group 1>/dev/null 2>/dev/null
  494.             if [ $? -ne 0 ]; then
  495.             grep "^$GRPN:" /etc/group >> $CHROOTD/etc/group
  496.             echo ""
  497.             echo -e "\tGroup $GRPN added"
  498.             echo ""
  499.             echo -e "\tPress ENTER to continue"
  500.             read junk
  501.             else
  502.             echo ""
  503.             echo -e "\t$GRPN already is in your $CHROOTD/etc/group"
  504.             echo ""
  505.             echo -e "\tPress ENTER to continue"
  506.             read junk
  507.             fi
  508.         else
  509.         echo ""
  510.         echo -e "\t$GRPN does not exist in your system"
  511.         echo ""
  512.         echo -e "\tPress ENTER to continue"
  513.         read junk 
  514.         fi
  515.     else
  516.     echo "OK... Continuing"
  517.     break
  518.     fi
  519. else
  520. echo -e "
  521. \tEnter an existing system group or NoMore if you wan't quit adding groups to chroot"
  522. echo -e "
  523. \tPress ENTER to continue"
  524. read junk 
  525. fi
  526. done
  527.  
  528. ##################################################################################
  529.  
  530. ### Package files. Taken from dpkg -L $PACKAGE without doc's and manuals ###
  531. echo "
  532. Copying package files to $CHROOTD:
  533. "
  534. cd $CHROOTD
  535. LIST=`dpkg -L $CHRPACK | grep -v "share/[man|doc]" | while read F
  536. do
  537. if [ ! -d $F ]; then
  538. echo -n "$F "
  539. else
  540. if [ ! -d $CHROOTD/$F ]; then
  541. mkdir -p $CHROOTD/$F > /dev/null 2>&1
  542. fi
  543. fi
  544. done`
  545. tar cvf - $LIST| tar xf -
  546. #########################################
  547.  
  548. echo "
  549. Copying libraries needed by $CHRPACK...
  550. "
  551. get_libs_for_pack | check_lib_for_exsist | file_list_for_tar | cp_to_chroot
  552.  
  553.  
  554. ### Package specific... APACHE ###
  555. if [ "$CHRPACK" = "apache" ]; then
  556.     if [ ! -d $CHROOTD/etc/apache ]; then
  557.     cd $CHROOTD
  558.     tar cvf - /etc/apache | tar xf -
  559.     else
  560.     cp -apuRi /etc/apache/* $CHROOTD/etc/apache
  561.     fi
  562.  
  563.     if [ ! -f $CHROOTD/etc/mime.types ]; then
  564.     cp -ap /etc/mime.types $CHROOTD/etc
  565.     fi
  566. echo "
  567.     If you are running Debian 3.0, I can try provide startup script for you.
  568.     It will be placed as /tmp/chrooted.apache.spartup.sh. You will need only
  569.     chmod 750 /tmp/chrooted.apache.spartup.sh
  570.     and
  571.     /tmp/chrooted.apache.spartup.sh start
  572. "
  573. echo -n "Do you want try this script? [y/n] : "
  574. read ANS
  575. if [ "$ANS" = "y" ]; then
  576. STARTUPFILE=/tmp/chrooted.apache.spartup.sh
  577. rm $STARTUPFILE
  578. echo "#!/bin/bash" >> $STARTUPFILE
  579. echo "#" >> $STARTUPFILE
  580. echo "# apache    Start the apache HTTP server." >> $STARTUPFILE
  581. echo "#" >> $STARTUPFILE
  582. echo "" >> $STARTUPFILE
  583. echo "CHRDIR=$CHROOTD" >> $STARTUPFILE
  584. echo "" >> $STARTUPFILE
  585. echo "NAME=apache" >> $STARTUPFILE
  586. echo "PATH=/bin:/usr/bin:/sbin:/usr/sbin" >> $STARTUPFILE
  587. echo "DAEMON=/usr/sbin/apache" >> $STARTUPFILE
  588. echo "SUEXEC=/usr/lib/apache/suexec" >> $STARTUPFILE
  589. echo "PIDFILE=/var/run/\$NAME.pid" >> $STARTUPFILE
  590. echo "CONF=/etc/apache/httpd.conf" >> $STARTUPFILE
  591. echo "APACHECTL=/usr/sbin/apachectl " >> $STARTUPFILE
  592. echo "" >> $STARTUPFILE
  593. echo "trap \"\" 1" >> $STARTUPFILE
  594. echo "export LANG=C" >> $STARTUPFILE
  595. echo "export PATH" >> $STARTUPFILE
  596. echo "" >> $STARTUPFILE
  597. echo "test -f \$DAEMON || exit 0" >> $STARTUPFILE
  598. echo "test -f \$APACHECTL || exit 0" >> $STARTUPFILE
  599. echo "" >> $STARTUPFILE
  600. echo "# ensure we don't leak environment vars into apachectl" >> $STARTUPFILE
  601. echo "APACHECTL=\"env -i LANG=\${LANG} PATH=\${PATH} \$APACHECTL\"" >> $STARTUPFILE
  602. echo "" >> $STARTUPFILE
  603. echo "if egrep -q -i \"^[[:space:]]*ServerType[[:space:]]+inet\" \$CONF" >> $STARTUPFILE
  604. echo "then" >> $STARTUPFILE
  605. echo "    exit 0" >> $STARTUPFILE
  606. echo "fi" >> $STARTUPFILE
  607. echo "" >> $STARTUPFILE
  608. echo "case \"\$1\" in" >> $STARTUPFILE
  609. echo "  start)" >> $STARTUPFILE
  610. echo "    echo -n \"Starting web server: \$NAME\"" >> $STARTUPFILE
  611. echo "    mount -t proc proc $CHROOTD/proc" >> $STARTUPFILE
  612. echo "    start-stop-daemon --start --pidfile \$PIDFILE --exec \$DAEMON --chroot \$CHRDIR" >> $STARTUPFILE
  613. echo "    ;;" >> $STARTUPFILE
  614. echo "" >> $STARTUPFILE
  615. echo "  stop)" >> $STARTUPFILE
  616. echo "    echo -n \"Stopping web server: \$NAME\"" >> $STARTUPFILE
  617. echo "    start-stop-daemon --stop --pidfile \$CHRDIR/\$PIDFILE --oknodo" >> $STARTUPFILE
  618. echo "    umount $CHROOTD/proc" >> $STARTUPFILE
  619. echo "    ;;" >> $STARTUPFILE
  620. echo "" >> $STARTUPFILE
  621. echo "  reload)" >> $STARTUPFILE
  622. echo "    echo -n \"Reloading \$NAME configuration\"" >> $STARTUPFILE
  623. echo "    start-stop-daemon --stop --pidfile \$CHRDIR/\$PIDFILE --signal USR1 --exec \$DAEMON --chroot \$CHRDIR" >> $STARTUPFILE
  624. echo "    ;;" >> $STARTUPFILE
  625. echo "" >> $STARTUPFILE
  626. echo "  reload-modules)" >> $STARTUPFILE
  627. echo "    echo -n \"Reloading \$NAME modules\"" >> $STARTUPFILE
  628. echo "    start-stop-daemon --stop --pidfile \$CHRDIR/\$PIDFILE --oknodo --retry 30" >> $STARTUPFILE
  629. echo "    start-stop-daemon --start --pidfile \$PIDFILE --exec \$DAEMON --chroot \$CHRDIR" >> $STARTUPFILE
  630. echo "    ;;" >> $STARTUPFILE
  631. echo "" >> $STARTUPFILE
  632. echo "  restart)" >> $STARTUPFILE
  633. echo "    \$0 reload-modules" >> $STARTUPFILE
  634. echo "    exit \$?" >> $STARTUPFILE
  635. echo "    ;;" >> $STARTUPFILE
  636. echo "" >> $STARTUPFILE
  637. echo "  force-reload)" >> $STARTUPFILE
  638. echo "    \$0 reload-modules" >> $STARTUPFILE
  639. echo "    exit \$?" >> $STARTUPFILE
  640. echo "    ;;" >> $STARTUPFILE
  641. echo "" >> $STARTUPFILE
  642. echo "  *)" >> $STARTUPFILE
  643. echo "    echo \"Usage: /etc/init.d/\$NAME {start|stop|reload|reload-modules|force-reload|restart}\"" >> $STARTUPFILE
  644. echo "    exit 1" >> $STARTUPFILE
  645. echo "    ;;" >> $STARTUPFILE
  646. echo "esac" >> $STARTUPFILE
  647. echo "" >> $STARTUPFILE
  648. echo "if [ \$? == 0 ]; then" >> $STARTUPFILE
  649. echo "    echo ." >> $STARTUPFILE
  650. echo "    exit 0" >> $STARTUPFILE
  651. echo "else" >> $STARTUPFILE
  652. echo "    echo failed" >> $STARTUPFILE
  653. echo "    exit 1" >> $STARTUPFILE
  654. echo "fi" >> $STARTUPFILE
  655. fi
  656. fi
  657.  
  658.