Sha256: 55e9bef335a1354d39c42425e84e8714f4e21b6565e34c957899784d5ed1b90b

Contents?: true

Size: 1.74 KB

Versions: 15

Compression:

Stored size: 1.74 KB

Contents

Standup.script :node do
  def run
    install_packages 'python-software-properties'
    sudo 'add-apt-repository ppa:pitti/postgresql'
    sudo 'apt-get update'

    #TODO execute sql /usr/share/postgresql/9.0/contrib/adminpack.sql
    install_packages 'postgresql postgresql-contrib libpq-dev'

    upload script_file('pg_hba.conf'),
           :to => '/etc/postgresql/9.0/main/pg_hba.conf',
           :sudo => true
  
    upload script_file('postgresql.conf'),
           :to => '/etc/postgresql/9.0/main/postgresql.conf',
           :sudo => true
  
    tune_kernel

     with_processed_file script_file('postgresql_monit.conf') do |file|
      scripts.monit.add_watch file
     end

    restart
#    sudo 'service postgresql restart'
  end

  def exec_sql sql, local = false
    command = "psql -c \"#{sql}\" -U postgres -w"
    if local
      local_exec command
    else
      exec command
    end
  end
  
  def create_database name, local = false
    if exec_sql("select * from pg_database where datname = '#{name}'", local) =~ /1 row/
      false
    else
      exec_sql "create database #{name}", local
      true
    end
  end
  
  def dump_command database, username = 'postgres', *args
    "pg_dump -c #{database} -U #{username} -w"
  end
  
  def load_command database, username = 'postgres', *args
    "psql #{database} -U #{username} -w"
  end

  def restart
    scripts.monit.restart_watch 'postgresql'
  end
  
  protected
  
  def tune_kernel
    sysctl_params = ['kernel.shmmax=134217728', 'kernel.shmall=2097152']
  
    remote_update '/etc/sysctl.conf',
                  sysctl_params.join("\n"),
                  :delimiter => '# standup script postgresql',
                  :sudo => true
  
    sysctl_params.each {|p| sudo "sysctl -w #{p}"}
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
standup-0.5.11 scripts/postgresql.rb
standup-0.5.10 scripts/postgresql.rb
standup-0.5.9 scripts/postgresql.rb
standup-0.5.8 scripts/postgresql.rb
standup-0.5.7 scripts/postgresql.rb
standup-0.5.6 scripts/postgresql.rb
standup-0.5.5 scripts/postgresql.rb
standup-0.5.4 scripts/postgresql.rb
standup-0.5.3 scripts/postgresql.rb
standup-0.5.1 scripts/postgresql.rb
standup-0.5.0 scripts/postgresql.rb
standup-0.4.0 scripts/postgresql.rb
standup-0.3.37 scripts/postgresql.rb
standup-0.3.36 scripts/postgresql.rb
standup-0.3.35 scripts/postgresql.rb