14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/shared_infrastructure/systemd/rails.rb', line 14
def write_unit_file(domain_name)
if ENV["SECRET_KEY_BASE"].nil? ||
ENV["DATABASE_USERNAME"].nil? ||
ENV["DATABASE_PASSWORD"].nil? ||
ENV["EMAIL_PASSWORD"].nil?
raise "Missing environment variable"
end
result = File.open(Systemd.unit_file(domain_name), "w") do |f|
f << " [Unit]\n Description=Puma HTTP Server for \#{domain_name}\n After=network.target\n\n # Uncomment for socket activation (see below)\n # Requires=\#{domain_name}.socket\n\n [Service]\n # Foreground process (do not use --daemon in ExecStart or config.rb)\n Type=simple\n\n User=nobody\n Group=www-data\n\n # Specify the path to the Rails application root\n WorkingDirectory=\#{Nginx.root_directory(domain_name)}\n\n # Helpful for debugging socket activation, etc.\n # Environment=PUMA_DEBUG=1\n Environment=RACK_ENV=production\n Environment=RAILS_ENV=production\n Environment=SECRET_KEY_BASE=\#{ENV['SECRET_KEY_BASE']}\n Environment=DATABASE_USERNAME=\#{ENV['DATABASE_USERNAME']}\n Environment=DATABASE_PASSWORD=\#{ENV['DATABASE_PASSWORD']}\n Environment=EMAIL_PASSWORD=\#{ENV['EMAIL_PASSWORD']}\n Environment=REDIS_URL=unix:///tmp/\#{redis_location(domain_name)}.sock\n\n # The command to start Puma\n # NOTE: TLS would be handled by Nginx\n ExecStart=\#{Nginx.root_directory(domain_name)}/bin/puma -b \#{puma_uri(domain_name)} \\\n --redirect-stdout=\#{Nginx.root_directory(domain_name)}/log/puma-production.stdout.log \\\n --redirect-stderr=\#{Nginx.root_directory(domain_name)}/log/puma-production.stderr.log\n # ExecStart=/usr/local/bin/puma -b tcp://\#{puma_uri(domain_name)}\n\n Restart=always\n\n [Install]\n WantedBy=multi-user.target\n UNIT_FILE\n end\n\n FileUtils.chmod(0o600, Systemd.unit_file(domain_name))\n `systemctl enable $domain_name.service` if Process.uid.zero?\n\n result\nend\n"
|