update install scripts

This commit is contained in:
r888888888
2014-05-02 20:27:14 -07:00
parent 1253592dc9
commit 3ed3febe06
9 changed files with 74 additions and 102 deletions

1
.gitignore vendored
View File

@@ -1,6 +1,7 @@
.bundle .bundle
config/database.yml config/database.yml
config/danbooru_local_config.rb config/danbooru_local_config.rb
config/deploy/*.rb
db/*.sqlite3 db/*.sqlite3
log/*.log log/*.log
tmp/* tmp/*

View File

@@ -39,6 +39,8 @@ gem 'diff-lcs', :require => "diff/lcs/array"
gem 'bcrypt-ruby', :require => "bcrypt" gem 'bcrypt-ruby', :require => "bcrypt"
gem 'awesome_print' gem 'awesome_print'
gem 'statistics2' gem 'statistics2'
gem 'capistrano'
gem 'capistrano-ext'
# needed for looser jpeg header compat # needed for looser jpeg header compat
gem 'ruby-imagespec', :require => "image_spec", :git => "https://github.com/r888888888/ruby-imagespec.git", :branch => "exif-fixes" gem 'ruby-imagespec', :require => "image_spec", :git => "https://github.com/r888888888/ruby-imagespec.git", :branch => "exif-fixes"

View File

@@ -56,6 +56,8 @@ GEM
net-sftp (>= 2.0.0) net-sftp (>= 2.0.0)
net-ssh (>= 2.0.14) net-ssh (>= 2.0.14)
net-ssh-gateway (>= 1.1.0) net-ssh-gateway (>= 1.1.0)
capistrano-ext (1.2.1)
capistrano (>= 1.0.0)
capistrano-unicorn (0.2.0) capistrano-unicorn (0.2.0)
capistrano (< 3.0) capistrano (< 3.0)
chronic (0.10.2) chronic (0.10.2)
@@ -233,6 +235,8 @@ DEPENDENCIES
awesome_print awesome_print
aws-s3! aws-s3!
bcrypt-ruby bcrypt-ruby
capistrano
capistrano-ext
capistrano-unicorn capistrano-unicorn
coffee-rails coffee-rails
daemons daemons

View File

@@ -7,25 +7,23 @@ if [[ "$(whoami)" != "root" ]] ; then
exit 1 exit 1
fi fi
echo "Danbooru Install" echo "* DANBOORU INSTALLATION SCRIPT"
echo "This script will install Ruby, Rails, PostgreSQL, and Nginx. By the end," echo "*"
echo "you should be able to connect to the server and create an account." echo "* This script will install all the necessary packages to run Danbooru on a "
echo "* Debian server."
echo echo
echo "It will create a new user called danbooru which will run the Danbooru" echo -n "* Enter the hostname for this server (ex: danbooru.donmai.us): "
echo "processes. It will download the latest copy and install it in"
echo "/var/www/danbooru2."
echo
echo -n "Enter the hostname for this server (ex: danbooru.donmai.us): "
read HOSTNAME read HOSTNAME
if [[ -z "$HOSTNAME" ]] ; then if [[ -z "$HOSTNAME" ]] ; then
echo "Must enter a hostname" echo "* Must enter a hostname"
exit 1 exit 1
fi fi
RUBY_VERSION=1.9.3-p327 RUBY_VERSION=1.9.3-p327
GITHUB_INSTALL_SCRIPTS=https://raw.githubusercontent.com/r888888888/danbooru/master/script/install
echo -n "Enter a name for the site (default: Danbooru): " echo -n "* Enter a name for the site (default: Danbooru): "
read SITENAME read SITENAME
if [[ -z "$SITENAME" ]] ; then if [[ -z "$SITENAME" ]] ; then
@@ -33,123 +31,83 @@ if [[ -z "$SITENAME" ]] ; then
fi fi
# Install packages # Install packages
echo "Installing packages..." echo "* Installing packages..."
apt-get update apt-get update
apt-get -y install build-essential automake openssl libssl-dev libyaml-dev libxml2-dev libxslt-dev autoconf ncurses-dev sudo gcc g++ libreadline-dev zlib1g-dev flex bison bzip2 ragel memcached libmemcache-dev git curl libcurl4-openssl-dev emacs imagemagick libmagickcore-dev libmagickwand-dev sendmail-bin sendmail psmisc postgresql postgresql-contrib libpq-dev apt-get -y install build-essential automake libssl-dev libxml2-dev libxslt-dev ncurses-dev sudo libreadline-dev flex bison ragel memcached libmemcache-dev git curl libcurl4-openssl-dev imagemagick libmagickcore-dev libmagickwand-dev sendmail-bin sendmail postgresql postgresql-contrib libpq-dev nginx ssh
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "* Error installing packages; aborting"
exit 1 exit 1
fi fi
# Create user account # Create user account
useradd -m danbooru useradd -m danbooru
chsh -s /bin/bash danbooru chsh -s /bin/bash danbooru
addgroup wheel usermod -G danbooru,sudo danbooru
usermod -G root,wheel root
usermod -G danbooru,wheel danbooru
# Setup danbooru account
echo
echo "*************************************************"
echo "* Enter a new password for the danbooru account *"
echo "*************************************************"
echo
passwd danbooru
# Install rbenv # Install rbenv
echo "Installing rbenv..." echo "* Installing rbenv..."
cd / cd /
sudo -u danbooru git clone git://github.com/sstephenson/rbenv.git /home/danbooru/.rbenv sudo -u danbooru git clone git://github.com/sstephenson/rbenv.git ~danbooru/.rbenv
sudo -u danbooru touch /home/danbooru/.bash_profile sudo -u danbooru touch ~danbooru/.bash_profile
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> /home/danbooru/.bash_profile echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~danbooru/.bash_profile
echo 'eval "$(rbenv init -)"' >> /home/danbooru/.bash_profile echo 'eval "$(rbenv init -)"' >> ~danbooru/.bash_profile
sudo -u danbooru mkdir -p /home/danbooru/.rbenv/plugins sudo -u danbooru mkdir -p ~danbooru/.rbenv/plugins
sudo -u danbooru git clone git://github.com/sstephenson/ruby-build.git /home/danbooru/.rbenv/plugins/ruby-build sudo -u danbooru git clone git://github.com/sstephenson/ruby-build.git ~danbooru/.rbenv/plugins/ruby-build
sudo -u danbooru bash -l -c "rbenv install $RUBY_VERSION" sudo -u danbooru bash -l -c "rbenv install $RUBY_VERSION"
sudo -u danbooru bash -l -c "rbenv global $RUBY_VERSION" sudo -u danbooru bash -l -c "rbenv global $RUBY_VERSION"
#Generate secret token and secret key # Generate secret token and secret key
sudo -u danbooru mkdir /home/danbooru/.danbooru/ echo "* Generating secret keys..."
sudo -u danbooru openssl rand -hex 32 > /home/danbooru/.danbooru/secret_token sudo -u danbooru mkdir ~danbooru/.danbooru/
sudo -u danbooru openssl rand -hex 32 > /home/danbooru/.danbooru/session_secret_key sudo -u danbooru openssl rand -hex 32 > ~danbooru/.danbooru/secret_token
chmod 600 /home/danbooru/.danbooru/session_secret_key sudo -u danbooru openssl rand -hex 32 > ~danbooru/.danbooru/session_secret_key
chmod 600 /home/danbooru/.danbooru/secret_token chmod 600 ~danbooru/.danbooru/*
chown -R danbooru:danbooru /home/danbooru/.danbooru/
# Install gems # Install gems
sudo -u danbooru bash -l -c 'gem install --no-ri --no-rdoc capistrano' echo "* Installing gems..."
sudo -u danbooru bash -l -c 'gem install --no-ri --no-rdoc capistrano-ext'
sudo -u danbooru bash -l -c 'gem install --no-ri --no-rdoc bundler' sudo -u danbooru bash -l -c 'gem install --no-ri --no-rdoc bundler'
sudo -u danbooru bash -l -c 'gem install --no-ri --no-rdoc whenever'
sudo -u danbooru bash -l -c 'gem install --no-ri --no-rdoc capistrano-unicorn'
# Install Nginx echo "* Install configuration scripts..."
curl http://nginx.org/keys/nginx_signing.key > /root/nginx_signing.key
apt-key add nginx_signing.key
echo "deb http://nginx.org/packages/debian/ squeeze nginx" >> /etc/apt/sources.list
echo "deb-src http://nginx.org/packages/debian/ squeeze nginx" >> /etc/apt/sources.list
apt-get update
apt-get -y install nginx
rm -f /etc/nginx/conf.d/*.conf
# Update PostgreSQL # Update PostgreSQL
PG_HBA_FILE="/etc/postgresql/8.4/main/pg_hba.conf" curl -L -s $GITHUB_INSTALL_SCRIPTS/postgresql_hba_conf -o /etc/postgresql/9.1/main/pg_hba.conf
echo "local all postgres,danbooru trust" > $PG_HBA_FILE
echo "host all postgres,danbooru 127.0.0.1/32 trust" >> $PG_HBA_FILE
/etc/init.d/postgresql restart /etc/init.d/postgresql restart
sudo -u postgres createuser -s danbooru sudo -u postgres createuser -s danbooru
sudo -u danbooru createdb danbooru2
# Setup nginx # Setup nginx
update-rc.d -f nginx defaults curl -L -s $GITHUB_INSTALL_SCRIPTS/nginx.danbooru.conf -o /etc/nginx/conf.d/danbooru.conf
curl -s https://raw.githubusercontent.com/r888888888/danbooru/master/script/install/nginx.danbooru.conf > /etc/nginx/conf.d/danbooru.conf
sed -i -e "s/__hostname__/$HOSTNAME/g" /etc/nginx/conf.d/danbooru.conf sed -i -e "s/__hostname__/$HOSTNAME/g" /etc/nginx/conf.d/danbooru.conf
/etc/init.d/nginx start /etc/init.d/nginx restart
echo "%wheel ALL=(ALL) ALL" >> /etc/sudoers
# Setup logrotate # Setup logrotate
LOGROTATE_CONF_FILE="/etc/logrotate.conf" curl -L -s $GITHUB_INSTALL_SCRIPTS/danbooru_logrotate_conf -o /etc/logrotate.d/danbooru.conf
echo >> $LOGROTATE_CONF_FILE
echo "/var/www/danbooru2/current/log/production.log {" >> $LOGROTATE_CONF_FILE
echo " daily" >> $LOGROTATE_CONF_FILE
echo " rotate 3" >> $LOGROTATE_CONF_FILE
echo " copytruncate" >> $LOGROTATE_CONF_FILE
echo "}" >> $LOGROTATE_CONF_FILE
sudo -u danbooru createdb danbooru2 # Setup danbooru account
sudo -u danbooru psql danbooru2 -c 'CREATE LANGUAGE plpgsql;' echo "* Enter a new password for the danbooru account"
passwd danbooru
echo "* Setting up SSH keys for the danbooru account"
sudo -u danbooru ssh-keygen
echo "* Setting up danbooru app..."
sudo -u danbooru git clone https://github.com/r888888888/danbooru ~danbooru/danbooru
sudo -u danbooru bash -l -c 'cd ~/danbooru ; bundle'
echo "* Creating a new local git branch called develop"
sudo -u danbooru git checkout -b develop
echo "* Setting up known_hosts for localhost"
ssh-keyscan -t rsa,dsa localhost 2>&1 | sort -u - ~/.ssh/known_hosts > ~/.ssh/tmp_hosts
cat ~/.ssh/tmp_hosts >> ~/.ssh/known_hosts
echo "* Almost done! The code has been checked out at ~danbooru/danbooru. You can "
echo "* now login as the danbooru user and run the following commands to deploy to "
echo "* the server:"
echo "*"
echo "* cd ~/danbooru"
echo "* bundle exec cap development deploy:setup"
echo "* bundle exec cap development deploy:update"
cd /home/danbooru
sudo -u danbooru mkdir /home/danbooru/apps
cd /home/danbooru/apps
git clone git://github.com/r888888888/danbooru.git danbooru
chown -R danbooru:danbooru danbooru
echo
echo
echo "**************************************************************"
echo "* Danbooru is almost ready for deployment. *"
echo "* *"
echo "* A local copy has been checked out into /home/danbooru/apps *"
echo "* but you may want to clone your own copy from *"
echo "* http://github.com/r888888888/danbooru.git *"
echo "* *"
echo "* You will probably want to create your own branch and *"
echo "* modify the config/deploy/staging.rb and production.rb *"
echo "* files to point to the correct servers. *"
echo "* *"
echo "* You will also need to edit config/deploy.rb and replace *"
echo "* albert with danbooru. Then run: *"
echo "* *"
echo "* cap deploy:setup && cap deploy *"
echo "* This will run as staging environment *"
echo "* *"
echo "* cap production deploy:setup && cap production deploy *"
echo "* This will run as production environment *"
echo "* *"
echo "* The first account will automatically be made an admin. *"
echo "* You can edit the configuration files by editing *"
echo "* /var/www/danbooru2/shared/config/local_config and *"
echo "* /var/www/danbooru2/shared/config/database.yml *"
echo "**************************************************************"

View File

@@ -1,4 +1,4 @@
set :stages, %w(production staging) set :stages, %w(production development staging)
set :default_stage, "staging" set :default_stage, "staging"
set :unicorn_env, defer {stage} set :unicorn_env, defer {stage}
require 'capistrano/ext/multistage' require 'capistrano/ext/multistage'
@@ -21,7 +21,7 @@ set :secret_2, SecureRandom.base64(32)
set :application, "danbooru" set :application, "danbooru"
set :repository, "git://github.com/r888888888/danbooru.git" set :repository, "git://github.com/r888888888/danbooru.git"
set :scm, :git set :scm, :git
set :user, "albert" set :user, "danbooru"
set :deploy_to, "/var/www/danbooru2" set :deploy_to, "/var/www/danbooru2"
require 'capistrano-unicorn' require 'capistrano-unicorn'

View File

@@ -1,2 +1,3 @@
set :user, "albert"
server "sonohara.donmai.us", :web, :app, :db, :primary => true server "sonohara.donmai.us", :web, :app, :db, :primary => true
server "hijiribe.donmai.us", :web, :app server "hijiribe.donmai.us", :web, :app

View File

@@ -1,2 +1 @@
set :user, "danbooru"
server "testbooru.donmai.us", :web, :app, :db, :primary => true server "testbooru.donmai.us", :web, :app, :db, :primary => true

View File

@@ -0,0 +1,5 @@
/var/www/danbooru2/shared/log/*.log {
daily
rotate 3
copytruncate
}

View File

@@ -0,0 +1,2 @@
local all postgres,danbooru trust
host all postgres,danbooru 127.0.0.1/32 trust