• PRODUCT

    PRODUCT

  • PRICING
    PRICING

  • HELP
    HELP

  • BLOG
    BLOG

  • APPSTORE
    APPSTORE

  • COMPANY
    COMPANY

  • LEGAL
    LEGAL

  • LOGIN
    LOGIN

  • Useful Devops Scripts


  • Useful Devops Scripts


  • Create your own cron script directories

    Add these to /etc/crontab

    0 0 * root run-parts /etc/cron.mymidnightly

    * root run-parts /etc/cron.myminutely

    The directory permissions are:

    drwxr-xr-x 2 root root

    You can check cron script's performance by looking at cronlogs. i.e.

    sudo tail /var/log/cron

    Will do

    Sep 8 08:39:01 ip-1-2-3-4 CROND24512: (root) CMD (run-parts /etc/cron.myminutely)

    Sep 8 08:39:01 ip-1-2-3-4 run-parts(/etc/cron.myminutely)24512: starting process_izyapp1.sh

    Sep 8 08:39:06 ip-1-2-3-4 run-parts(/etc/cron.myminutely)24545: finished process_izyapp1.sh

    Sep 8 08:39:06 ip-1-2-3-4 run-parts(/etc/cron.myminutely)24512: starting process_izyapp2.sh

    Sep 8 08:39:06 ip-1-2-3-4 run-parts(/etc/cron.myminutely)24551: finished process_izyapp2.sh

    Sep 8 08:40:01 ip-1-2-3-4 CROND24559: (root) CMD (run-parts /etc/cron.myminutely)

    Sep 8 08:40:01 ip-1-2-3-4 run-parts(/etc/cron.myminutely)24559: starting process_izyapp1.sh

    Sep 8 08:40:05 ip-1-2-3-4 run-parts(/etc/cron.myminutely)24592: finished process_izyapp1.sh

    Sep 8 08:40:05 ip-1-2-3-4 run-parts(/etc/cron.myminutely)24559: starting process_izyapp2.sh

    Sep 8 08:40:05 ip-1-2-3-4 run-parts(/etc/cron.myminutely)24598: finished process_izyapp2.sh

    Periodically check web server health

    Put this in /etc/cron.myminutely/checkwebserver.sh.

    !/bin/sh

    URL="http://localhost/checkwebserver.txt"

    echo "Checking, 100 second timeout ..."

    wget -q recursive=off --timeout=100 -O /dev/null "$URL"

    if [ $? -ne 0 ]; then

    echo "FORCE RESET SINCE SERVICE IS DOWN"

    echo \ps -ef | grep http | wc -l\ | mail -s "[checkwebserver.sh] FORCE RESET SINCE SERVICE IS DOWN \date\ $URL" youremail@yourdomain.com

    /opt/lampp/lampp restart | mail -s "[checkwebserver.sh] FORCE RESET SINCE SERVICE IS DOWN \date\ $URL" youremail@yourdomain.com

    else

    echo "OK"

    fi

    Make sure to set the correct permissions, i.e:

    -rwxr-xr-x 1 root root

    Periodically run an izy node script, skip run if it is already in progress

    !/bin/sh

    uncomment the line below to temporarily disable

    exit 0

    this is the g_appname module name. see npm package izymodtask

    APPNAME=myappname

    APPDIR=/opt/lampp/htdocs/apps/myappname

    LOGDIR=$APPDIR/secure/log

    LOGFILE=$LOGDIR/scheduler.log

    chain as many atomic steps as you like below

    if ps -ef | grep -v grep | grep "ldo.sh $APPNAME" ; then

    echo "running already"

    exit 0

    else

    cd $APPDIR;./ldo.sh $APPNAME.processraw 5 >> $LOGFILE 2>&1;./ldo.sh $APPNAME.processmonitor 5 >> $LOGFILE 2>&1;./ldo.sh $APPNAME.processrecord 5 >> $LOGFILE 2>&1;./ldo.sh $APPNAME.processcustomer 5 >> $LOGFILE 2>&1;./ldo.sh $APPNAME.processautodiscover 5 >> $LOGFILE 2>&1;

    echo $LOGFILE

    exit 0

    fi

    Do nightly backups and put archive on dropbox

    !/bin/sh

    TMPDIR="/tmp/apps/myappname"

    APPFOLDER="/opt/lampp/htdocs/apps/myappname"

    APPNAME="myappname"

    CLOUDFILENAME="myappname.backup"

    logger "Backing up myappname ..."

    logger "Wipe/Create $TMPDIR"

    mkdir -p "$TMPDIR"

    rm $TMPDIR/*.gz

    logger "Backup DISK Contents"

    tar -zcvf $TMPDIR/files.tar.gz $APPFOLDER/

    logger "Backup Database Contents"

    /opt/lampp/bin/mysqldump -h localhost -u root $APPNAME > $TMPDIR/database.sql

    gzip -v $TMPDIR/database.sql

    tar cf $TMPDIR/backup.tar $TMPDIR/*.gz $APPFOLDER/restore.sh /etc/cron.mymidnightly/backup$APPNAME.sh /etc/cron.myminutely/process_$APPNAME.sh

    logger "Upload to cloud. results will be in $TMPDIR/uploadlog.log"

    date > $TMPDIR/uploadlog.log

    $APPFOLDER/dropbox_uploader.sh upload $TMPDIR/backup.tar $CLOUDFILENAME >> $TMPDIR/uploadlog.log 2>&1

    logger "Upload complete, cleanup .."

    rm $TMPDIR/*.gz;

    > $APPFOLDER/secure/log/accesslog; > $APPFOLDER/secure/log/errorlog; > $APPFOLDER/secure/log/sslrequestlog;> $APPFOLDER/secure/log/scheduler.log;

    rm $TMPDIR/*.tar

    This will log results to /var/log/messages that you can check by

    sudo less /var/log/messages

    Periodically clean up logs

    !/bin/sh

    > /opt/lampp/logs/accesslog; > /opt/lampp/logs/errorlog; > /opt/lampp/logs/sslrequestlog

    > /opt/lampp/htdocs/p1/logging/0.is.sync.log

    Periodically reset the lampp stack

    !/bin/sh

    rm /opt/lampp/logs/httpd.pid

    /opt/lampp/lampp restart

    Tip on managing server space

    • Always have log rotation turned on
    • Periodically prune your logs

    Use this to track large directories:

    sudo du -sm * | awk '$1 > 100'


  • Izyware Blog
    Izyware Blog