Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
nifty shell script for starting apache+mysql in chroot jails
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
paradox508
Tux's lil' helper
Tux's lil' helper


Joined: 18 Mar 2003
Posts: 79
Location: Chicago, IL

PostPosted: Sun Sep 21, 2003 4:53 am    Post subject: nifty shell script for starting apache+mysql in chroot jails Reply with quote

ok i wrote this to automate the starting of my apache1.3.28/PHP/SSL and mysql in chroot jails.
Apache and Mysql are in thier own seperate jails.
apache1.3.28 w/ SSL + PHP was installed from source into /chroot/www/apache
mysql was installed from binary distribution from mysql.org in /chroot/mysql/usr/local/mysql

here is the script. Enjoy
Code:

#!/bin/bash

#lets set up some variables here...

MYSQLUSER="mysql"
APACHECHROOTPATH="/chroot/www"
APACHEPATH="/apache"
MYSQLCHROOTPATH="/chroot/mysql"
MYSQLPATH="/usr/local/mysql"
STATUS="0"
SOCKET="/mysql.sock"
SOCKETPATH="${MYSQLCHROOTPATH}/tmp"
SOCKETLINKPATH="${APACHECHROOTPATH}/tmp"
#end of config section...


#creates hardlink from mysql's socket to the apache/php chroot path
linkSock(){
sleep 5
     echo "Creating Socket Link from ${SOCKETPATH}${SOCKET} to ${SOCKETLINKPATH}"
if test -a ${SOCKETPATH}${SOCKET}
then
ln ${SOCKETPATH}${SOCKET} ${SOCKETLINKPATH}${SOCKET}
         echo "Done!"
else
   echo "Error Linking: Source ${SOCKETPATH}${SOCKET} does not exist!"
   echo "Check that Mysqld is running and that it configured to use local sockets"
fi
}

#checks to make sure mysql cleaned up its socket after it exits, if not it removes it
cleanUp(){
   echo -n "Cleaning up...     "

if test -a ${SOCKETLINKPATH}${SOCKET} ; then
      
   echo -n "Deleting hardlink ${SOCKETLINKPATH}${SOCKET}...     "
   
rm -rf ${SOCKETLINKPATH}${SOCKET} || { $STATUS="1"; echo "Error Deleting ${SOCKETLINKPATH}${SOCKET}!!!";exit 1;}
   
   echo  "Done.";
else
   echo "Nothing to cleanup."
fi
echo
}
startDynamicWeb(){
   echo "Starting Dynamic-Web..."
echo -n "Starting Mysql Daemon...     "
      chroot ${MYSQLCHROOTPATH} ${MYSQLPATH}/bin/mysqld nice --user=${MYSQLUSER} &
         echo "Done!"

echo -n "Starting Apache Daemon with SSL and PHP support...     "
      chroot ${APACHECHROOTPATH} ${APACHEPATH}/bin/apachectl startssl  &
         echo "Done!"
linkSock

echo "Dynamic-Web is Running... Have Fun!"

}

stopDynamicWeb(){
   echo "Bringing down Dynamic-Web..."
       echo
      
      echo -n "Taking down Apache...     "
         ${APACHEPATH}/bin/apachectl stop >/dev/null 2>&1 &
            echo "Done!"
      
      echo -n "Taking down Mysql...     "
         nohup killall mysqld >/dev/null 2>&1 &
                echo "Done!"
cleanUp
   echo "Dynamic-Web is Stopped."
}

case $1 in
start)
startDynamicWeb
;;
stop)
stopDynamicWeb
;;
restart)
stopDynamicWeb
startDynamicWeb
;;
cleanup)
cleanUp
;;
*)
echo "Usage: ./dynamic-web { start | stop | restart | cleanup }"
;;
esac

if [ "$STATUS" = "1" ];then
   exit 1;
else
   exit 0;
fi


just copy/paste into your favorite editor and save as "dynamic-web"
i put mine in /etc/dynamic-web/
i also wrote a nifty little rc-script wrapper for it

Code:

#!/sbin/runscript


depend(){
need net
}
start(){
ebegin "starting dynamic-web"
/etc/dynamic-web/dynamic-web start
eend $?
}
stop(){
ebegin "Stopping dynamic-web"
/etc/dynamic-web/dynamic-web stop
eend $?
}
restart(){
ebegin "Restarting dynamic-web"
/etc/dynamic-web/dynamic-web restart
eend $?
}
cleanup(){
ebegin "Cleaning up dynamic-web"
/etc/dynamic-web/dynamic-web cleanup
eend $?
}


Pax Universalis
'Dox
Back to top
View user's profile Send private message
someguy
Guru
Guru


Joined: 10 Jul 2003
Posts: 433
Location: (-_-) .::OH_WELL::. (-_-)

PostPosted: Fri Dec 17, 2004 6:59 am    Post subject: Reply with quote

hey buddy can you help me with this i would REALLY like to get my apache service running correctly once again with my forum
im running your script and im getting this i can give you more info tomm at work

Starting Dynamic-Web...
Starting Mysql Daemon... Done!
Starting Apache Daemon with SSL and PHP support... Done!
chroot: cannot run command `/usr/bin/mysql/bin/mysqld': Not a directory
chroot: cannot run command `/apache/bin/apachectl': No such file or directory
Creating Socket Link from /chroot/mysql/tmp/mysql.sock to /chroot/apache/www/tmp
Error Linking: Source /chroot/mysql/tmp/mysql.sock does not exist!
Check that Mysqld is running and that it configured to use local sockets
Dynamic-Web is Running... Have Fun[/code]
_________________
print pack"C*",split/\D+/,`echo "16iII*o\U@{$/=$z;[(pop,pop,unpack"H*",<>
)]}\EsMsKsN0[lN*1lK[d2%Sa2/d0<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<J]dsJxp"|dc`
while [ 1 ] ; do echo "*" | telnet ip.of.print.er 9100 ; done
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum