4 echo "Usage: launcher COMMAND CONFIG [--skip-prereqs] [--skip-discourse-prereqs] [--docker-args STRING]"
6 echo " start: Start/initialize a container"
7 echo " stop: Stop a running container"
8 echo " restart: Restart a container"
9 echo " destroy: Stop and remove a container"
10 echo " enter: Use nsenter to enter a container"
11 echo " logs: Docker logs for container"
12 echo " bootstrap: Bootstrap a container for the config based on a template"
13 echo " rebuild: Rebuild a container (destroy old, bootstrap, start new)"
14 echo " cleanup: Remove all containers that have stopped for > 24 hours"
15 echo " setup: Create a new configuration file and bootstrap"
18 echo " --skip-prereqs Don't check launcher prerequisites"
19 echo " --skip-discourse-prereqs Don't check prerequisites specifiy to Discourse"
20 echo " --docker-args Extra arguments to pass when running docker"
29 while [ ${#} -gt 0 ]; do
35 --skip-discourse-prereqs)
36 SKIP_DISCOURSE_PREREQS
="1"
47 # Docker doesn't like uppercase characters, spaces or special characters, catch it now before we build everything out and then find out
48 re
='[A-Z/ !@#$%^&*()+~`=]'
49 if [[ $config =~
$re ]];
52 echo "ERROR: Config name must not contain upper case characters, spaces or special characters. Correct config name and rerun $0."
59 docker_min_version
='1.6.0'
60 docker_rec_version
='1.6.0'
61 git_min_version
='1.8.0'
62 git_rec_version
='1.8.0'
64 config_file
=containers
/"$config".yml
65 cidbootstrap
=cids
/"$config"_bootstrap.cid
66 local_discourse
=local_discourse
67 image
=discourse
/discourse
:1.0.17
68 docker_path
=`which docker.io || which docker`
70 template_path
=samples
/standalone.yml
71 changelog
=/tmp
/changelog
# used to test whether sed did anything
73 if [ "${SUPERVISED}" = "true" ]; then
74 restart_policy
="--restart=no"
76 attach_on_run
="-a stdout -a stderr"
81 if [ -n "$DOCKER_HOST" ]; then
82 docker_ip
=`sed -e 's/^tcp:\/\/\(.*\):.*$/\1/' <<< "$DOCKER_HOST"`
83 elif [ -x "$(which ip 2>/dev/null)" ]; then
84 docker_ip
=`ip addr show docker0 | \
86 awk '{ split($2,a,"/"); print a[1] }';`
88 docker_ip
=`ifconfig | \
89 grep -B1 "inet addr" | \
90 awk '{ if ( $1 == "inet" ) { print $2 } else if ( $2 == "Link" ) { printf "%s:" ,$1 } }' | \
92 awk -F: '{ print $3 }';`
98 IFS
=.
read -a ver_a
<<< "$1"
99 IFS
=.
read -a ver_b
<<< "$2"
101 while [[ -n $ver_a ]]; do
102 if (( ver_a
> ver_b
)); then
104 elif (( ver_b
> ver_a
)); then
108 ver_a
=("${ver_a[@]}")
110 ver_b
=("${ver_b[@]}")
113 return 1 # They are equal
119 echo "Docker is not installed, you will need to install Docker in order to run Discourse"
120 echo "Please visit https://docs.docker.com/installation/ for instructions on how to do this for your system"
122 echo "If you are running a recent Ubuntu Server, try the following:"
123 echo "sudo apt-get install docker-engine"
130 if [ -z $docker_path ]; then
134 # 1. docker daemon running?
135 # we send stderr to /dev/null cause we don't care about warnings,
136 # it usually complains about swap which does not matter
137 test=`$docker_path info 2> /dev/null`
138 if [[ $?
-ne 0 ]] ; then
139 echo "Cannot connect to the docker daemon - verify it is running and you have access"
143 # 2. running aufs or btrfs
144 test=`$docker_path info 2> /dev/null | grep 'Driver: '`
145 if [[ "$test" =~
[aufs|btrfs|zfs|overlay
] ]] ; then : ; else
146 echo "Your Docker installation is not using a supported filesystem if we were to proceed you may have a broken install."
147 echo "aufs is the recommended filesystem you should be using (zfs/btrfs and overlay may work as well)"
148 echo "You can tell what filesystem you are using by running \"docker info\" and looking at the driver"
150 echo "If you wish to continue anyway using your existing unsupported filesystem, "
151 echo "read the source code of launcher and figure out how to bypass this."
155 # 3. running recommended docker version
156 test=($
($docker_path --version)) # Get docker version string
157 test=${test[2]//,/} # Get version alone and strip comma if exists
159 # At least minimum docker version
160 if compare_version
"${docker_min_version}" "${test}"; then
161 echo "ERROR: Docker version ${test} not supported, please upgrade to at least ${docker_min_version}, or recommended ${docker_rec_version}"
165 # Recommend newer docker version
166 if compare_version
"${docker_rec_version}" "${test}"; then
167 echo "WARNING: Docker version ${test} deprecated, recommend upgrade to ${docker_rec_version} or newer."
170 # 4. discourse docker image is downloaded
171 test=`$docker_path images | awk '{print $1 ":" $2 }' | grep "$image"`
173 if [ -z "$test" ]; then
175 echo "WARNING: We are about to start downloading the Discourse base image"
176 echo "This process may take anywhere between a few minutes to an hour, depending on your network speed"
178 echo "Please be patient"
183 # 5. running recommended git version
184 test=($
($git_path --version)) # Get git version string
185 test=${test[2]//,/} # Get version alone and strip comma if exists
187 # At least minimum version
188 if compare_version
"${git_min_version}" "${test}"; then
189 echo "ERROR: Git version ${test} not supported, please upgrade to at least ${git_min_version}, or recommended ${git_rec_version}"
193 # Recommend best version
194 if compare_version
"${git_rec_version}" "${test}"; then
195 echo "WARNING: Git version ${test} deprecated, recommend upgrade to ${git_rec_version} or newer."
198 # 6. able to attach stderr / out / tty
199 test=`$docker_path run $user_args -i --rm -a stdout -a stderr $image echo working`
200 if [[ "$test" =~
"working" ]] ; then : ; else
201 echo "Your Docker installation is not working correctly"
203 echo "See: https://meta.discourse.org/t/docker-error-on-bootstrap/13657/18?u=sam"
214 avail_mem
="$(LANG=C free -m | grep '^Mem:' | awk '{print $2}')"
215 if [ "$avail_mem" -lt 900 ]; then
216 resources
="insufficient"
217 echo "WARNING: You do not appear to have sufficient memory to run Discourse."
219 echo "Your system may not work properly, or future upgrades of Discourse may"
220 echo "not complete successfully."
222 echo "See https://github.com/discourse/discourse/blob/master/docs/INSTALL-cloud.md#create-new-cloud-server"
223 elif [ "$avail_mem" -lt 1800 ]; then
224 total_swap
="$(LANG=C free -m | grep ^Swap: | awk '{print $2}')"
225 if [ "$total_swap" -lt 1000 ]; then
226 resources
="insufficient"
227 echo "WARNING: You must have at least 1GB of swap when running with less"
228 echo "than 2GB of RAM."
230 echo "Your system may not work properly, or future upgrades of Discourse may"
231 echo "not complete successfully."
233 echo "See https://github.com/discourse/discourse/blob/master/docs/INSTALL-cloud.md#set-up-swap-if-needed"
238 free_disk
="$(df /var | tail -n 1 | awk '{print $4}')"
239 if [ "$free_disk" -lt 5000 ]; then
240 resources
="insufficient"
241 echo "WARNING: You must have at least 5GB of *free* disk space to run Discourse."
243 echo "Insufficient disk space may result in problems running your site, and may"
244 echo "not even allow Discourse installation to complete successfully."
246 echo "Please free up some space, or expand your disk, before continuing."
248 echo "Run \`apt-get autoremove && apt-get autoclean\` to clean up unused packages and \`./launcher cleanup\` to remove stale Docker containers."
252 if [ -t 0 ] && [ "$resources" != "ok" ]; then
254 read -p "Press ENTER to continue, or Ctrl-C to exit and give your system more resources"
259 local valid
=$
(netstat
-tln |
awk '{print $4}' |
grep ":${1}\$")
261 if [ -n "$valid" ]; then
262 echo "Launcher has detected that port ${1} is in use."
264 echo "If you are trying to run Discourse simultaneously with another web server like Apache or nginx, you will need to bind to a different port."
265 echo "See https://meta.discourse.org/t/17247 for help."
266 echo "To continue anyway, re-run Launcher with --skip-prereqs"
271 if [ -z "$SKIP_PREREQS" ] ; then
276 read -r -d '' env_ruby
<< 'RUBY'
279 input
= STDIN.readlines.
join
280 yaml
= YAML.load
(input
)
282 if host_run
= yaml
['host_run']
283 params
= yaml
['params'] ||
{}
284 host_run.each
do |run|
286 run
= run.gsub
("$#{k}", v
)
288 STDOUT.
write "#{run}--SEP--"
293 host_run
=`cat $config_file | $docker_path run $user_args --rm -i -a stdout -a stdin $image ruby -e "$env_ruby"`
295 while [ "$host_run" ] ; do
296 iter
=${host_run%%--SEP--*}
298 echo "Host run: $iter"
301 host_run
="${host_run#*--SEP--}"
307 volumes
=`cat $config_file | $docker_path run $user_args --rm -i -a stdout -a stdin $image ruby -e \
308 "require 'yaml'; puts YAML.load(STDIN.readlines.join)['volumes'].map{|v| '-v ' << v['volume']['host'] << ':' << v['volume']['guest'] << ' '}.join"`
312 links
=`cat $config_file | $docker_path run $user_args --rm -i -a stdout -a stdin $image ruby -e \
313 "require 'yaml'; puts YAML.load(STDIN.readlines.join)['links'].map{|l| '--link ' << l['link']['name'] << ':' << l['link']['alias'] << ' '}.join"`
316 set_template_info
() {
318 templates
=`cat $config_file | $docker_path run $user_args --rm -i -a stdin -a stdout $image ruby -e \
319 "require 'yaml'; puts YAML.load(STDIN.readlines.join)['templates']"`
321 arrTemplates
=(${templates// / })
322 config_data
=$
(cat $config_file)
326 for template
in "${arrTemplates[@]}"
328 [ ! -z $template ] && {
329 input
="$input _FILE_SEPERATOR_ $(cat $template)"
333 # we always want our config file last so it takes priority
334 input
="$input _FILE_SEPERATOR_ $config_data"
336 read -r -d '' env_ruby
<< 'RUBY'
339 input
=STDIN.readlines.
join
340 # default to UTF-8 for the dbs sake
341 env
= {'LANG' => 'en_US.UTF-8'}
342 input.
split('_FILE_SEPERATOR_').each
do |yml|
345 env.merge
!(YAML.load
(yml
)['env'] ||
{})
346 rescue Psych
::SyntaxError
=> e
354 puts env.map
{|k
,v|
"-e\n#{k}=#{v}" }.
join("\n")
357 raw
=`exec echo "$input" | $docker_path run $user_args --rm -i -a stdin -a stdout $image ruby -e "$env_ruby"`
362 if [ "$i" == "*ERROR." ]; then
364 elif [ -n "$i" ]; then
369 if [ "$ok" -ne 1 ]; then
371 echo "YAML syntax error. Please check your /var/discourse/containers/*.yml config files."
376 if [ -z $docker_path ]; then
380 [ "$command" == "cleanup" ] && {
382 echo "The following command will"
383 echo "- Delete all docker images for old containers"
384 echo "- Delete all stopped and orphan containers"
386 read -p "Are you sure (Y/n): " -n 1 -r && echo
387 if [[ $REPLY =~ ^
[Yy
]$ ||
! $REPLY ]]
389 space
=$
(df
/var
/lib
/docker |
awk '{ print $4 }' |
grep -v Available
)
390 echo "Starting Cleanup (bytes free $space)"
392 STATE_DIR
=.
/.gc-state
scripts
/docker-gc
394 space
=$
(df
/var
/lib
/docker |
awk '{ print $4 }' |
grep -v Available
)
395 echo "Finished Cleanup (bytes free $space)"
403 if [ -z "$command" -a -z "$config" ]; then
407 if [ ! "$command" == "setup" ]; then
408 if [[ ! -e $config_file ]]; then
409 echo "Config file was not found, ensure $config_file exists"
411 echo "Available configs ( `cd containers && ls -dm *.yml | tr -s '\n' ' ' | awk '{ gsub(/\.yml/, ""); print }'`)"
416 docker_version
=($
($docker_path --version))
417 docker_version
=${test[2]//,/}
418 restart_policy
=${restart_policy:---restart=always}
420 set_existing_container
(){
421 existing
=`$docker_path ps -a | awk '{ print $1, $(NF) }' | grep " $config$" | awk '{ print $1 }'`
426 set_existing_container
428 if [ ! -z $existing ]
432 $docker_path stop
-t 10 $config
435 echo "$config was not started !"
441 run_image
=`cat $config_file | $docker_path run $user_args --rm -i -a stdin -a stdout $image ruby -e \
442 "require 'yaml'; puts YAML.load(STDIN.readlines.join)['run_image']"`
444 if [ -z "$run_image" ]; then
445 run_image
="$local_discourse/$config"
450 boot_command
=`cat $config_file | $docker_path run $user_args --rm -i -a stdin -a stdout $image ruby -e \
451 "require 'yaml'; puts YAML.load(STDIN.readlines.join)['boot_command']"`
453 if [ -z "$boot_command" ]; then
455 no_boot_command
=`cat $config_file | $docker_path run $user_args --rm -i -a stdin -a stdout $image ruby -e \
456 "require 'yaml'; puts YAML.load(STDIN.readlines.join)['no_boot_command']"`
458 if [ -z "$no_boot_command" ]; then
459 boot_command
="/sbin/boot"
464 scale_ram_and_cpu
() {
466 # grab info about total system ram and physical (NOT LOGICAL!) CPU cores
467 avail_mem
="$(LANG=C free -m | grep '^Mem:' | awk '{print $2}')"
468 avail_gb
=$
(( $avail_mem / 950 ))
469 avail_cores
=`cat /proc/cpuinfo | grep "cpu cores" | uniq | awk '{print $4}'`
470 echo "Found ${avail_gb}GB of memory and $avail_cores physical CPU cores"
472 # db_shared_buffers: 128MB for 1GB, 256MB for 2GB, or 256MB * GB, max 4096MB
473 if [ "$avail_gb" -eq "1" ]
475 db_shared_buffers
=128
477 if [ "$avail_gb" -eq "2" ]
479 db_shared_buffers
=256
481 db_shared_buffers
=$
(( 256 * $avail_gb ))
484 db_shared_buffers
=$
(( db_shared_buffers
< 4096 ? db_shared_buffers
: 4096 ))
486 sed -i -e "s/^ #db_shared_buffers:.*/ db_shared_buffers: \"${db_shared_buffers}MB\"/w $changelog" $config_file
489 echo "setting db_shared_buffers = ${db_shared_buffers}MB based on detected CPU/RAM"
494 # UNICORN_WORKERS: 2 * GB for 2GB or less, or 2 * CPU, max 8
495 if [ "$avail_gb" -le "2" ]
497 unicorn_workers
=$
(( 2 * $avail_gb ))
499 unicorn_workers
=$
(( 2 * $avail_cores ))
501 unicorn_workers
=$
(( unicorn_workers
< 8 ? unicorn_workers
: 8 ))
503 sed -i -e "s/^ #UNICORN_WORKERS:.*/ UNICORN_WORKERS: ${unicorn_workers}/w $changelog" $config_file
506 echo "setting UNICORN_WORKERS = ${unicorn_workers} based on detected CPU/RAM"
513 if [ -f $config_file ]
515 echo $config_file exists already.
516 echo To remove it use
: rm $config_file
519 cp .
/samples
/standalone.yml
$config_file
520 if [ ! -f $config_file ]
522 echo Unable to copy
$config_file. Are you root?
526 local hostname
="discourse.example.com"
527 local developer_emails
="me@example.com"
528 local smtp_address
="smtp.example.com"
529 local smtp_user_name
="user@example.com"
530 local smtp_password
="pa\$\$word"
531 local letsencrypt_account_email
="your.email@example.com"
532 local letsencrypt_status
="change to enable"
535 local letsencrypt_status
="change to enable"
536 local config_sane
="n"
540 while [[ "$config_ok" == "n" ||
"$config_sane" == "n" ]]
542 if [ ! -z $hostname ]
544 read -p "hostname: [$hostname]: " new_value
545 if [ ! -z $new_value ]
552 if [ ! -z $developer_emails ]
554 read -p "developer_emails [$developer_emails]: " new_value
555 if [ ! -z $new_value ]
557 developer_emails
=$new_value
560 if [ ! -z $smtp_address ]
562 read -p "smtp_address [$smtp_address]: " new_value
563 if [ ! -z $new_value ]
565 smtp_address
=$new_value
568 if [ "$smtp_address" == "smtp.sparkpostmail.com" ]
570 smtp_user_name
="SMTP_Injection"
573 if [ "$smtp_address" == "smtp.sendgrid.net" ]
575 smtp_user_name
="apikey"
577 if [ ! -z $smtp_user_name ]
579 read -p "smtp_user_name [$smtp_user_name]: " new_value
580 if [ ! -z $new_value ]
582 smtp_user_name
=$new_value
585 if [ ! -z $smtp_password ]
587 read -p "smtp_password [$smtp_password]: " new_value
588 if [ ! -z $new_value ]
590 smtp_password
=$new_value
593 if [ ! -z $letsencrypt_account_email ]
595 read -p "letsencrypt_account_email ($letsencrypt_status) [$letsencrypt_account_email]: " new_value
596 if [ ! -z $new_value ]
598 letsencrypt_account_email
=$new_value
599 if [ "$new_value" == "off" ]
601 letsencrypt_status
="change to enable"
603 letsencrypt_status
="Enter 'OFF' to disable."
604 echo "Letsencrypt enabled."
607 echo "letsencrypt unchanged"
611 #TODO sanity check these values. For now we trust the user's input.
614 if [ "$config_sane" == "y" ]
616 echo -e "\nThat's it! Everything is set. Read carefully before continuing.\n"
618 echo "Errors found in settings"
621 echo "DISCOURSE_HOSTNAME: $hostname"
622 echo "DISCOURSE_DEVELOPER_EMAILS: $developer_emails"
623 echo "DISCOURSE_SMTP_ADDRESS: $smtp_address"
624 echo "DISCOURSE_SMTP_USER_NAME: $smtp_user_name"
625 echo "DISCOURSE_SMTP_PASSWORD: $smtp_password"
626 if [ "$letsencrypt_status" == "Enter 'OFF' to disable." ]
628 echo "LETSENCRYPT_ACCOUNT_EMAIL: $letsencrypt_account_email"
629 echo "LETSENCRYPT will be enabled."
631 echo "LETSENCRYPT will not be enabled."
634 read -p "Enter to write these settings to $config_file, 'N' to retry, or ^C to start again: " config_ok
637 echo -e "\nWriting changes to $config_file:"
638 sed -i -e "s/^ DISCOURSE_HOSTNAME: 'discourse.example.com'/ DISCOURSE_HOSTNAME: $hostname/w $changelog" $config_file
644 echo DISCOURSE_HOSTNAME change failed.
648 sed -i -e "s/^ DISCOURSE_DEVELOPER_EMAILS:.*/ DISCOURSE_DEVELOPER_EMAILS: \'$developer_emails\'/w $changelog" $config_file
654 echo DISCOURSE_DEVELOPER_EMAILS change failed.
658 sed -i -e "s/^ DISCOURSE_SMTP_ADDRESS: smtp.example.com.*/ DISCOURSE_SMTP_ADDRESS: $smtp_address/w $changelog" $config_file
664 echo DISCOURSE_SMTP_ADDRESS change failed.
668 sed -i -e "s/^ #DISCOURSE_SMTP_USER_NAME: user@example.com.*/ DISCOURSE_SMTP_USER_NAME: $smtp_user_name/w $changelog" $config_file
674 echo DISCOURSE_SMTP_USER_NAME change failed.
678 sed -i -e "s/^ #DISCOURSE_SMTP_PASSWORD: pa\$\$word.*/ DISCOURSE_SMTP_PASSWORD: $smtp_password/w $changelog" $config_file
684 echo DISCOURSE_SMTP_PASSWORD change failed.
688 if [ "$letsencrypt_status" != "change to enable" ]
690 sed -i -e "s/^ #LETSENCRYPT_ACCOUNT_EMAIL: your.email@example.com/ LETSENCRYPT_ACCOUNT_EMAIL: $letsencrypt_account_email/w $changelog" $config_file
696 echo LETSENCRYPT_ACCOUNT_EMAIL change failed.
699 local src
='^ #- "templates\/web.ssl.template.yml"'
700 local dst
=' \- "templates\/web.ssl.template.yml"'
701 sed -i -e "s/$src/$dst/w $changelog" $config_file
704 echo " web.ssl.template.yml enabled"
707 echo " web.ssl.template.yml NOT ENABLED--was it on already?"
709 local src
='^ #- "templates\/web.letsencrypt.ssl.template.yml"'
710 local dst
=' - "templates\/web.letsencrypt.ssl.template.yml"'
712 sed -i -e "s/$src/$dst/w $changelog" $config_file
715 echo " letsencrypt.ssl.template.yml enabled"
718 echo "letsencrypt.ssl.template.yml NOT ENABLED--was it on already?"
720 fi # enable letsencrypt
722 if [ "$update_ok" == "y" ]
724 echo -e "\n$config_file updated successfully."
726 echo -e "There was an error changing the configuration.\n"
732 existing
=`$docker_path ps | awk '{ print $1, $(NF) }' | grep " $config$" | awk '{ print $1 }'`
734 if [ ! -z $existing ]
736 echo "Nothing to do, your container has already started!"
740 existing
=`$docker_path ps -a | awk '{ print $1, $(NF) }' | grep " $config$" | awk '{ print $1 }'`
741 if [ ! -z $existing ]
743 echo "starting up existing container"
746 $docker_path start
$config
753 if [ -z "$SKIP_DISCOURSE_PREREQS" ] ; then
754 ports
=`cat $config_file | $docker_path run $user_args --rm -i -a stdout -a stdin $image ruby -e \
755 "require 'yaml'; puts YAML.load(STDIN.readlines.join)['expose'].map{|p| \"-p #{p}\"}.join(' ')"`
757 IFS
='-p ' read -a array
<<< "$ports"
758 for element
in "${array[@]}"
760 IFS
=':' read -a args
<<< "$element"
761 if [ "${#args[@]}" == "2" ]; then
762 check_ports
"${args[0]}"
763 elif [ "${#args[@]}" == "3" ]; then
764 check_ports
"${args[1]}"
769 docker_args
=`cat $config_file | $docker_path run $user_args --rm -i -a stdout -a stdin $image ruby -e \
770 "require 'yaml'; puts YAML.load(STDIN.readlines.join)['docker_args']"`
778 # get hostname and settings from container configuration
779 for envar
in "${env[@]}"
781 if [[ $envar == DOCKER_USE_HOSTNAME
* ]] ||
[[ $envar == DISCOURSE_HOSTNAME
* ]]
783 # use as environment variable
789 hostname
=`hostname -s`
791 if [ "$DOCKER_USE_HOSTNAME" = "true" ]
793 hostname
=$DISCOURSE_HOSTNAME
795 hostname
=$hostname-$config
798 # we got to normalize so we only have allowed strings, this is more comprehensive but lets see how bash does first
799 # hostname=`$docker_path run $user_args --rm $image ruby -e 'print ARGV[0].gsub(/[^a-zA-Z-]/, "-")' $hostname`
800 # docker added more hostname rules
801 hostname
=${hostname/_/-}
804 $docker_path run
$user_args $links $attach_on_run $restart_policy "${env[@]}" -h "$hostname" \
805 -e DOCKER_HOST_IP
=$docker_ip --name $config -t $ports $volumes $docker_args $run_image $boot_command
812 valid_config_check
() {
815 for x
in DISCOURSE_SMTP_ADDRESS DISCOURSE_SMTP_USER_NAME DISCOURSE_SMTP_PASSWORD \
816 DISCOURSE_DEVELOPER_EMAILS DISCOURSE_HOSTNAME
818 mail_var
=`grep "^ $x:" $config_file`
820 local default
="example.com"
823 if [[ $mail_var = *"$default"* ]]
825 echo "Warning: $x left at incorrect default of example.com"
829 echo "Warning: $x not configured"
833 if [ -t 0 ] && [ "$valid_config" != "y" ]; then
835 read -p "Press Ctrl-C to exit and edit $config_file or ENTER to continue"
840 if [ -z "$SKIP_DISCOURSE_PREREQS" ] ; then
841 # Does your system meet the minimum requirements?
844 # is our configuration file valid?
847 # make minor scaling adjustments for RAM and CPU
851 # I got no frigging clue what this does, ask Sam Saffron. It RUNS STUFF ON THE HOST I GUESS?
854 # Is the image available?
855 # If not, pull it here so the user is aware what's happening.
856 $docker_path history $image >/dev
/null
2>&1 ||
$docker_path pull
$image
860 base_image
=`cat $config_file | $docker_path run $user_args --rm -i -a stdin -a stdout $image ruby -e \
861 "require 'yaml'; puts YAML.load(STDIN.readlines.join)['base_image']"`
863 update_pups
=`cat $config_file | $docker_path run $user_args --rm -i -a stdin -a stdout $image ruby -e \
864 "require 'yaml'; puts YAML.load(STDIN.readlines.join)['update_pups']"`
866 if [[ ! X
"" = X
"$base_image" ]]; then
875 run_command
="cd /pups &&"
876 if [[ ! "false" = $update_pups ]]; then
877 run_command
="$run_command git pull &&"
879 run_command
="$run_command /pups/bin/pups --stdin"
883 (exec echo "$input" |
$docker_path run
$user_args $links "${env[@]}" -e DOCKER_HOST_IP
=$docker_ip --cidfile $cidbootstrap -i -a stdin
-a stdout
-a stderr
$volumes $image \
884 /bin
/bash
-c "$run_command") \
885 ||
($docker_path rm `cat $cidbootstrap` && rm $cidbootstrap)
887 [ ! -e $cidbootstrap ] && echo "** FAILED TO BOOTSTRAP ** please scroll up and look for earlier error messages, there may be more than one" && exit 1
891 $docker_path commit
`cat $cidbootstrap` $local_discourse/$config ||
echo 'FAILED TO COMMIT'
892 $docker_path rm `cat $cidbootstrap` && rm $cidbootstrap
900 echo "Successfully bootstrapped, to startup use ./launcher start $config"
906 read -p "Press ENTER to continue, or Ctrl-C to exit to check $config_file"
912 exec $docker_path exec -it $config /bin
/bash
--login
922 $docker_path logs
$config
938 if [ "$(git symbolic-ref --short HEAD)" == "master" ]; then
939 echo "Ensuring discourse docker is up to date"
943 LOCAL
=$
(git rev-parse @
)
944 REMOTE
=$
(git rev-parse @
{u
})
945 BASE
=$
(git merge-base @ @
{u
})
947 if [ $LOCAL = $REMOTE ]; then
948 echo "Discourse Docker is up-to-date"
950 elif [ $LOCAL = $BASE ]; then
951 echo "Updating Discourse Docker"
952 git pull ||
(echo 'failed to update' && exit 1)
955 elif [ $REMOTE = $BASE ]; then
956 echo "Your version of Discourse Docker is ahead of origin"
959 echo "Discourse Docker has diverged source, this is only expected in Dev mode"
964 set_existing_container
966 if [ ! -z $existing ]
968 echo "Stopping old container"
971 $docker_path stop
-t 10 $config
977 if [ ! -z $existing ]
979 echo "Removing old container"
982 $docker_path rm $config
992 (set -x; $docker_path stop
-t 10 $config && $docker_path rm $config) ||
(echo "$config was not found" && exit 0)