Skip to content

Instantly share code, notes, and snippets.

@tjstein
tjstein / gs-backup.sh
Created November 17, 2009 04:23
gs-backup.sh
#!/bin/bash
# Tar shit up:
today=$(date '+%d_%m_%y')
echo "* Performing domain backup..."
tar czf /var/backups/constantshift.com_"$today".tar.gz -C / var/www/constantshift.com
echo "* Backed up..."
# Remove shit older than 7 days:
MaxFileAge=7
find /var/backups/ -name '*.gz' -type f -mtime +$MaxFileAge -exec rm -f {} \;
# Rsync shit to the grid:
@tjstein
tjstein / apc
Created May 16, 2010 20:19
apc
#!/usr/bin/perl
#
# Magic markers:
#%# family=auto
#%# capabilities=autoconf
my $ret = undef;
if (! eval "require LWP::UserAgent;")
{
<?php
$mem = apc_sma_info();
$mem_size = $mem['num_seg']*$mem['seg_size'];
$mem_avail= $mem['avail_mem'];
$mem_used = $mem_size-$mem_avail;
$out = array(
'size: ' . sprintf("%.2f", $mem_size),
'used: ' . sprintf("%.2f", $mem_used),
'free: ' . sprintf("%.2f", $mem_avail)
);
@tjstein
tjstein / memcached
Created May 16, 2010 20:33
memcached
#!/usr/bin/perl -w
#
# Copyright (C) 2008 Rodolphe Quiedeville <rodolphe@quiedeville.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2 dated June,
# 1991.
#
# This program is distributed in the hope that it will be useful,
@tjstein
tjstein / memcached_hits
Created May 16, 2010 20:34
memcached_hits
#!/usr/bin/perl -w
#
# Copyright (C) 2008 Rodolphe Quiedeville <rodolphe@quiedeville.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2 dated June,
# 1991.
#
# This program is distributed in the hope that it will be useful,
@tjstein
tjstein / memcached_size
Created May 16, 2010 20:34
memcached_size
#!/usr/bin/perl -w
#
# Copyright (C) 2008 Rodolphe Quiedeville <rodolphe@quiedeville.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2 dated June,
# 1991.
#
# This program is distributed in the hope that it will be useful,
@tjstein
tjstein / varnish_
Created May 16, 2010 21:15
varnish_
#!/usr/bin/perl -w
#
# varnish_ - Munin plugin to for Varnish
# Copyright (C) 2009 Redpill Linpro AS
#
# Author: Kristian Lyngstøl <kristian@redpill-linpro.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
add-apt-repository ppa:brianmercer/php
aptitude -y update
aptitude -y install php5-cli php5-common php5-mysql php5-suhosin php5-gd php5-curl
aptitude -y install php5-fpm php5-cgi php-pear php5-memcache php-apc php5-dev
echo "apc.mmap_file_mask=/tmp/apc.XXXXXX" >> /etc/php5/conf.d/apc.ini
echo "apc.shm_size = 64" >> /etc/php5/conf.d/apc.ini
cp /etc/php5/fpm/php5-fpm.conf /etc/php5/fpm/php5-fpm.conf.original
sed -i 's/.*listen.allowed_clients = 127.0.0.1.*/listen.allowed_clients = 127.0.0.1/g' /etc/php5/fpm/php5-fpm.conf
@tjstein
tjstein / apachetest.sh
Created September 1, 2010 19:05
Find out what Apache MaxClients should be set to
#!/bin/bash
echo "This is intended as a guideline only!"
if [ -e /etc/debian_version ]; then
APACHE="apache2"
elif [ -e /etc/redhat-release ]; then
APACHE="httpd"
fi
RSS=`ps -aylC $APACHE |grep "$APACHE" |awk '{print $8'} |sort -n |tail -n 1`
RSS=`expr $RSS / 1024`
echo "Stopping $APACHE to calculate free memory"
@tjstein
tjstein / nginx
Created September 14, 2010 08:18
nginx
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon