Switch launcher to use PG 10.
authorGuo Xiang Tan <tgx_world@hotmail.com>
Wed, 4 Apr 2018 03:07:39 +0000 (11:07 +0800)
committerGuo Xiang Tan <tgx_world@hotmail.com>
Wed, 4 Apr 2018 06:26:23 +0000 (14:26 +0800)
launcher
templates/postgres.10.template.yml
templates/postgres.9.5.template.yml
templates/postgres.template.yml

index 0a4fb23c61b616eb8ca98919651f9b573511887f..e7ff177aa507f1ab163552d42f07a476d1c6d04b 100755 (executable)
--- a/launcher
+++ b/launcher
@@ -64,7 +64,7 @@ git_rec_version='1.8.0'
 config_file=containers/"$config".yml
 cidbootstrap=cids/"$config"_bootstrap.cid
 local_discourse=local_discourse
-image=discourse/base:2.0.20171231
+image=discourse/base:2.0.20180404
 docker_path=`which docker.io || which docker`
 git_path=`which git`
 
index b6c1abd16a5d2b97b64aec6184ea50a5e7abcbbd..b9f85ed6d0d2a68ff4807849676141996a4d0d18 100644 (file)
@@ -19,8 +19,6 @@ hooks:
        to: sv start postgres || exit 1
 
 run:
-  - exec: apt-get remove -y postgresql-9.5 postgresql-client-9.5 postgresql-contrib-9.5
-  - exec: apt-get update && apt-get install -y postgresql-10 postgresql-client-10 postgresql-contrib-10
   - exec: mkdir -p /shared/postgres_run
   - exec: chown postgres:postgres /shared/postgres_run
   - exec: chmod 775 /shared/postgres_run
@@ -46,83 +44,6 @@ run:
        #!/bin/bash
        sv stop postgres
 
-  - file:
-     path: /root/upgrade_postgres
-     chmod: "+x"
-     contents: |
-       #!/bin/bash
-       PG_MAJOR_OLD=`cat /shared/postgres_data/PG_VERSION`
-
-       if [ ! "10" = "$PG_MAJOR_OLD" ]; then
-         echo Upgrading PostgreSQL to from version ${PG_MAJOR_OLD} to 10
-         rm -fr /shared/postgres_data_new
-         install -d -m 0755 -o postgres -g postgres /shared/postgres_data_new && sudo -u postgres /usr/lib/postgresql/10/bin/initdb -D /shared/postgres_data_new || exit 0
-         apt-get update
-         apt-get install -y postgresql-${PG_MAJOR_OLD}
-         chown -R postgres:postgres /var/lib/postgresql/10
-         /etc/init.d/postgresql stop
-         rm -fr /shared/postgres_data/postmaster.pid
-         cd ~postgres
-         cp -pr /etc/postgresql/${PG_MAJOR_OLD}/main/* /shared/postgres_data
-         echo  >> /shared/postgres_data/postgresql.conf
-         echo "data_directory = '/shared/postgres_data'" >> /shared/postgres_data/postgresql.conf
-         SUCCESS=true
-         sudo -u postgres /usr/lib/postgresql/10/bin/pg_upgrade -d /shared/postgres_data -D /shared/postgres_data_new -b /usr/lib/postgresql/${PG_MAJOR_OLD}/bin -B /usr/lib/postgresql/10/bin || SUCCESS=false
-
-         if [[ "$SUCCESS" == 'false' ]]; then
-           echo -------------------------------------------------------------------------------------
-           echo UPGRADE OF POSTGRES FAILED
-           echo
-           echo You are going to need to export your data and import into a clean instance:
-           echo
-
-           if [ "$PG_MAJOR_OLD" = "9.5" ]; then
-             echo 'In containers/app.yml: Change "templates/postgres.template.yml" TO "templates/postgres.9.5.template.yml"'
-             echo
-           fi
-
-           echo Run "./launcher rebuild app" again
-           echo
-           echo When your instance is running:
-           echo Run "./launcher enter app"
-           echo Run "cd /shared/postgres_backup && sudo -u postgres pg_dump discourse > backup.db"
-           echo
-
-           if [ "$PG_MAJOR_OLD" = "9.5" ]; then
-             echo Undo the base_image in your container config
-           fi
-
-           echo Run: "./launcher stop app"
-           echo Run: "sudo mv /var/discourse/shared/standalone/postgres_data /var/discourse/shared/standalone/postgres_data_old"
-           echo Run: "./launcher rebuild app"
-           echo
-           echo Run: "./launcher enter app"
-           echo Run: "cd /shared/postgres_backup"
-           echo Run: "sv stop unicorn"
-           echo Run: "sudo -iu postgres dropdb discourse"
-           echo Run: "sudo -iu postgres createdb discourse"
-           echo Run: "sudo -iu postgres psql discourse < backup.db"
-           echo Run: "exit"
-           echo Run: "./launcher rebuild app"
-           exit 1
-         fi
-
-         mv /shared/postgres_data /shared/postgres_data_old
-         mv /shared/postgres_data_new /shared/postgres_data
-
-         echo -------------------------------------------------------------------------------------
-         echo UPGRADE OF POSTGRES COMPLETE
-         echo
-         echo Old ${PG_MAJOR_OLD} database is stored at /shared/postgres_data_old
-         echo
-         echo To complete the upgrade, rebuild again using:
-         echo
-         echo     ./launcher rebuild app
-         echo -------------------------------------------------------------------------------------
-         # Magic exit status to denote no failure
-         exit 77
-       fi
-
   - exec:
       cmd:
         - chown -R root /var/lib/postgresql/10/main
@@ -130,9 +51,6 @@ run:
         - chown -R postgres:postgres /shared/postgres_data
         - chown -R postgres:postgres /var/run/postgresql
 
-  - exec: /root/upgrade_postgres
-  - exec: rm /root/upgrade_postgres
-
   - replace:
       filename: "/etc/postgresql/10/main/postgresql.conf"
       from: "data_directory = '/var/lib/postgresql/10/main'"
index 09e3b4640508e9280692fbb8f44a37742ca2c897..bae3f6bbe9a041b8888cef68d81abd2ad31d4608 100644 (file)
@@ -11,7 +11,6 @@ params:
   db_logging_collector: off
   db_log_min_duration_statement: 100
 
-
 hooks:
   before_code:
     - replace:
index d483b76899b829041f4d277500ce784528d90242..82635b9269f0b22d3f6474582d9bbcf9bb7ee4e6 100644 (file)
@@ -11,7 +11,6 @@ params:
   db_logging_collector: off
   db_log_min_duration_statement: 100
 
-
 hooks:
   before_code:
     - replace:
@@ -28,15 +27,16 @@ run:
   - exec: socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1
   - exec: rm -fr /shared/postgres_run/.s*
   - exec: rm -fr /shared/postgres_run/*.pid
-  - exec: mkdir -p /shared/postgres_run/9.5-main.pg_stat_tmp
-  - exec: chown postgres:postgres /shared/postgres_run/9.5-main.pg_stat_tmp
+  - exec: mkdir -p /shared/postgres_run/10-main.pg_stat_tmp
+  - exec: chown postgres:postgres /shared/postgres_run/10-main.pg_stat_tmp
   - file:
      path: /etc/service/postgres/run
      chmod: "+x"
      contents: |
         #!/bin/sh
         exec 2>&1
-        HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/9.5/bin/postmaster -D /etc/postgresql/9.5/main
+        HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/10/bin/postmaster -D /etc/postgresql/10/main
+
   - file:
      path: /etc/service/postgres/log/run
      chmod: "+x"
@@ -45,6 +45,7 @@ run:
        mkdir -p /var/log/postgres
        exec svlogd /var/log/postgres
 
+
   - file:
      path: /etc/runit/3.d/99-postgres
      chmod: "+x"
@@ -59,20 +60,21 @@ run:
        #!/bin/bash
        PG_MAJOR_OLD=`cat /shared/postgres_data/PG_VERSION`
 
-       if [ ! "9.5" = "$PG_MAJOR_OLD" ]; then
-         echo Upgrading PostgreSQL to from version ${PG_MAJOR_OLD} to 9.5
+       if [ ! "10" = "$PG_MAJOR_OLD" ]; then
+         echo Upgrading PostgreSQL to from version ${PG_MAJOR_OLD} to 10
          rm -fr /shared/postgres_data_new
-         install -d -m 0755 -o postgres -g postgres /shared/postgres_data_new && sudo -u postgres /usr/lib/postgresql/9.5/bin/initdb -D /shared/postgres_data_new || exit 0
+         install -d -m 0755 -o postgres -g postgres /shared/postgres_data_new && sudo -u postgres /usr/lib/postgresql/10/bin/initdb -D /shared/postgres_data_new || exit 0
          apt-get update
          apt-get install -y postgresql-${PG_MAJOR_OLD}
+         chown -R postgres:postgres /var/lib/postgresql/10
          /etc/init.d/postgresql stop
          rm -fr /shared/postgres_data/postmaster.pid
          cd ~postgres
-         cp /etc/postgresql/${PG_MAJOR_OLD}/main/*.conf /shared/postgres_data
+         cp -pr /etc/postgresql/${PG_MAJOR_OLD}/main/* /shared/postgres_data
          echo  >> /shared/postgres_data/postgresql.conf
          echo "data_directory = '/shared/postgres_data'" >> /shared/postgres_data/postgresql.conf
          SUCCESS=true
-         sudo -u postgres /usr/lib/postgresql/9.5/bin/pg_upgrade -d /shared/postgres_data -D /shared/postgres_data_new -b /usr/lib/postgresql/${PG_MAJOR_OLD}/bin -B /usr/lib/postgresql/9.5/bin || SUCCESS=false
+         sudo -u postgres /usr/lib/postgresql/10/bin/pg_upgrade -d /shared/postgres_data -D /shared/postgres_data_new -b /usr/lib/postgresql/${PG_MAJOR_OLD}/bin -B /usr/lib/postgresql/10/bin || SUCCESS=false
 
          if [[ "$SUCCESS" == 'false' ]]; then
            echo -------------------------------------------------------------------------------------
@@ -81,14 +83,8 @@ run:
            echo You are going to need to export your data and import into a clean instance:
            echo
 
-           if [ "$PG_MAJOR_OLD" = "9.2" ]; then
-             echo Add the line: 'base_image: "samsaffron/discourse:0.1.1"'
-             echo 'In containers/app.yml: Change "templates/postgres.template.yml" TO "templates/postgres.9.2.template.yml"'
-             echo
-           fi
-
-           if [ "$PG_MAJOR_OLD" = "9.3" ]; then
-             echo 'In containers/app.yml: Change "templates/postgres.template.yml" TO "templates/postgres.9.3.template.yml"'
+           if [ "$PG_MAJOR_OLD" = "9.5" ]; then
+             echo 'In containers/app.yml: Change "templates/postgres.template.yml" TO "templates/postgres.9.5.template.yml"'
              echo
            fi
 
@@ -98,12 +94,11 @@ run:
            echo Run "./launcher enter app"
            echo Run "cd /shared/postgres_backup && sudo -u postgres pg_dump discourse > backup.db"
            echo
-           if [ "$PG_MAJOR_OLD" = "9.2" ]; then
+
+           if [ "$PG_MAJOR_OLD" = "9.5" ]; then
              echo Undo the base_image in your container config
            fi
-           if [ "$PG_MAJOR_OLD" = "9.3" ]; then
-             echo Undo the postgres template in your container config
-           fi
+
            echo Run: "./launcher stop app"
            echo Run: "sudo mv /var/discourse/shared/standalone/postgres_data /var/discourse/shared/standalone/postgres_data_old"
            echo Run: "./launcher rebuild app"
@@ -134,10 +129,11 @@ run:
          # Magic exit status to denote no failure
          exit 77
        fi
+
   - exec:
       cmd:
-        - chown -R root /var/lib/postgresql/9.5/main
-        - "[ ! -e /shared/postgres_data ] && install -d -m 0755 -o postgres -g postgres /shared/postgres_data && sudo -E -u postgres /usr/lib/postgresql/9.5/bin/initdb -D /shared/postgres_data || exit 0"
+        - chown -R root /var/lib/postgresql/10/main
+        - "[ ! -e /shared/postgres_data ] && install -d -m 0755 -o postgres -g postgres /shared/postgres_data && sudo -E -u postgres /usr/lib/postgresql/10/bin/initdb -D /shared/postgres_data || exit 0"
         - chown -R postgres:postgres /shared/postgres_data
         - chown -R postgres:postgres /var/run/postgresql
 
@@ -145,37 +141,37 @@ run:
   - exec: rm /root/upgrade_postgres
 
   - replace:
-      filename: "/etc/postgresql/9.5/main/postgresql.conf"
-      from: "data_directory = '/var/lib/postgresql/9.5/main'"
+      filename: "/etc/postgresql/10/main/postgresql.conf"
+      from: "data_directory = '/var/lib/postgresql/10/main'"
       to: "data_directory = '/shared/postgres_data'"
 
   # listen on all interfaces
   - replace:
-      filename: "/etc/postgresql/9.5/main/postgresql.conf"
+      filename: "/etc/postgresql/10/main/postgresql.conf"
       from: /#?listen_addresses *=.*/
       to: "listen_addresses = '*'"
 
   # sync commit off is faster and less spiky, also marginally less safe
   - replace:
-      filename: "/etc/postgresql/9.5/main/postgresql.conf"
+      filename: "/etc/postgresql/10/main/postgresql.conf"
       from: /#?synchronous_commit *=.*/
       to: "synchronous_commit = $db_synchronous_commit"
 
   # default is 128MB which is way too small
   - replace:
-      filename: "/etc/postgresql/9.5/main/postgresql.conf"
+      filename: "/etc/postgresql/10/main/postgresql.conf"
       from: /#?shared_buffers *=.*/
       to: "shared_buffers = $db_shared_buffers"
 
   # default is 1MB which is too small
   - replace:
-      filename: "/etc/postgresql/9.5/main/postgresql.conf"
+      filename: "/etc/postgresql/10/main/postgresql.conf"
       from: /#?work_mem *=.*/
       to: "work_mem = $db_work_mem"
 
   # allow for other
   - replace:
-      filename: "/etc/postgresql/9.5/main/postgresql.conf"
+      filename: "/etc/postgresql/10/main/postgresql.conf"
       from: /#?default_text_search_config *=.*/
       to: "default_text_search_config = '$db_default_text_search_config'"
 
@@ -185,38 +181,38 @@ run:
         - install -d -m 0755 -o postgres -g postgres /shared/postgres_backup
 
   - replace:
-      filename: "/etc/postgresql/9.5/main/postgresql.conf"
+      filename: "/etc/postgresql/10/main/postgresql.conf"
       from: /#?max_wal_senders *=.*/
       to: "max_wal_senders = $db_max_wal_senders"
 
   - replace:
-      filename: "/etc/postgresql/9.5/main/postgresql.conf"
+      filename: "/etc/postgresql/10/main/postgresql.conf"
       from: /#?wal_level *=.*/
       to: "wal_level = $db_wal_level"
 
   - replace:
-      filename: "/etc/postgresql/9.5/main/postgresql.conf"
+      filename: "/etc/postgresql/10/main/postgresql.conf"
       from: /#?checkpoint_segments *=.*/
       to: "checkpoint_segments = $db_checkpoint_segments"
 
   - replace:
-      filename: "/etc/postgresql/9.5/main/postgresql.conf"
+      filename: "/etc/postgresql/10/main/postgresql.conf"
       from: /#?logging_collector *=.*/
       to: "logging_collector = $db_logging_collector"
 
   - replace:
-      filename: "/etc/postgresql/9.5/main/postgresql.conf"
+      filename: "/etc/postgresql/10/main/postgresql.conf"
       from: /#?log_min_duration_statement *=.*/
       to: "log_min_duration_statement = $db_log_min_duration_statement"
 
   - replace:
-      filename: "/etc/postgresql/9.5/main/pg_hba.conf"
+      filename: "/etc/postgresql/10/main/pg_hba.conf"
       from: /^#local +replication +postgres +peer$/
       to: "local replication postgres  peer"
 
   # allow all to connect in with md5 auth
   - replace:
-      filename: "/etc/postgresql/9.5/main/pg_hba.conf"
+      filename: "/etc/postgresql/10/main/pg_hba.conf"
       from: /^host.*all.*all.*127.*$/
       to: "host all all 0.0.0.0/0 md5"
 
@@ -224,7 +220,7 @@ run:
       background: true
       # use fast shutdown for pg
       stop_signal: INT
-      cmd: HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/9.5/bin/postmaster -D /etc/postgresql/9.5/main
+      cmd: HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/10/bin/postmaster -D /etc/postgresql/10/main
 
   # give db a few secs to start up
   - exec: "sleep 5"