From 3ed3febe060db9b49c7772c7a2fa2cea2b619c77 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Fri, 2 May 2014 20:27:14 -0700 Subject: [PATCH] update install scripts --- .gitignore | 1 + Gemfile | 2 + Gemfile.lock | 4 + INSTALL.debian | 156 +++++++++---------------- config/deploy.rb | 4 +- config/deploy/production.rb | 1 + config/deploy/staging.rb | 1 - script/install/danbooru_logrotate_conf | 5 + script/install/postgresql_hba_conf | 2 + 9 files changed, 74 insertions(+), 102 deletions(-) create mode 100644 script/install/danbooru_logrotate_conf create mode 100644 script/install/postgresql_hba_conf diff --git a/.gitignore b/.gitignore index 1f08c82ee..f48785238 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .bundle config/database.yml config/danbooru_local_config.rb +config/deploy/*.rb db/*.sqlite3 log/*.log tmp/* diff --git a/Gemfile b/Gemfile index 9776a34dc..e7525239c 100644 --- a/Gemfile +++ b/Gemfile @@ -39,6 +39,8 @@ gem 'diff-lcs', :require => "diff/lcs/array" gem 'bcrypt-ruby', :require => "bcrypt" gem 'awesome_print' gem 'statistics2' +gem 'capistrano' +gem 'capistrano-ext' # needed for looser jpeg header compat gem 'ruby-imagespec', :require => "image_spec", :git => "https://github.com/r888888888/ruby-imagespec.git", :branch => "exif-fixes" diff --git a/Gemfile.lock b/Gemfile.lock index 1f37e6340..a8435533b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -56,6 +56,8 @@ GEM net-sftp (>= 2.0.0) net-ssh (>= 2.0.14) net-ssh-gateway (>= 1.1.0) + capistrano-ext (1.2.1) + capistrano (>= 1.0.0) capistrano-unicorn (0.2.0) capistrano (< 3.0) chronic (0.10.2) @@ -233,6 +235,8 @@ DEPENDENCIES awesome_print aws-s3! bcrypt-ruby + capistrano + capistrano-ext capistrano-unicorn coffee-rails daemons diff --git a/INSTALL.debian b/INSTALL.debian index 065605b59..eef0e1144 100644 --- a/INSTALL.debian +++ b/INSTALL.debian @@ -7,25 +7,23 @@ if [[ "$(whoami)" != "root" ]] ; then exit 1 fi -echo "Danbooru Install" -echo "This script will install Ruby, Rails, PostgreSQL, and Nginx. By the end," -echo "you should be able to connect to the server and create an account." +echo "* DANBOORU INSTALLATION SCRIPT" +echo "*" +echo "* This script will install all the necessary packages to run Danbooru on a " +echo "* Debian server." echo -echo "It will create a new user called danbooru which will run the Danbooru" -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): " +echo -n "* Enter the hostname for this server (ex: danbooru.donmai.us): " read HOSTNAME if [[ -z "$HOSTNAME" ]] ; then - echo "Must enter a hostname" + echo "* Must enter a hostname" exit 1 fi 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 if [[ -z "$SITENAME" ]] ; then @@ -33,123 +31,83 @@ if [[ -z "$SITENAME" ]] ; then fi # Install packages -echo "Installing packages..." +echo "* Installing packages..." 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 + echo "* Error installing packages; aborting" exit 1 fi # Create user account useradd -m danbooru chsh -s /bin/bash danbooru -addgroup wheel -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 +usermod -G danbooru,sudo danbooru # Install rbenv -echo "Installing rbenv..." +echo "* Installing rbenv..." cd / -sudo -u danbooru git clone git://github.com/sstephenson/rbenv.git /home/danbooru/.rbenv -sudo -u danbooru touch /home/danbooru/.bash_profile -echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> /home/danbooru/.bash_profile -echo 'eval "$(rbenv init -)"' >> /home/danbooru/.bash_profile -sudo -u danbooru mkdir -p /home/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/rbenv.git ~danbooru/.rbenv +sudo -u danbooru touch ~danbooru/.bash_profile +echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~danbooru/.bash_profile +echo 'eval "$(rbenv init -)"' >> ~danbooru/.bash_profile +sudo -u danbooru mkdir -p ~danbooru/.rbenv/plugins +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 global $RUBY_VERSION" -#Generate secret token and secret key -sudo -u danbooru mkdir /home/danbooru/.danbooru/ -sudo -u danbooru openssl rand -hex 32 > /home/danbooru/.danbooru/secret_token -sudo -u danbooru openssl rand -hex 32 > /home/danbooru/.danbooru/session_secret_key -chmod 600 /home/danbooru/.danbooru/session_secret_key -chmod 600 /home/danbooru/.danbooru/secret_token -chown -R danbooru:danbooru /home/danbooru/.danbooru/ +# Generate secret token and secret key +echo "* Generating secret keys..." +sudo -u danbooru mkdir ~danbooru/.danbooru/ +sudo -u danbooru openssl rand -hex 32 > ~danbooru/.danbooru/secret_token +sudo -u danbooru openssl rand -hex 32 > ~danbooru/.danbooru/session_secret_key +chmod 600 ~danbooru/.danbooru/* # Install gems -sudo -u danbooru bash -l -c 'gem install --no-ri --no-rdoc capistrano' -sudo -u danbooru bash -l -c 'gem install --no-ri --no-rdoc capistrano-ext' +echo "* Installing gems..." 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 -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 +echo "* Install configuration scripts..." # Update PostgreSQL -PG_HBA_FILE="/etc/postgresql/8.4/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 - +curl -L -s $GITHUB_INSTALL_SCRIPTS/postgresql_hba_conf -o /etc/postgresql/9.1/main/pg_hba.conf /etc/init.d/postgresql restart sudo -u postgres createuser -s danbooru +sudo -u danbooru createdb danbooru2 # Setup nginx -update-rc.d -f nginx defaults -curl -s https://raw.githubusercontent.com/r888888888/danbooru/master/script/install/nginx.danbooru.conf > /etc/nginx/conf.d/danbooru.conf +curl -L -s $GITHUB_INSTALL_SCRIPTS/nginx.danbooru.conf -o /etc/nginx/conf.d/danbooru.conf sed -i -e "s/__hostname__/$HOSTNAME/g" /etc/nginx/conf.d/danbooru.conf -/etc/init.d/nginx start - -echo "%wheel ALL=(ALL) ALL" >> /etc/sudoers +/etc/init.d/nginx restart # Setup logrotate -LOGROTATE_CONF_FILE="/etc/logrotate.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 +curl -L -s $GITHUB_INSTALL_SCRIPTS/danbooru_logrotate_conf -o /etc/logrotate.d/danbooru.conf -sudo -u danbooru createdb danbooru2 -sudo -u danbooru psql danbooru2 -c 'CREATE LANGUAGE plpgsql;' +# Setup danbooru account +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 "**************************************************************" diff --git a/config/deploy.rb b/config/deploy.rb index 1338a2193..ba2d38900 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,4 +1,4 @@ -set :stages, %w(production staging) +set :stages, %w(production development staging) set :default_stage, "staging" set :unicorn_env, defer {stage} require 'capistrano/ext/multistage' @@ -21,7 +21,7 @@ set :secret_2, SecureRandom.base64(32) set :application, "danbooru" set :repository, "git://github.com/r888888888/danbooru.git" set :scm, :git -set :user, "albert" +set :user, "danbooru" set :deploy_to, "/var/www/danbooru2" require 'capistrano-unicorn' diff --git a/config/deploy/production.rb b/config/deploy/production.rb index 2d62d97e0..8568fcf19 100644 --- a/config/deploy/production.rb +++ b/config/deploy/production.rb @@ -1,2 +1,3 @@ +set :user, "albert" server "sonohara.donmai.us", :web, :app, :db, :primary => true server "hijiribe.donmai.us", :web, :app diff --git a/config/deploy/staging.rb b/config/deploy/staging.rb index c7b969f4e..1fa48f7ad 100644 --- a/config/deploy/staging.rb +++ b/config/deploy/staging.rb @@ -1,2 +1 @@ -set :user, "danbooru" server "testbooru.donmai.us", :web, :app, :db, :primary => true diff --git a/script/install/danbooru_logrotate_conf b/script/install/danbooru_logrotate_conf new file mode 100644 index 000000000..4e8d26e88 --- /dev/null +++ b/script/install/danbooru_logrotate_conf @@ -0,0 +1,5 @@ +/var/www/danbooru2/shared/log/*.log { + daily + rotate 3 + copytruncate +} diff --git a/script/install/postgresql_hba_conf b/script/install/postgresql_hba_conf new file mode 100644 index 000000000..0f7c5bc2d --- /dev/null +++ b/script/install/postgresql_hba_conf @@ -0,0 +1,2 @@ +local all postgres,danbooru trust +host all postgres,danbooru 127.0.0.1/32 trust \ No newline at end of file