LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-17-2009, 08:26 PM   #1
trist007
Senior Member
 
Registered: May 2008
Distribution: Slackware
Posts: 1,052

Rep: Reputation: 70
Need help adding postgresql sevice at boot...


I'm running Slackware 13.0

I edit the /etc/rc.d/rc.M file to add postgresql. The service needs to be started as the postgres user. This is what I've tried so far.

Code:
# Start the PostgreSQL database:
if [ -x /usr/local/pgsql/bin/pg_ctl ]; then
  . sudo -u postgres /usr/local/pgsql/bin/pg_ctl start -D /usr/local/pgsql/data -l serverlog
fi
Code:
# Start the PostgreSQL database:
if [ -x /usr/local/pgsql/bin/pg_ctl ]; then
   sudo -u postgres /usr/local/pgsql/bin/pg_ctl start -D /usr/local/pgsql/data -l serverlog
fi
It's one with and without the ".". Yet it still fails to load on boot.

If I run
Code:
sudo -u postgres /usr/local/pgsql/bin/pg_ctl start -D /usr/local/pgsql/data -l serverlog
directly in a terminal it loads up everything fine.

Any ideas?

Last edited by trist007; 11-17-2009 at 08:28 PM.
 
Old 11-18-2009, 01:10 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,216
Blog Entries: 1

Rep: Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067
Use the full path to sudo:
Code:
/usr/bin/sudo -u postgres /usr/local/pgsql/bin/pg_ctl start -D /usr/local/pgsql/data -l serverlog
May I ask why you put the script in rc.M and not in rc.local?
 
Old 11-18-2009, 01:11 AM   #3
trist007
Senior Member
 
Registered: May 2008
Distribution: Slackware
Posts: 1,052

Original Poster
Rep: Reputation: 70
Oh man that's right. No reason, what's rc.local meant for? I usually put all the services in rc.M.

How come in rc.M some lines have a period and others don't, what's period for?

Like I know sometimes when running a sh file I do

./start.sh but how come it's not on everything.

Also, just tried the suggested solution and it's still not working.

Last edited by trist007; 11-18-2009 at 02:12 AM.
 
Old 11-18-2009, 03:21 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,216
Blog Entries: 1

Rep: Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067
Hi,

rc.local is used to run commands or scripts, at the end of the default runlevel init scripts. So it's always good to put your custom startup scripts there.
The dot means that the command runs from current direcotry.
Regarding your problem maybe you have to give also the full path to serverlog, or you could try to use su instead of sudo:
Code:
/bin/su postgres -c "/usr/local/pgsql/bin/pg_ctl start -D /usr/local/pgsql/data -l serverlog"
 
Old 11-19-2009, 01:37 AM   #5
trist007
Senior Member
 
Registered: May 2008
Distribution: Slackware
Posts: 1,052

Original Poster
Rep: Reputation: 70
Nope that didn't work. Any other ideas? I can't find the full path to serverlog.
 
Old 11-19-2009, 04:47 AM   #6
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,216
Blog Entries: 1

Rep: Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067
According to postgres documentation if serverlog does not exist it will be created, so you can use for example "-l /tmp/serverlog" so it gets written in /tmp.
Anyway try to use this startup script, after modifying it to suit your needs

Regards
 
Old 11-19-2009, 06:36 AM   #7
trist007
Senior Member
 
Registered: May 2008
Distribution: Slackware
Posts: 1,052

Original Poster
Rep: Reputation: 70
Excellent finally got it. Thank you so much. Made some minor changes.
Code:
root@server:~# cat postgresql.sh
#!/bin/sh

case "$1" in
        start)
                su postgres -c "/usr/local/pgsql/bin/pg_ctl  -D /usr/local/pgsql/data -p /usr/local/pgsql/bin/postmaster start  > /dev/null 2>&1" < /dev/null
                ;;
        stop)
                kill `ps -efa | grep postmaster | grep -v grep | awk '{print $2}'`
                ;;
        *)
                echo $"Usage: $0 {start|stop}"
                exit 1
esac

exit 0
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Debian Lenny postgresql and adding user problems apolinsky Linux - Software 5 03-03-2009 08:12 PM
FTP sevice doesn't work gene.taylor Linux - Enterprise 2 12-07-2006 12:58 AM
Can I delete sevice pack 2 with linux bar1313 Linux - General 3 11-02-2006 11:20 AM
Running a .pl script as a sevice JonathonReinhart Linux - Software 2 11-21-2005 09:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration