bash脚本安装PostgreSQL的 - 不工作 [英] Bash Script to install PostgreSQL - Not working

查看:129
本文介绍了bash脚本安装PostgreSQL的 - 不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有当我的Debian 6.0服务器部署,它的目的是从源代码编译PostgreSQL中,创建一个系统用户为它创建一个数据库,并启动它运行的脚本。我是新来这一点,但我做了很多功课,这就是我想出了:

I have a script which runs when my debian 6.0 server is deployed and it is designed to build postgreSQL from source, create a system user for it, create a database and start it running. I am new to this but I did a lot of homework and this is what I came up with:

# Initial
    apt-get update
    apt-get -y install aptitude bzip2 libbz2-dev git-core bison flex
    aptitude -y install sudo python-all-dev python-setuptools libxml2-dev libgeoip-dev libxslt1-dev uuid-dev gcc automake autoconf libpcre3-dev libssl-dev unzip zip python-psycopg2 libpq-dev wget make libreadline-dev
    aptitude -y full-upgrade 


# POSTGRESQL
###############################

# Postgresql Download & Install
    wget http://ftp.postgresql.org/pub/source/v8.4.6/postgresql-8.4.6.tar.gz -P /tmp
    mkdir /tmp/postgresql
    tar xzf /tmp/postgresql-8.4.6.tar.gz -C "/tmp/postgresql"
    cd /tmp/postgresql/postgresql-8.4.6
    ./configure
    make
    make install

# Add User
    useradd postgres
    chown "postgres" /usr/local/pgsql
    mkdir /usr/local/pgsql/data
    chown postgres:postgres /usr/local/pgsql/data
    su - postgres
    /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data/
    /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data
    /usr/local/pgsql/bin/createdb test

因为这是部署运行其难以调试了什么错误,但我可以看到,下载和安装的Postgres似乎工作正常。然而,我所知道的是我的服务器上运行未启用的Postgres。我想知道我的code最后一部分,如果任何人都可以看到什么我这样做不正确可能导致此?

Since this is run on deployment its difficult to debug what is going wrong, but I can see that the download and install of postgres seems to work ok. However, what I do know is postgres isnt running on my server. I was wondering for the last part of my code if anyone can see anything I am doing incorrectly which might cause this?

推荐答案

这是在你的脚本显然是错误的部分是,它预计继苏系 - 的Postgres 要以postgres用户身份运行。这将不会发生。

The part that is clearly wrong in your script is that it expects the lines following the su - postgres to be run as the postgres user. This won't happen.

在批处理模式下,苏 - Postgres的启动和立即退出,因为没有命令被送到它。然后,脚本的下一个命令为用户启动脚本(presumably根)执行,他们失败。

In batch mode, su - postgres starts and immediately exits because no command is fed to it. Then the next commands of the scripts are executed as the user launching the script (presumably root) and they fail.

相反,你应该这样写:

su - postgres <<-'EOF'
  /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data/
  /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data
  /usr/local/pgsql/bin/createdb test
EOF
# the lines after the EOF will be executed again as the initial user

在评论中建议,假设您已经通过一个软件包安装PostgreSQL的,但是这不是问题的情况下。当你从源代码安装与 ./配置不带参数和制作安装外,它永远不会安装任何在/ usr /本地/ pgsql里。这是完全正常的有在 在这种情况下没有启动脚本/ etc中。

The suggestions in the comments assume that you have installed postgresql via a package, but that's not the context of the question. When you install from source with ./configure without arguments and make install, it will never install anything outside /usr/local/pgsql. It's perfectly normal to have no startup script under /etc in this context.

这篇关于bash脚本安装PostgreSQL的 - 不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆