0

I have used one script, https://github.com/reddit/reddit/blob/master/install-reddit.sh on several machines and every time it worked perfectly. Now, one one server which has Ubuntu 64bit, I encounter issues with one part of the script.

###############################################################################
# Configure PostgreSQL
###############################################################################
SQL="SELECT COUNT(1) FROM pg_catalog.pg_database WHERE datname = 'reddit';"
IS_DATABASE_CREATED=$(sudo -u postgres psql -t -c "$SQL")

if [ $IS_DATABASE_CREATED -ne 1 ]; then
    cat <<PGSCRIPT | sudo -u postgres psql
CREATE DATABASE reddit WITH ENCODING = 'utf8' TEMPLATE template0;
CREATE USER reddit WITH PASSWORD 'password';
PGSCRIPT
fi

sudo -u postgres psql reddit < $REDDIT_HOME/reddit/sql/functions.sql

This is basically breaking the whole install process. I have tried running the lines manually from the script, like sudo -u postgres psql but I get no output at all. It seems that the database creation is not complete, because if I follow the guide for manually setting up POSTGRESQL, the command sudo -u postgres initdb -D /usr/local/pgsql/data fails with this output:

sudo: initdb: command not found

I also tried adding things to the path, export PATH=$PATH:/usr/lib/postgresql/bin but without help too, initdb wont start. Postgresql is installed, so I don't really know what is causing this.

Output of /etc/init.d/postgresql status is Running clusters: 9.1/main so the service is running.

I even tried installing ia32-libs and libc6-i386 but that didn't do much difference either.

UPDATE: After dealing with that issue, as described in the comments, I have encountered another one. I will put this here too as I think it's also closely related to this. I get the following error then:

+ sudo -u reddit make pyx
[+] including definitions from Makefile.py
python setup.py build_ext --inplace
/home/reddit/reddit/r2/ez_setup.py:101: UserWarning: Module ez_setup was already imported from /home/reddit/reddit/r2/ez_setup.pyc, but /usr/lib/pymodules/python2.7 is being added to sys.path
  import pkg_resources
running build_ext
skipping './r2/models/_builder.c' Cython extension (up-to-date)
building 'r2.models._builder' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c ./r2/models/_builder.c -o build/temp.linux-x86_64-2.7/./r2/models/_builder.o
unable to execute gcc: Permission denied
error: command 'gcc' failed with exit status 1

So, this gcc thing is now causing issues. This lines are triggering this: cd $REDDIT_HOME/reddit/r2 sudo -u $REDDIT_OWNER make pyx # generate the .c files from .pyx

$REDDIT_OWNER is reddit, so it runs as that user, and that ends up in those errors. Can anyone suggest a potential solution for this too? make: * [build/pyx-buildstamp] Error 1

Thanks for your help!

wont_compile
  • 855
  • 2
  • 17
  • 43
  • 1
    Might help: http://serverfault.com/questions/233497/where-is-initdb-in-ubuntu – knittl Dec 25 '12 at 09:22
  • Thanks knittl, this led me to solving some of the problems. I tried locating the initdb but without help, but when I looked to the /usr/lib/postgresql/9.1/bin/postgres as your discussion mentioned, I fond it. I changed the initdb, pqsl things to that path, and those things worked. But now I have another issue :) – wont_compile Dec 25 '12 at 14:36

1 Answers1

1

You're probably running into a problem where the PATH get reset by sudo. See here

Community
  • 1
  • 1
Andres Olarte
  • 4,380
  • 3
  • 24
  • 45
  • Hey, as I mentioned in the comment above, I found the things in the /usr/lib/postgresql/9.1/bin/postgres and I somehow managed to do all the postgres things from the bash manually, didn't risk with the script again. But, unfortunately, I have another issue now, with gcc, I have updated my original post. – wont_compile Dec 25 '12 at 14:36
  • It seems that user reddit does NOT have permission to execute gcc. Normally everyuser has permission to use gcc, but there might be some security issues there. Make sure to set the permissions properly (chmod a+x /path/to/gcc) – Andres Olarte Dec 25 '12 at 15:00