overleaf/chef/cookbooks/sharelatex/providers/app.rb

121 lines
2.2 KiB
Ruby
Raw Normal View History

action :start do
package "git"
package "build-essential"
r = new_resource
deploy_to = "/var/www/" + r.name
node_environment = "production"
directory deploy_to do
user r.user if r.user
recursive true
end
env = {
"HOME" => deploy_to
}
directory "#{deploy_to}/releases" do
user r.user if r.user
recursive true
end
shared_dir = "#{deploy_to}/shared"
directory shared_dir do
user r.user if r.user
recursive true
end
directory "#{shared_dir}/config" do
user r.user if r.user
recursive true
end
directory "#{shared_dir}/log" do
user r.user if r.user
recursive true
end
deploy_revision deploy_to do
repository r.repository
revision r.revision
user r.user if r.user
purge_before_symlink [
"log", "config", "node_modules"
]
create_dirs_before_symlink []
symlinks({
"log" => "log",
"config" => "config"
})
symlink_before_migrate({
"node_modules" => "node_modules"
})
environment env
migrate true
migration_command "npm install; grunt install"
before_migrate do
directory "#{deploy_to}/shared/node_modules" do
user r.user if r.user
recursive true
end
end
2014-03-31 04:40:07 -04:00
notifies :restart, "service[#{r.name}]"
end
2014-03-31 11:41:13 -04:00
env = ""
r.environment.each do |key, value|
env += "#{key}=#{value} "
end
file "/etc/init/#{r.name}.conf" do
content <<-EOS
description "#{r.name}"
author "ShareLaTeX <team@sharelatex.com>"
start on started mountall
stop on shutdown
respawn
limit nofile 8192 8192
script
echo $$ > /var/run/#{r.name}.pid
chdir #{deploy_to}/current
2014-03-31 11:41:13 -04:00
exec sudo -u #{r.user} env NODE_ENV=#{node_environment} SHARELATEX_CONFIG=/etc/sharelatex/settings.coffee #{env} node app.js >> log/production.log 2>&1
end script
EOS
2014-03-31 11:41:13 -04:00
notifies :restart, "service[#{r.name}]"
end
2014-03-31 04:40:07 -04:00
directory "/etc/sharelatex"
template "/etc/sharelatex/settings.coffee" do
mode 0400
user "www-data"
notifies :restart, "service[#{r.name}]"
end
service "#{r.name}" do
provider Chef::Provider::Service::Upstart
action :start
end
file "/etc/logrotate.d/#{r.name}" do
content <<-EOS
#{deploy_to}/shared/log/*.log {
rotate 7
size 5M
missingok
compress
copytruncate
}
EOS
end
end