Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > macOS > Invoking the Terminal in a StartupItem?

Invoking the Terminal in a StartupItem?
Thread Tools
TheJoshu
Mac Elite
Join Date: Oct 1999
Location: Brooklyn, New York, USA
Status: Offline
Reply With Quote
Apr 13, 2006, 12:32 PM
 
Hi guys. I'm trying to get PostgreSQL to start up every time my Mac mini does, but that requires Terminal access. Some guy created a utility to do this (which some other guy fixed), and I've ended up with this relevant excerpt in a StartupItem document:

StartService ()
{

if [ "${POSTGRES:=-YES-}" = "-YES-" ]; then

ConsoleMessage "Starting PostgreSQL database server"
su - postgres -c '/usr/local/pgsql/bin/pg_ctl start -D /usr/local/pgsql/data -l /usr/local/pgsql/logfile -o -i'

fi

}
However, it doesn't work, and when I test it in the Terminal (sudo /Library/StartupItems/PostgreSQL/PostgreSQL start) I get the error /usr/local/pgsql/logfile - permission denied.

The basic parameters of this are: I am logging in as one user, let's say "thejoshu", and the owner of these folders (/usr/local/postgres/[...]) is another user, "postgres." By hand, in the Terminal, I use Apple's recommendation to start PostgreSQL:

su -l postgres
[password]
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start

I expect the problem is that there's no place in this code for me to provide postgres's password before starting postgreSQL?

Any ideas? Thanks!
     
Tesseract
Grizzled Veteran
Join Date: Apr 2002
Location: california
Status: Offline
Reply With Quote
Apr 13, 2006, 10:07 PM
 
If you are root (or using sudo) you should be able to su to any user without giving that user's password. This is how the script can start postgres as the postgres user without having the password in the script.

That said, I don't run postgres on my Mac so I have no idea what your actual problem is.
     
TheJoshu  (op)
Mac Elite
Join Date: Oct 1999
Location: Brooklyn, New York, USA
Status: Offline
Reply With Quote
Apr 14, 2006, 02:18 AM
 
OK, so, is the idea that postgres maybe doesn't - for some reason - own that logfile? If I use sudo to su to that user, it'll give me that issue because it's owned by another user? Maybe the tragedy is that the logfile is owned by someone else. Now, to track down the logfile.
     
TheJoshu  (op)
Mac Elite
Join Date: Oct 1999
Location: Brooklyn, New York, USA
Status: Offline
Reply With Quote
Apr 14, 2006, 02:34 AM
 
ah, so that's the solution indeed. move logfile to a place where postgres can write... Works great when I change that line from usr/local/pgsql/logfile to usr/local/pgsql/data/logfile!
     
   
 
Forum Links
Forum 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 On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 12:37 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,