WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: [SOLVED] POSTGRESQL as a service  (Read 3386 times)

Offline jessethepro

  • Newbie
  • *
  • Posts: 3
[SOLVED] POSTGRESQL as a service
« on: February 18, 2013, 09:36:03 PM »
Hi,

I am trying to run postgresql as a service. When run as user tc through ssh script:

PGDATA=/tmp/maxdb
pg_ctl init
/tmp/tcloop/postgresql/usr/local/bin/postgres -D /tmp/maxdb

Runs without issue.

When put into bootlocal.sh service doesn't start. Anyone have success starting postgres on boot as a service?

Respectfully,
Jesse
« Last Edit: February 20, 2013, 04:46:50 PM by jessethepro »

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: POSTGRESQL as a service
« Reply #1 on: February 18, 2013, 09:51:04 PM »
bootlocal.sh runs as root.
When you say ssh script did you perhaps mean sh script?
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: POSTGRESQL as a service
« Reply #2 on: February 18, 2013, 09:56:20 PM »
You also should not be referencing /tmp/tcloop/postgresql/

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11623
Re: POSTGRESQL as a service
« Reply #3 on: February 18, 2013, 10:00:10 PM »
Hi jessethepro
I would also question your use of  /tmp/tcloop.   /tmp/tcloop/postgresql/usr/local/bin/postgres is linked to
/usr/local/bin/postgres  and  /usr/local/bin  is in the path.
postgres -D /tmp/maxdb  is all you need.

Offline jessethepro

  • Newbie
  • *
  • Posts: 3
Re: POSTGRESQL as a service
« Reply #4 on: February 18, 2013, 10:38:43 PM »
Thank you for the great info,

I log in through ssh and run the script with the default shell

I didn't know the path linked to /usr/local/bin. That is great to know.

Changing the start command to postgres -D /tmp/maxdb works perfect when run through the shell,  but won't start when run through bootlocal.sh. If postgres is like mysql, it probably doesn't like being started by root. Is there a way to start a service by user tc through bootlocal.sh?

I tried putting:
echo -e "password for tc" | su tc
Before the postgres commands to switch users and run the last of bootlocal.sh.as user tc, but didn't have much luck with that.

Respectfully,
Jesse

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11623
Re: POSTGRESQL as a service
« Reply #5 on: February 18, 2013, 10:46:06 PM »
Hi jessethepro
This same type of situation came up recently here:
http://forum.tinycorelinux.net/index.php/topic,14573.msg82686.html#msg82686
So maybe something like:
Code: [Select]
su tc -c 'postgres -D /tmp/maxdb'will do what you need.

Offline jessethepro

  • Newbie
  • *
  • Posts: 3
[SOLVED] POSTGRESQL as a service
« Reply #6 on: February 20, 2013, 04:45:06 PM »
Rich,

The command you gave me worked perfectly. I do appreciate the assistance. For future reference, the complete script in bootlocal.sh to start the postgresql server with default unix sockets is:

Code: (bash) [Select]
export PGDATA=/tmp/maxdb #or any other file path for the database
su tc -c 'pg_ctl init'
su tc -c 'postgres -D /tmp/maxdb'

Thank you again for everyones assistance,
Jesse