1
+ #!/usr/bin/env puma
2
+ require 'dotenv'
3
+ Dotenv . load
4
+ root = ENV [ 'WEB_ROOT' ] || "/home/vagrant/web/"
5
+ # The directory to operate out of.
6
+ #
7
+ # The default is the current directory.
8
+ #
9
+
10
+ # Set the environment in which the rack's app will run. The value must be a string.
11
+ #
12
+ # The default is “development”. (pass with environment variable, -e)
13
+ #
14
+ # environment "development"
15
+
16
+ # Daemonize the server into the background. Highly suggest that
17
+ # this be combined with “pidfile” and “stdout_redirect”.
18
+ #
19
+ # The default is “false”.
20
+ #
21
+ daemonize true
22
+ # daemonize false
23
+
24
+ # Store the pid of the server in the file at “path”.
25
+ #
26
+ pidfile "#{ root } tmp/pids/puma.pid"
27
+
28
+ # Use “path” as the file to store the server info state. This is
29
+ # used by “pumactl” to query and control the server.
30
+ #
31
+ #state_path '/Users/justinraines/Code/flu-vaccine-map/tmp/pids/puma.state'
32
+
33
+ # Redirect STDOUT and STDERR to files specified. The 3rd parameter
34
+ # (“append”) specifies whether the output is appended, the default is
35
+ # “false”.
36
+ #
37
+ stdout_redirect "#{ root } log/puma.stdout.log" , "#{ root } log/puma.stderr.log" , true
38
+ # stdout_redirect '/u/apps/lolcat/log/stdout', '/u/apps/lolcat/log/stderr', true
39
+
40
+ # Disable request logging.
41
+ #
42
+ # The default is “false”.
43
+ #
44
+ # quiet
45
+
46
+ # Configure “min” to be the minimum number of threads to use to answer
47
+ # requests and “max” the maximum.
48
+ #
49
+ # The default is “0, 16”.
50
+ #
51
+ threads ENV [ 'WEB_MIN_CONCURRENCY' ] || 0 , ENV [ 'WEB_MAX_CONCURRENCY' ] || 16
52
+
53
+ # Bind the server to “url”. “tcp://”, “unix://” and “ssl://” are the only
54
+ # accepted protocols.
55
+ #
56
+ # The default is “tcp://0.0.0.0:9292”.
57
+ #
58
+ bind ENV [ 'WEB_PORT' ] || "tcp://0.0.0.0:3000"
59
+
60
+ # bind 'unix:///var/run/puma.sock'
61
+ # bind 'unix:///var/run/puma.sock?umask=0777'
62
+ # bind 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'
63
+
64
+ # Instead of “bind 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'” you
65
+ # can also use the “ssl_bind” option.
66
+ #
67
+ # ssl_bind '127.0.0.1', '9292', { key: path_to_key, cert: path_to_cert }
68
+
69
+ # Code to run before doing a restart. This code should
70
+ # close log files, database connections, etc.
71
+ #
72
+ # This can be called multiple times to add code each time.
73
+ #
74
+ on_restart do
75
+ defined? ( ActiveRecord ::Base ) and
76
+ ActiveRecord ::Base . connection . disconnect!
77
+
78
+ if defined? ( Resque )
79
+ Resque . redis . quit
80
+ Rails . logger . info ( 'Disconnected from Redis' )
81
+ end
82
+ end
83
+
84
+ # Command to use to restart puma. This should be just how to
85
+ # load puma itself (ie. 'ruby -Ilib bin/puma'), not the arguments
86
+ # to puma, as those are the same as the original process.
87
+ #
88
+ # restart_command '/u/app/lolcat/bin/restart_puma'
89
+
90
+ # === Cluster mode ===
91
+
92
+ # How many worker processes to run.
93
+ #
94
+ # The default is “0”.
95
+ #
96
+ workers ENV [ 'WEB_WORKERS' ] || 4
97
+
98
+ # Code to run when a worker boots to setup the process before booting
99
+ # the app.
100
+ #
101
+ # This can be called multiple times to add hooks.
102
+ #
103
+ on_worker_boot do
104
+ defined? ( ActiveRecord ::Base ) and
105
+ ActiveRecord ::Base . establish_connection ( Rails . application . config . database_configuration [ Rails . env ] )
106
+
107
+ if defined? ( Resque )
108
+ Resque . redis = ENV [ 'REDIS_URL' ]
109
+ Rails . logger . info ( 'Connected to Redis' )
110
+ end
111
+ end
112
+
113
+ # Preload app to make use of ruby 2.0 features
114
+ preload_app!
115
+
116
+ # === Puma control rack application ===
117
+
118
+ # Start the puma control rack application on “url”. This application can
119
+ # be communicated with to control the main server. Additionally, you can
120
+ # provide an authentication token, so all requests to the control server
121
+ # will need to include that token as a query parameter. This allows for
122
+ # simple authentication.
123
+ #
124
+ # Check out https://github.com/puma/puma/blob/master/lib/puma/app/status.rb
125
+ # to see what the app has available.
126
+ #
127
+ # activate_control_app 'unix:///var/run/pumactl.sock'
128
+ # activate_control_app 'unix:///var/run/pumactl.sock', { auth_token: '12345' }
129
+ # activate_control_app 'unix:///var/run/pumactl.sock', { no_token: true }
0 commit comments