LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 07: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 07:28 PM.
 
Old 11-18-2009, 12:10 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
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, 12: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 01:12 AM.
 
Old 11-18-2009, 02:21 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
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, 12: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, 03:47 AM   #6
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
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, 05: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



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 07:12 PM
FTP sevice doesn't work gene.taylor Linux - Enterprise 2 12-06-2006 11:58 PM
Can I delete sevice pack 2 with linux bar1313 Linux - General 3 11-02-2006 10:20 AM
Running a .pl script as a sevice JonathonReinhart Linux - Software 2 11-21-2005 08:03 PM

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

All times are GMT -5. The time now is 09:56 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