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
|
# File 'lib/shared_infrastructure/systemd/rails.rb', line 14
def write_unit_file(domain_name, domain, rails_env = "production", user)
puts "writing unit file (domain_name): #{Systemd.unit_file(domain_name)} (#{domain_name})" if Runner.debug
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=\#{user}\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=\#{rails_env}\n Environment=RAILS_ENV=\#{rails_env}\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-\#{rails_env}.stdout.log \\\n --redirect-stderr=\#{Nginx.root_directory(domain_name)}/log/puma-\#{rails_env}.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 puts \"changing mode of unit file\" if Runner.debug\n FileUtils.chmod(0o600, Systemd.unit_file(domain_name))\n puts \"enabling service\" if Runner.debug && Process.uid.zero?\n `systemctl enable \#{domain_name}.service` if Process.uid.zero?\n\n result\nend\n"
|