Arch Rails Server

by asayers
5 deployments · 1 still active · last rev. 3 years ago

Sets up a decent Rails server with Nginx, PostgreSQL, and Redis.

WARNING: This script downloads nginx config files from Please check them before you run the script. NO WARRANTY etc.

Remember to run `sudo pacman-key --populate archlinux` when you first boot.

Compatible with: No distros currently supported
# <UDF name="hostname" label="Host name" example="Desired host name of your Linode" />
# <UDF name="userpass" label="Unprivileged user password" />
# <UDF name="gitname" label="Full name for git" />
# <UDF name="gitemail" label="Email for git" />

# Setting hostname
echo $HOSTNAME > /etc/hostname

# Setting locale
echo -e "en_GB.UTF-8 UTF-8\nen_US.UTF-8 UTF-8" > /etc/locale.gen
echo 'LANG="en_GB.UTF-8"' > /etc/locale.conf
echo "KEYMAP=uk" > /etc/vconsole.conf

# Setting timezone to London
#ln -s /usr/share/zoneinfo/Europe/London /etc/localtime   # Already set to UTC
#hwclock --systohc --utc

# Initializing pacman
haveged -w 1024
pacman-key --init
pkill haveged
curl "" > ~/pacman.conf
#pacman-key --populate archlinux

# Upgrading system
pacman -Syu --noconfirm --config ~/pacman.conf
pacman -Syu --noconfirm --config ~/pacman.conf
pacman -S --noconfirm --config ~/pacman.conf base-devel htop tmux vim git nginx postgresql redis

# Configuring user: root
echo "%wheel ALL=(ALL) ALL" >> /etc/sudoers

# Configuring user: deployer
useradd -m -g users -G wheel -s /bin/bash deployer
passwd deployer <<EOF
chown -R deployer:users /home/deployer
su - deployer -c "ssh-keygen -t rsa -f ~/.ssh/id_rsa -N $USERPASS"
su - deployer -c 'curl "" > ~/.bashrc'

# Setting up git
su - deployer -c "git config --global '$GITNAME'"
su - deployer -c "git config --global '$GITEMAIL'"

# Setting up ruby
su deployer
cd ~
curl | bash
rbenv install 1.9.3-p194
rbenv global 1.9.3-p194
rbenv bootstrap
rbenv rehash

# Setting up nginx
mkdir /etc/nginx/sites-available
mkdir /etc/nginx/sites-enabled
curl "" > /etc/nginx/nginx.conf
curl "" > /etc/nginx/sites-available/default
systemctl enable nginx
systemctl start nginx

# Setting up postgres
chown -R postgres /var/lib/postgres/
su - postgres -c "initdb --locale en_US.UTF-8 -D '/var/lib/postgres/data'"
su - postgres -c "createuser -d deployer"
mkdir /run/postgresql
chown postgres /run/postgresql/
systemctl enable postgresql
systemctl start postgresql

# Setting up redis
systemctl enable redis
systemctl start redis

# Maybe add a password for the deployer postgres user? Use -P <<EOF etc.