4 ## Do we have enough memory and disk space for Discourse?
6 check_disk_and_memory
() {
9 avail_mem
="$(LANG=C free -m | grep '^Mem:' | awk '{print $2}')"
10 if [ "$avail_mem" -lt 900 ]; then
11 resources
="insufficient"
12 echo "WARNING: Discourse requires 1GB RAM to run. This system does not appear"
13 echo "to have sufficient memory."
15 echo "Your site may not work properly, or future upgrades of Discourse may not"
16 echo "complete successfully."
17 elif [ "$avail_mem" -lt 1800 ]; then
18 total_swap
="$(LANG=C free -m | grep ^Swap: | awk '{print $2}')"
19 if [ "$total_swap" -lt 1000 ]; then
20 resources
="insufficient"
21 echo "WARNING: Discourse requires at least 1GB of swap when running with less "
22 echo "than 2GB of RAM. This system does not appear to have sufficient swap space."
24 echo "Without sufficient swap space, your site may not work properly, or future"
25 echo "upgrades of Discourse may not complete successfully."
27 echo "See https://meta.discourse.org/t/13880"
31 free_disk
="$(df /var | tail -n 1 | awk '{print $4}')"
32 if [ "$free_disk" -lt 5000 ]; then
33 resources
="insufficient"
34 echo "WARNING: Discourse requires at least 5GB free disk space. This system"
35 echo "does not appear to have sufficient disk space."
37 echo "Insufficient disk space may result in problems running your site, and"
38 echo "may not even allow Discourse installation to complete successfully."
40 echo "Please free up some space, or expand your disk, before continuing."
42 echo "Run \`apt-get autoremove && apt-get autoclean\` to clean up unused"
43 echo "packages and \`./launcher cleanup\` to remove stale Docker containers."
47 if [ -t 0 ] && [ "$resources" != "ok" ]; then
49 read -p "Press ENTER to continue, or Ctrl-C to exit and give your system more resources"
55 ## If we have lots of RAM or lots of CPUs, bump up the defaults to scale better
59 local changelog
=/tmp
/changelog.
$PPID
60 # grab info about total system ram and physical (NOT LOGICAL!) CPU cores
61 avail_mem
="$(LANG=C free -m | grep '^Mem:' | awk '{print $2}')"
62 avail_gb
=$
(( $avail_mem / 950 ))
63 avail_cores
=`cat /proc/cpuinfo | grep "cpu cores" | uniq | awk '{print $4}'`
64 echo "Found ${avail_gb}GB of memory and $avail_cores physical CPU cores"
66 # db_shared_buffers: 128MB for 1GB, 256MB for 2GB, or 256MB * GB, max 4096MB
67 if [ "$avail_gb" -eq "1" ]
71 if [ "$avail_gb" -eq "2" ]
75 db_shared_buffers
=$
(( 256 * $avail_gb ))
78 db_shared_buffers
=$
(( db_shared_buffers
< 4096 ? db_shared_buffers
: 4096 ))
80 sed -i -e "s/^ #db_shared_buffers:.*/ db_shared_buffers: \"${db_shared_buffers}MB\"/w $changelog" $config_file
83 echo "setting db_shared_buffers = ${db_shared_buffers}MB"
87 # UNICORN_WORKERS: 2 * GB for 2GB or less, or 2 * CPU, max 8
88 if [ "$avail_gb" -le "2" ]
90 unicorn_workers
=$
(( 2 * $avail_gb ))
92 unicorn_workers
=$
(( 2 * $avail_cores ))
94 unicorn_workers
=$
(( unicorn_workers
< 8 ? unicorn_workers
: 8 ))
96 sed -i -e "s/^ #UNICORN_WORKERS:.*/ UNICORN_WORKERS: ${unicorn_workers}/w $changelog" $config_file
99 echo "setting UNICORN_WORKERS = ${unicorn_workers}"
107 ## standard http / https ports must not be occupied
112 echo "Ports 80 and 443 are free for use"
117 ## check a port to see if it is already in use
121 local valid
=$
(netstat
-tln |
awk '{print $4}' |
grep ":${1}\$")
123 if [ -n "$valid" ]; then
124 echo "Port ${1} appears to already be in use."
126 echo "If you are trying to run Discourse simultaneously with another web"
127 echo "server like Apache or nginx, you will need to bind to a different port"
129 echo "See https://meta.discourse.org/t/17247"
135 ## prompt user for typical Discourse config file values
137 ask_user_for_config
() {
139 local changelog
=/tmp
/changelog.
$PPID
140 local hostname
="discourse.example.com"
141 local developer_emails
="me@example.com,you@example.com"
142 local smtp_address
="smtp.example.com"
143 local smtp_user_name
="postmaster@discourse.example.com"
144 local smtp_password
=""
145 local letsencrypt_account_email
="me@example.com"
146 local letsencrypt_status
="ENTER to skip"
154 while [[ "$config_ok" == "n" ]]
156 if [ ! -z $hostname ]
158 read -p "Hostname for your Discourse? [$hostname]: " new_value
159 if [ ! -z $new_value ]
165 if [ ! -z $developer_emails ]
167 read -p "Email address for admin account? [$developer_emails]: " new_value
168 if [ ! -z $new_value ]
170 developer_emails
=$new_value
174 if [ ! -z $smtp_address ]
176 read -p "SMTP server address? [$smtp_address]: " new_value
177 if [ ! -z $new_value ]
179 smtp_address
=$new_value
183 if [ "$smtp_address" == "smtp.sparkpostmail.com" ]
185 smtp_user_name
="SMTP_Injection"
188 if [ "$smtp_address" == "smtp.sendgrid.net" ]
190 smtp_user_name
="apikey"
193 if [ ! -z $smtp_user_name ]
195 read -p "SMTP user name? [$smtp_user_name]: " new_value
196 if [ ! -z $new_value ]
198 smtp_user_name
=$new_value
202 read -p "SMTP password? [$smtp_password]: " new_value
203 if [ ! -z $new_value ]
205 smtp_password
=$new_value
208 if [ ! -z $letsencrypt_account_email ]
210 read -p "Let's Encrypt account email? ($letsencrypt_status) [$letsencrypt_account_email]: " new_value
211 if [ ! -z $new_value ]
213 letsencrypt_account_email
=$new_value
214 if [ "$new_value" == "off" ]
216 letsencrypt_status
="ENTER to skip"
218 letsencrypt_status
="Enter 'OFF' to disable."
223 echo -e "\nDoes this look right?\n"
224 echo "Hostname : $hostname"
225 echo "Email : $developer_emails"
226 echo "SMTP address : $smtp_address"
227 echo "SMTP username : $smtp_user_name"
228 echo "SMTP password : $smtp_password"
230 if [ "$letsencrypt_status" == "Enter 'OFF' to disable." ]
232 echo "Let's Encrypt : $letsencrypt_account_email"
236 read -p "Press ENTER to continue, 'n' to try again, or ^C to exit: " config_ok
239 sed -i -e "s/^ DISCOURSE_HOSTNAME:.*/ DISCOURSE_HOSTNAME: $hostname/w $changelog" $config_file
244 echo "DISCOURSE_HOSTNAME change failed."
248 sed -i -e "s/^ DISCOURSE_DEVELOPER_EMAILS:.*/ DISCOURSE_DEVELOPER_EMAILS: \'$developer_emails\'/w $changelog" $config_file
253 echo "DISCOURSE_DEVELOPER_EMAILS change failed."
257 sed -i -e "s/^ DISCOURSE_SMTP_ADDRESS:.*/ DISCOURSE_SMTP_ADDRESS: $smtp_address/w $changelog" $config_file
262 echo "DISCOURSE_SMTP_ADDRESS change failed."
266 sed -i -e "s/^ #DISCOURSE_SMTP_USER_NAME:.*/ DISCOURSE_SMTP_USER_NAME: $smtp_user_name/w $changelog" $config_file
271 echo "DISCOURSE_SMTP_USER_NAME change failed."
275 sed -i -e "s/^ #DISCOURSE_SMTP_PASSWORD:.*/ DISCOURSE_SMTP_PASSWORD: $smtp_password/w $changelog" $config_file
280 echo "DISCOURSE_SMTP_PASSWORD change failed."
284 if [ "$letsencrypt_status" != "ENTER to skip" ]
286 sed -i -e "s/^ #LETSENCRYPT_ACCOUNT_EMAIL:.*/ LETSENCRYPT_ACCOUNT_EMAIL: $letsencrypt_account_email/w $changelog" $config_file
291 echo "LETSENCRYPT_ACCOUNT_EMAIL change failed."
294 local src
='^ #- "templates\/web.ssl.template.yml"'
295 local dst
=' \- "templates\/web.ssl.template.yml"'
296 sed -i -e "s/$src/$dst/w $changelog" $config_file
299 echo "web.ssl.template.yml enabled"
302 echo "web.ssl.template.yml NOT ENABLED--was it on already?"
304 local src
='^ #- "templates\/web.letsencrypt.ssl.template.yml"'
305 local dst
=' - "templates\/web.letsencrypt.ssl.template.yml"'
307 sed -i -e "s/$src/$dst/w $changelog" $config_file
310 echo "letsencrypt.ssl.template.yml enabled"
313 echo "letsencrypt.ssl.template.yml NOT ENABLED -- was it on already?"
317 if [ "$update_ok" == "y" ]
319 echo -e "\nConfiguration file at $config_file updated successfully!\n"
321 echo -e "\nUnfortunately, there was an error changing $config_file\n"
327 ## is our config file valid? Does it have the required fields set?
333 for x
in DISCOURSE_SMTP_ADDRESS DISCOURSE_SMTP_USER_NAME DISCOURSE_SMTP_PASSWORD \
334 DISCOURSE_DEVELOPER_EMAILS DISCOURSE_HOSTNAME
336 config_line
=`grep "^ $x:" $config_file`
338 local default
="example.com"
342 if [[ $config_line = *"$default"* ]]
344 echo "$x left at incorrect default of example.com"
347 config_val
=`echo $config_line | awk '{print $2}'`
348 if [ -z $config_val ]
350 echo "$x was left blank"
354 echo "$x not present"
359 if [ "$valid_config" != "y" ]; then
360 echo -e "\nSorry, these $config_file settings aren't valid -- can't continue!"
367 ## template file names
370 template_path
=samples
/standalone.yml
371 config_file
=containers
/$app_name.yml
372 changelog
=/tmp
/changelog
375 ## Check requirements before creating a copy of a config file we won't edit
377 check_disk_and_memory
381 ## make a copy of the simple standalone config file
383 if [ -a $config_file ]
385 echo "The configuration file $config_file already exists!"
387 echo "If you want to delete your old configuration file and start over:"
388 echo "rm $config_file"
391 cp $template_path $config_file
399 ## if we reach this point without exiting, OK to proceed
401 .
/launcher bootstrap
$app_name
402 .
/launcher start
$app_name