Created
July 24, 2016 11:50
-
-
Save kymmt90/9b7709cf57369aeae70d87f10524c1a1 to your computer and use it in GitHub Desktop.
2016-07-24 時点の kymmt.com 用 Itamae レシピ
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
include_recipe 'selinux::disabled' | |
package 'epel-release' | |
package 'gcc' | |
package 'gcc-c++' | |
package 'git' | |
package 'libyaml-devel' | |
package 'nginx' | |
package 'openssl-devel' | |
package 'postgresql-contrib' | |
package 'postgresql-devel' | |
package 'postgresql-server' | |
package 'readline-devel' | |
package 'zlib-devel' | |
module ResourceHelper | |
def sudo(user) | |
"sudo -u #{user} -i" | |
end | |
end | |
Itamae::Resource::Base::EvalContext.include(ResourceHelper) | |
include_recipe 'rbenv::system' | |
execute 'add rbenv.sh to /etc/profile.d/' do | |
command <<-EOL | |
echo 'export RBENV_ROOT=/usr/local/rbenv' >>/etc/profile.d/rbenv.sh | |
echo 'export PATH=\"${RBENV_ROOT}/bin:${PATH}\"' >>/etc/profile.d/rbenv.sh | |
echo 'eval "$(rbenv init -)"' >>/etc/profile.d/rbenv.sh | |
EOL | |
not_if 'test -f /etc/profile.d/rbenv.sh' | |
end | |
execute 'install bundler' do | |
command "#{sudo('vagrant')} gem i bundler" | |
not_if "#{sudo('vagrant')} gem list | grep bundler" | |
end | |
KYMMT_DIR = node['kymmt']['dir'] | |
git KYMMT_DIR do | |
repository 'git://github.com/kymmt90/kymmt.com.git' | |
user 'vagrant' | |
end | |
execute 'bundle install' do | |
command "#{sudo('vagrant')} sh -c 'cd #{KYMMT_DIR} ; bundle --without test development'" | |
not_if "#{sudo('vagrant')} sh -c 'cd #{KYMMT_DIR} ; bundle check'" | |
end | |
remote_file '/etc/nginx/nginx.conf' do | |
source './nginx.conf' | |
owner 'root' | |
group 'root' | |
mode '644' | |
notifies :reload, 'service[nginx]' | |
end | |
service 'nginx' do | |
action [:enable, :start] | |
end | |
# TODO: setting Let's Encrypt | |
execute 'init postgresql' do | |
command 'postgresql-setup initdb' | |
not_if 'test -n "$(ls -A /var/lib/pgsql/data)"' | |
end | |
remote_file '/var/lib/pgsql/data/pg_hba.conf' do | |
source './pg_hba.conf' | |
owner 'postgres' | |
group 'postgres' | |
mode '600' | |
end | |
service 'postgresql' do | |
action [:enable, :start] | |
end | |
execute 'create user' do | |
user_exists = <<-EOL | |
#{sudo('postgres')} sh -c "psql -c \\"SELECT * FROM pg_user WHERE usename='#{node['kymmt']['dbuser']}'\\"" | grep #{node['kymmt']['dbuser']} | |
EOL | |
command <<-EOL | |
#{sudo('postgres')} sh -c "psql -c \\"CREATE USER #{node['kymmt']['dbuser']} WITH PASSWORD '#{node['kymmt']['dbpassword']}'\\"" | |
EOL | |
not_if user_exists | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment