a30cf25e9a9a06add0246473e90a42333106c7ac max Tue Jan 12 12:21:16 2016 -0800 fixing virtualbox auto-detect and skipping inno-db to save RAM, refs #16616 diff --git src/browserbox/root/updateBrowser.sh src/browserbox/root/updateBrowser.sh index 1bf3466..2e89800 100755 --- src/browserbox/root/updateBrowser.sh +++ src/browserbox/root/updateBrowser.sh @@ -35,82 +35,94 @@ # rsync options: # l = preserve symlinks # t = preserve time # r = recurse # z = compress # v = verbose # h = human readable # u = skip if file is newer on receiver RSYNCOPTS="-ltrzvh" # rsync server for CGIs and html files RSYNCSRC="rsync://hgdownload.cse.ucsc.edu" RSYNCCGIBIN=cgi-bin RSYNCHTDOCS=htdocs UPDATEFLAG=http://hgdownload.cse.ucsc.edu/gbib/lastUpdate LOGFILE=/var/log/gbibUpdates.log +DEBUG=0 +if [[ "$#" -ne 0 ]]; then + DEBUG=1 +fi + +# function to echo only if run with some arguments +function echoDebug { + if [[ DEBUG -eq "1" ]]; then + echo $* + fi +} # make sure that apt-get never opens an interactive dialog export DEBIAN_FRONTEND=noninteractive # help if [ "$1" == "-h" ] ; then echo "Without any options, this script checks if it can reach hgdownload and if " echo "new data has been added since the last run. It updates itself and runs the new copy." echo "The new copy rsyncs the CGIs/MysqlDbs/htdocs from hgdownload." echo "It rsyncs the gbib/push directory into / to update other files." echo "It finally repairs mysql tables, makes some trackDb changes, adds symlinks," echo "and chmods the directories." echo "Parameters:" echo "updateBrowser.sh notSelf - do not update the script itself. Do not check if data has been " echo " added to hgdownload since the last run" echo "updateBrowser.sh hgwdev - more info on how to update to alpha versions (used only by UCSC)" exit 0 fi # check if running as root if [ "$(id -u)" != "0" ] ; then echo "This script must be run as root" 1>&2 exit 1 fi # check if running already, 3 = the main script + its update + the subshell where this command is running RUNNING=`ps --no-headers -CupdateBrowser.sh | wc -l` if [ ${RUNNING} -gt 3 ] ; then - #echo update already running + echoDebug GBiB update already running, not starting exit 2 fi -# check if the VirtualBox guest addition kernel modules work and if yes, if auto-updates were -# deactivated from the Vbox host via a property +# if run with no argument (=from cron): check if the VirtualBox guest addition +# kernel modules work and if yes, if auto-updates were deactivated from the +# Vbox host via a property +if [ "$#" -eq 0 ] ; then if modprobe vboxguest 2> /dev/null > /dev/null; then if VBoxControl guestproperty get gbibAutoUpdateOff | grep -xq "Value: yes" 2> /dev/null ; then exit 6 - # exit only if no argument specified on command line = run from cronjob - if [ "$#" -eq 0 ] ; then - exit 6 fi fi +# show a little note when VirtualBox kernel module is not working and we're not running under cron else - # only show this notice when run with a command line argument (=not from cron) - if [ "$#" -ne 0 ] ; then - echo - Info: GBiB not running under VirtualBox or VirtualBox Guest Utils are not working + if [ ! modprobe vboxguest 2> /dev/null > /dev/null ] ; then + echo - Info: GBiB not running on VirtualBox or VirtualBox Guest Utils are not working fi fi + # check if we have internet, stop if not wget -q --tries=1 --timeout=10 --spider http://hgdownload.soe.ucsc.edu -O /dev/null if [ $? -ne 0 ] ; then + echoDebug GBiB has no connection to hgdownload.soe.ucsc.edu, cannot update now exit 3 fi # check flag file if run with no parameter (=from cron) if [ "$#" -eq 0 ] ; then # check a flag file to see if anything on hgdownload actually changed if /root/urlIsNotNewerThanFile $UPDATEFLAG /root/lastUpdateTime.flag then exit 0 fi fi # keep a log of all output of this script and the date echo --------------------------------- >> $LOGFILE date >> $LOGFILE @@ -134,30 +146,38 @@ chmod a+x /root/updateBrowser.sh /root/updateBrowser.sh $1 notSelf exit 0 fi rm -f /root/gbibSkipNextUpdate # check if any hgMirror jobs are running right now # check if the group id file exists and also if any processes exist with this group id # note that the .pid actually contains a group id, not a process id if [ -f /tmp/lastJob.pid ] && [ "$(ps x -o pgid | grep $(cat /tmp/lastJob.pid) | wc -l)" != "0" ] ; then echo a hgMirror job is running right now, not updating exit 4 fi +# deactivate inno-db support in mysql. Saves 400-500MB of RAM. +if ! grep skip-innodb /etc/mysql/my.cnf > /dev/null 2> /dev/null ; then + echo - Switching off inno-db in /etc/mysql/my.cnf + sed -i '/^.mysqld.$/a skip-innodb' /etc/mysql/my.cnf + sed -i '/^.mysqld.$/a default-storage-engine=myisam' /etc/mysql/my.cnf + service mysql restart +fi + # activate the apt repo 'main' and 'universe' so we can install external software if ! apt-cache policy r-base | grep "Unable to locate" > /dev/null; then if ! grep '^deb http://us.archive.ubuntu.com/ubuntu trusty main universe multiverse$' /etc/apt/sources.list > /dev/null; then echo - Activating the main Ubuntu package repository echo 'deb http://us.archive.ubuntu.com/ubuntu trusty main universe multiverse' >> /etc/apt/sources.list fi fi # activate daily automated security updates with automated reboots # automated reboots are strange but probably better than to risk exploits # see https://help.ubuntu.com/community/AutomaticSecurityUpdates if apt-cache policy unattended-upgrades | grep "Installed: .none." > /dev/null; then echo - Activating automated daily Ubuntu security updates # from http://askubuntu.com/questions/203337/enabling-unattended-upgrades-from-a-shell-script apt-get update