Thread: freebsd sample startup script doesn't work

freebsd sample startup script doesn't work

From
Vivek Khera
Date:
I installed the sample startup script for postgres for FreeBSD, but it
reports the following error upon running:

# /usr/local/etc/rc.d/postgres.sh start
pg_ctl: no database directory or environment variable $PGDATA is specified
Try 'pg_ctl --help' for more information.

I see clearly that PGDATA is set and exported.  I'm suspecting that
the "su -l" causes the environment to disappear.  My guess is that
whomever wrote this script has PGDATA set in the ~/.profile (or
equivalent) in the postgres user's home directory.

Thus, it is pointless to set PGDATA in the script.  Setting and
exporting PGDATA in the ~/.profile file lets postgres start as
expected.

The commentary says to copy the file to /usr/local/etc/rc.d/postgresql
but this is not useful; the file must in '.sh' and be executable or
FreeBSD will ignore it on boot.

Also, the following line in the start action of the sript is useful:

        /sbin/ldconfig -m $prefix/lib


--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Vivek Khera, Ph.D.                Khera Communications, Inc.
Internet: khera@kciLink.com       Rockville, MD       +1-240-453-8497
AIM: vivekkhera Y!: vivek_khera   http://www.khera.org/~vivek/

Re: freebsd sample startup script doesn't work

From
Bruce Momjian
Date:
Got it.  I recommend changing 'su -l' to 'su -m' to preserve the
environment.  How does that sound?


> I installed the sample startup script for postgres for FreeBSD, but it
> reports the following error upon running:
>
> # /usr/local/etc/rc.d/postgres.sh start
> pg_ctl: no database directory or environment variable $PGDATA is specified
> Try 'pg_ctl --help' for more information.
>
> I see clearly that PGDATA is set and exported.  I'm suspecting that
> the "su -l" causes the environment to disappear.  My guess is that
> whomever wrote this script has PGDATA set in the ~/.profile (or
> equivalent) in the postgres user's home directory.
>
> Thus, it is pointless to set PGDATA in the script.  Setting and
> exporting PGDATA in the ~/.profile file lets postgres start as
> expected.
>
> The commentary says to copy the file to /usr/local/etc/rc.d/postgresql
> but this is not useful; the file must in '.sh' and be executable or
> FreeBSD will ignore it on boot.
>
> Also, the following line in the start action of the sript is useful:
>
>         /sbin/ldconfig -m $prefix/lib
>
>
> --
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> Vivek Khera, Ph.D.                Khera Communications, Inc.
> Internet: khera@kciLink.com       Rockville, MD       +1-240-453-8497
> AIM: vivekkhera Y!: vivek_khera   http://www.khera.org/~vivek/
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://www.postgresql.org/search.mpl
>

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Re: freebsd sample startup script doesn't work

From
Peter Eisentraut
Date:
Vivek Khera writes:

> I see clearly that PGDATA is set and exported.  I'm suspecting that
> the "su -l" causes the environment to disappear.  My guess is that
> whomever wrote this script has PGDATA set in the ~/.profile (or
> equivalent) in the postgres user's home directory.

This is fixed in the soon to be released 7.1.1.

> Also, the following line in the start action of the sript is useful:
>
>         /sbin/ldconfig -m $prefix/lib

You ought to run this once, not every time the system starts.

--
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter

Re: freebsd sample startup script doesn't work

From
Peter Eisentraut
Date:
Vivek Khera writes:

> >>>>> "PE" == Peter Eisentraut <peter_e@gmx.net> writes:
>
> >> Also, the following line in the start action of the sript is useful:
> >>
> >> /sbin/ldconfig -m $prefix/lib
>
> PE> You ought to run this once, not every time the system starts.
>
> No, FreeBSD does *not* cache this info.

Sure it does.  See 'var/run/ld[-elf].so.hints'.

--
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter

Re: freebsd sample startup script doesn't work

From
Bruce Momjian
Date:
OK, I think this is already fixed in 7.1.1.  The fix was to add -D to
pg_ctl.  Would you try 7.1.1 or the snapshot and let me know.  Thanks.

New line shows:

        su -l $PGUSER -c "$DAEMON start -D '$PGDATA' -s -l $PGLOG"

You will need an updated pg_ctl that understands -D.

>
> Got it.  I recommend changing 'su -l' to 'su -m' to preserve the
> environment.  How does that sound?
>
>
> > I installed the sample startup script for postgres for FreeBSD, but it
> > reports the following error upon running:
> >
> > # /usr/local/etc/rc.d/postgres.sh start
> > pg_ctl: no database directory or environment variable $PGDATA is specified
> > Try 'pg_ctl --help' for more information.
> >
> > I see clearly that PGDATA is set and exported.  I'm suspecting that
> > the "su -l" causes the environment to disappear.  My guess is that
> > whomever wrote this script has PGDATA set in the ~/.profile (or
> > equivalent) in the postgres user's home directory.
> >
> > Thus, it is pointless to set PGDATA in the script.  Setting and
> > exporting PGDATA in the ~/.profile file lets postgres start as
> > expected.
> >
> > The commentary says to copy the file to /usr/local/etc/rc.d/postgresql
> > but this is not useful; the file must in '.sh' and be executable or
> > FreeBSD will ignore it on boot.
> >
> > Also, the following line in the start action of the sript is useful:
> >
> >         /sbin/ldconfig -m $prefix/lib
> >
> >
> > --
> > =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> > Vivek Khera, Ph.D.                Khera Communications, Inc.
> > Internet: khera@kciLink.com       Rockville, MD       +1-240-453-8497
> > AIM: vivekkhera Y!: vivek_khera   http://www.khera.org/~vivek/
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 6: Have you searched our list archives?
> >
> > http://www.postgresql.org/search.mpl
> >
>
> --
>   Bruce Momjian                        |  http://candle.pha.pa.us
>   pgman@candle.pha.pa.us               |  (610) 853-3000
>   +  If your life is a hard drive,     |  830 Blythe Avenue
>   +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Re: freebsd sample startup script doesn't work

From
Peter Eisentraut
Date:
Bruce Momjian writes:

> You will need an updated pg_ctl that understands -D.

All versions of pg_ctl understand -D.

--
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter

Re: freebsd sample startup script doesn't work

From
Vivek Khera
Date:
>>>>> "PE" == Peter Eisentraut <peter_e@gmx.net> writes:

>> Also, the following line in the start action of the sript is useful:
>>
>> /sbin/ldconfig -m $prefix/lib

PE> You ought to run this once, not every time the system starts.

No, FreeBSD does *not* cache this info.  You need to run it on every
system startup, unless you're libs are in /usr/lib or /usr/local/lib
or you've altered FreeBSD's setting of ldconfig_paths in the system
startup scripts.

Here's what I'm using, as file /usr/local/etc/rc.d/00postgres-client.sh,
as opposed to running it in the server startup script.

--cut here--
#!/bin/sh

case "$1" in
    start)
        /sbin/ldconfig -m /usr/local/pgsql/lib
        ;;
    stop)
        ;;
    *)
        echo ""
        echo "Usage: `basename $0` { start | stop }"
        echo ""
        exit 64
        ;;
esac

--cut here--

--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Vivek Khera, Ph.D.                Khera Communications, Inc.
Internet: khera@kciLink.com       Rockville, MD       +1-240-453-8497
AIM: vivekkhera Y!: vivek_khera   http://www.khera.org/~vivek/

Re: freebsd sample startup script doesn't work

From
Vivek Khera
Date:
>>>>> "BM" == Bruce Momjian <pgman@candle.pha.pa.us> writes:

BM> Got it.  I recommend changing 'su -l' to 'su -m' to preserve the
BM> environment.  How does that sound?

Just tried it and it works ok.  The only issue I can think of is if
root has some secret info in the environment, that it will now be
accessible to postgres... but then who puts secret info in their
environment?  ;-)

--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Vivek Khera, Ph.D.                Khera Communications, Inc.
Internet: khera@kciLink.com       Rockville, MD       +1-240-453-8497
AIM: vivekkhera Y!: vivek_khera   http://www.khera.org/~vivek/

Re: freebsd sample startup script doesn't work

From
Vivek Khera
Date:
>>>>> "PE" == Peter Eisentraut <peter_e@gmx.net> writes:

PE> Sure it does.  See 'var/run/ld[-elf].so.hints'.

But /var/run is not guaranteed to survive reboot.  "man hier" has this
to say about it:

     run/       system information files describing various info
                about system since it was booted

Says nothing about prior to booting.

Re: freebsd sample startup script doesn't work

From
Vivek Khera
Date:
>>>>> "VK" == Vivek Khera <khera@kcilink.com> writes:

>>>>> "PE" == Peter Eisentraut <peter_e@gmx.net> writes:
PE> Sure it does.  See 'var/run/ld[-elf].so.hints'.

VK> But /var/run is not guaranteed to survive reboot.  "man hier" has this
VK> to say about it:

One more thing... /etc/rc _explicitly_ sets the ldconfig path,
overriding anything that may have been sitting in
/var/run/ld-elf.so.hints anyhow.  So you *must* do the ldconfig -m
/usr/local/pgsql/lib every boot or you don't get those libs.

Re: freebsd sample startup script doesn't work

From
Palle Girgensohn
Date:
You should really use the port. it has a working startup
script, and it creates a pgsql/.profile for you. Using su -m is
more error prone IMHO. It will export locales and such, that
you really don't want to export to postmaster.

/Palle

Vivek Khera wrote:
>
> I installed the sample startup script for postgres for FreeBSD, but it
> reports the following error upon running:
>
> # /usr/local/etc/rc.d/postgres.sh start
> pg_ctl: no database directory or environment variable $PGDATA is specified
> Try 'pg_ctl --help' for more information.
>
> I see clearly that PGDATA is set and exported.  I'm suspecting that
> the "su -l" causes the environment to disappear.  My guess is that
> whomever wrote this script has PGDATA set in the ~/.profile (or
> equivalent) in the postgres user's home directory.
>
> Thus, it is pointless to set PGDATA in the script.  Setting and
> exporting PGDATA in the ~/.profile file lets postgres start as
> expected.
>
> The commentary says to copy the file to /usr/local/etc/rc.d/postgresql
> but this is not useful; the file must in '.sh' and be executable or
> FreeBSD will ignore it on boot.
>
> Also, the following line in the start action of the sript is useful:
>
>         /sbin/ldconfig -m $prefix/lib
>
> --
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> Vivek Khera, Ph.D.                Khera Communications, Inc.
> Internet: khera@kciLink.com       Rockville, MD       +1-240-453-8497
> AIM: vivekkhera Y!: vivek_khera   http://www.khera.org/~vivek/
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://www.postgresql.org/search.mpl

--
         Partitur Informationsteknik AB
Wenner-Gren Center             +46 8 566 280 02
113 46 Stockholm           +46 70 785 86 02
Sweden                   girgen@partitur.se

Re: freebsd sample startup script doesn't work

From
Vivek Khera
Date:
>>>>> "PG" == Palle Girgensohn <girgen@partitur.se> writes:

PG> You should really use the port. it has a working startup
PG> script, and it creates a pgsql/.profile for you. Using su -m is
PG> more error prone IMHO. It will export locales and such, that
PG> you really don't want to export to postmaster.

I started with the FreeBSD port, bit I dislike it.  It is not really
well put together.  If I specify an alternate location of the data
directory, it still creates the default one.  It is just easier to do
it myself directly.  Also, the port uses the user "pgsql" which just
feels funny to me.