#!/bin/bash function usage { echo "Usage:" echo "$0 --all|-a website" echo "$0 --sync|-s website" echo "$0 --deploy|-d website" } case $2 in 'website') project_repository="http://repository.ctld/website/trunk/" dir="/home/hio/repository/website.com/" prod_dir="/home/www/website.com/" exclude_list=".svn frontend_test.php frontend_dev.php auth.php backend_dev.php" ;; *) usage exit 1 esac if [[ $1 == "--all" || $1 == "-a" ]]; then $0 --sync $2 $0 --deploy $2 fi if [[ $1 == "--sync" || $1 == "-s" ]]; then if [ ! -d "$project_repository" ]; then svn co $project_repository $dir else svn up $dir fi fi for e in $exclude_list do excludes="$excludes --exclude '$e'" done if [[ $1 == "--deploy" || $1 == "-d" ]]; then rsync="sudo rsync -rha --stats $excludes $dir $prod_dir" echo $rsync eval $rsync sudo chown www-data:www-data -R $prod_dir fi
Category Archives: Linux
memo mdadm
Déclarer un disque défaillant et le retirer du raid
mdadm --manage /dev/md2 --set-faulty /dev/sdb1 mdadm --manage /dev/md2 --remove /dev/sdb1
Stopper un raid
mdadm --stop /dev/md2 mdadm --remove /dev/md2
Rajouter/remplacer un disque dans un raid et resynch
mdadm --assemble /dev/md2 /dev/sdb1
Information sur un raid
mdadm --detail /dev/md2
Sauvegarder la conf mdadm
mdadm --detail --scan --verbose >> /etc/mdadm/mdadm.conf
Générer CSR
openssl req -nodes -newkey rsa:2048 -keyout server.key -out server.csr
Country Name (2 letter code) [AU]: FR State or Province Name (full name) [Some-State]: . Locality Name (eg, city) []: Town Organization Name (eg, company) [Internet Widgits Pty Ltd]: company Organizational Unit Name (eg, section) []: IT Common Name (eg, YOUR name) []: www.website.tld Email Address []: A challenge password []: An optional company name []:
cat server.csrmass_update.sh
#!/bin/bash hosts="hio@host1.com hio@host2.com hio@host3.com hio@host4.com hio@host5.com" cmd="echo 'updating ...';sudo aptitude update >> /dev/null;sudo aptitude safe-upgrade -y;echo 'done'" for i in $hosts do echo "###### connecting to $i ..." ssh -t $i $cmd echo "" done
install_symfony2.sh
#!/bin/bash function usage { echo "Usage:" echo "$0 /home/www/mySf2Project" } if [[ $1 == "" ]]; then usage exit 1 fi cd $1 if [ -d "app/" ]; then echo "already installed, do a <git pull> if you want an update :)" exit 1 fi git clone git://github.com/symfony/symfony-standard.git mv symfony-standard/* . mv symfony-standard/.git* . rmdir symfony-standard bash bin/vendors.sh && php bin/build_bootstrap.php echo "chmod -R 777 app/cache/ app/logs/" chmod -R 777 app/cache/ app/logs/ exit 0
import.sh
#!/bin/bash date_format="+%d/%m/%Y %H:%M:%S" dir="/home/smile" mysql_client="mysql -u import -pP4S5W0RD" echo `date "$date_format"`" start" cd $dir if [ ! -d "tmp" ];then mkdir tmp fi if [ ! -d "bak" ];then mkdir bak fi for i in `ls *.sql.gz` do f=`echo $i|cut -d'.' -f1-2` db_name=`echo $i|cut -d'-' -f1` echo `date "$date_format"`" gzip -d $i -c > tmp/$f" gzip -d $i -c > tmp/$f echo `date "$date_format"`" mysql -u import -p***** $db_name < tmp/$f" $mysql_client <<EOF DROP DATABASE $db_name ; CREATE DATABASE $db_name ; EOF $mysql_client $db_name < tmp/$f mv $i bak/$i rm tmp/$f done echo `date "$date_format"`" end"
10/04/2011 08:00:01 start 10/04/2011 08:00:01 gzip -d bayardsso_prod-201104100542.sql.gz -c > tmp/bayardsso_prod-201104100542.sql 10/04/2011 08:00:02 mysql -u import -p***** bayardsso_prod < tmp/bayardsso_prod-201104100542.sql 10/04/2011 08:01:18 gzip -d notretemps-201104090006.sql.gz -c > tmp/notretemps-201104090006.sql 10/04/2011 08:01:45 mysql -u import -p***** notretemps < tmp/notretemps-201104090006.sql 10/04/2011 08:33:20 gzip -d notretemps_outils-201104090006.sql.gz -c > tmp/notretemps_outils-201104090006.sql 10/04/2011 08:33:20 mysql -u import -p***** notretemps_outils < tmp/notretemps_outils-201104090006.sql 10/04/2011 08:33:20 gzip -d phosphore-201104100040.sql.gz -c > tmp/phosphore-201104100040.sql 10/04/2011 08:34:20 mysql -u import -p***** phosphore < tmp/phosphore-201104100040.sql 10/04/2011 10:23:21 end
arbo.sh
#!/bin/bash dir="/home/www/bayardcdn.com/bj.emailing" month[1]=`date +%Y/%m` month[2]=`date +%Y/%m --date "+1 month"` month[3]=`date +%Y/%m --date "+2 month"` month[4]=`date +%Y/%m --date "+3 month"` m_nb=`seq 1 4` chmod u+w,g+w,o-w -R $dir for i in $m_nb do if [ ! -d "$dir/${month[$i]}" ]; then echo "mkdir -p $dir/${month[$i]}" mkdir -p "$dir/${month[$i]}" fi done chmod u-w,g-w,o-w -R $dir for i in $m_nb do if [ -d "$dir/${month[$i]}" ]; then echo "chmod u+w,g+w -R $dir/${month[$i]}" chmod u+w,g+w -R $dir/${month[$i]} fi done
wwwperm.sh
#!/bin/bash www=$2 dirperms="750" fileperms="640" owner="www-data:www-data" function usage { echo "Usage:" echo "$0 --all /home/www" echo "$0 --dir /home/www" echo "$0 --file /home/www" echo "$0 --owner /home/www" } if [[ $1 == "" || $2 == "" ]]; then usage exit 1 fi case $1 in '--all') bash $0 --dir $www bash $0 --file $www bash $0 --owner $www ;; '--dir') echo "fixing dirs in $www ..." find $www -type d -exec sh -c "chmod $dirperms '{}'" \; ;; '--file') echo "fixing files in $www ..." find $www -type f -exec sh -c "chmod $fileperms '{}'" \; ;; '--owner') echo "fixing owner in $www ..." chown -R $owner $www ;; *) usage exit 1 esac exit 0
memo varnish *.vcl
vcl_recv Called at the beginning of a request, after the complete
request has been received and parsed. Its purpose is to
decide whether or not to serve the request, how to do it,
and, if applicanle, which backend to use.
vcl_hit Called after a cache lookup if the requested document was
found in the cache.
vcl_miss Called after a cache lookup if the requested document was
not found in the cache. Its purpose is to decide whether or
not to attempt to retrieve the document from the backend,
and which backend to use.
vcl_fetch Called after a document has been retrieved from the backend,
before it is inserted into the cache.
vcl_timeout Called by the reaper thread when a cached document has
reached its expiry time.vcl_recv
sub vcl_recv {
if (req.http.host == "be-geek.com" && req.url ~ "\.(gif|jpg|swf|css|js|png|jpg|jpeg|gif|png|tiff|tif|ico)$") {
set req.url = regsub(req.url, "\?.*", "");
set req.http.user-agent = "mozilla";
unset req.http.Cookie;
unset req.http.Authorization;
set req.backend = nginx;
return(lookup);
}
if (req.http.host ~ "^static.bgkcdn.com$" || req.http.host ~ "^static(1|2|3|4).bgkcdn.com$") {
set req.url = regsub(req.url, "\?.*", "");
set req.http.user-agent = "mozilla";
unset req.http.Cookie;
unset req.http.Authorization;
set req.backend = nginx;
return(lookup);
}
if (req.http.host ~ "^download.hio.fr$") {
set req.backend = nginx;
return(pipe);
}
# Properly handle different encoding types
// Remove has_js and Google Analytics __* cookies.
set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(_[_a-z]+|has_js)=[^;]*", "");
// Remove a ";" prefix, if present.
set req.http.Cookie = regsub(req.http.Cookie, "^;\s*", "");
#return(lookup);
}memo rsync
rsync -rh --size-only --progress --stats --verbose --delete hio@hio.fr:/home/hio/ /home/hio