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

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?

share|improve this question

Just run the script from the shell and see whether it spits out errors. – PeeHaa 19 hours ago
1  
PeeHaa's suggestion is the best idea. Just to provide an alternative, if you postgres is installing but not starting, have a look at the log files in the data directory, as they may contain errors related to starting up. – Scott S 19 hours ago
run sudo /etc/init.d/postgresql start and post errors – Baconator507 19 hours ago
Thank you for all the replies. @Baconator507 I get this: sudo: /etc/init.d/postgresql: command not found – James Willson 19 hours ago
try service postgresql start – Baconator507 19 hours ago
show 1 more comment
feedback

1 Answer

up vote 1 down vote accepted

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.

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.

Instead, you should write something like this:

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

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.

share|improve this answer
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.