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

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

问题描述

我有一个脚本,它在部署我的 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.我想知道我的代码的最后一部分是否有人可以看到我做错的任何事情,这可能会导致这种情况?

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?

推荐答案

脚本中明显错误的部分是它希望 su - 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.

在批处理模式下,su - postgres 启动并立即退出,因为没有向其提供命令.然后脚本的下一个命令在用户启动脚本(可能是 root)时执行,但它们会失败.

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,但这不是问题的上下文.当你使用 ./configure 不带参数和 make install 从源代码安装时,它永远不会在 /usr/local/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.

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

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