Created
December 12, 2012 12:00
-
-
Save gu-fan/4267247 to your computer and use it in GitHub Desktop.
server_setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Server Deployment Script | |
# Summary: Setup basic deploy enviroment for web apps. | |
# Author: Rykka (rykka10@gmail.com) | |
# OS: ubuntu 12.04 | |
# Usage: sh server_setup $HOST_NAME | |
# Via net: wget --no-check-certificate https://gist.github.com/raw/4267247/37aa9dc296e3777161bd2b006b7f5f9d765f073b/server_setup -O - | sh | |
# Install puppet , and use puppet to intall | |
# nginx and mysql and uwsgi | |
# and setup the users. setup hostname and directory names | |
if [ $1 ]; then | |
FULL_HOSTNAME=$1 | |
else | |
FULL_HOSTNAME="example.com" | |
fi | |
SHORT_HOST=`echo ${FULL_HOSTNAME} | cut -d'.' -f1` | |
APTGET=`which apt-get` | |
APT_KEY=`which apt-key` | |
########### | |
# Need to add in the aptitude workarounds for instances. | |
# * First disable dialog boxes for dpkg | |
########### | |
export DEBIAN_FRONTEND=noninteractive | |
########### | |
# Update the instance and install the puppet agent | |
########### | |
${APTGET} update | |
${APTGET} -y upgrade | |
${APTGET} -y install puppet | |
PUPPET=`which puppet` | |
########## | |
# Setup the puppet manifest in /root/server_setup | |
########## | |
cat >>/root/server_setup.pp <<EOF | |
# ENV setup for ubuntu 12.04 by server_setup script | |
Exec { path => [ "/bin/", "/sbin/" , "/usr/bin/", "/usr/sbin/" ] } | |
host { '$FULL_HOSTNAME': ip => '127.0.0.1', | |
host_aliases => [ '$SHORT_HOST','puppet' ], } | |
user { 'root': shell => '/bin/zsh', } | |
group { 'www-data': ensure=>present,} | |
group { 'uwsgi': ensure=>present, } | |
user { 'www-data': ensure=>present, gid=>'www-data', } | |
user { 'uwsgi': ensure=>present, gid=>'uwsgi', } | |
# basic | |
package { 'git': ensure => installed } | |
package { 'curl': ensure => installed } | |
package { 'wget': ensure => installed } | |
package { 'sed': ensure => installed } | |
# server | |
package { 'mysql': ensure => installed } | |
package { 'memcached': ensure => installed } | |
package { 'nginx': ensure => installed } | |
service { 'nginx': | |
ensure => true, | |
enable => true, | |
require => Package['nginx'] | |
} | |
package { 'vim': ensure => installed } | |
package { 'zsh': ensure => installed } | |
exec { 'oh-my-zsh': | |
command => 'cd ~ && wget --no-check-certificate https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh', | |
creates => "/root/.oh-my-zsh" } | |
exec { 'zshrc': | |
command => 'cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc', | |
creates => "/root/.zshrc" } | |
# uwsgi | |
package { 'python-pip': ensure => installed } | |
package { 'build-essential': ensure => installed } | |
package { 'python-dev': ensure => installed } | |
package { 'libxml2-dev': ensure => installed } | |
exec { 'uwsgi': | |
command => 'pip install uwsgi' , | |
require => [ | |
Package['build-essential'], | |
Package['python-dev'], | |
Package['libxml2-dev'], | |
], | |
} | |
EOF | |
############ | |
# Apply the puppet manifest | |
############ | |
$PUPPET apply /root/server_setup.pp | |
rm /root/server_setup.pp | |
############ | |
# End of script cleanup. | |
############ | |
export DEBIAN_FRONTEND=dialog |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment