automatically starting PostgreSQL

Nagy László Zsolt nagylzs at freemail.hu
Mon Apr 2 19:47:46 UTC 2007


>
> For reasons having to do with our particular operation, it is our 
> custom to build many packages from source code no matter the operating 
> system, so I don't want to install from the ports tree.
Did you know that when you install from the ports tree, it will actually 
download the sources, make important patched for freebsd, and install 
from that source? In particular, you can give CFLAGS, makefile defines 
etc. In addition, when you install it from the ports tree, it gets 
recorded in the package database so you can install other applications 
that depend on postgresql. (For example, pgadmin3). Why do you want to 
install it from the sources? If you only want to optimize for your CPU 
and compile some contrib/extension modules, then you do not need to 
install from a source tarball yourself. Using the port will be enough.
> The script I used is one which is part of the PostgreSQL package and 
> is specifically for FreeBSD.  As I said the script works as expected. 
> '/etc/rc.d/postgresql start|stop|restart' all work.  I also have a 
> duplicate script in /usr/local/etc/rc.d which also works as expected 
> when run manually.  Neither of these start the server at boot time.
First of all, since postgresql is not part of the base system, you 
should put its rc script under /usr/local/etc/rc.d instead of /etc/rc.d. 
The rc script won't be execute unless the following criterion are met:

1. The script is executeable (chmod +x <filename>)
2. The script has a .sh suffix, OR it uses rcorder. (See: man rcorder). 
Using rcorder is the better because you can define when to start your 
service. (Obvious example: you need to start networking before starting 
postgresql...)
3. If the script supports rc variables, then probably you need to adjust 
some variables in /etc/rc.conf. However, it depends on the script 
itself. Most ports work with rc scripts. Custom programs installed from 
source may not need this.

> I have an apache2 installation also built from source code, and also 
> with a script from an external source, also placed in /etc/rc.d and 
> referenced by the line 'apache2_enable="YES"', and this *does* start 
> at boot time.
I guess because it is named "apache.sh" instead of "apache", am I right?
> So I am a little confused as to what I need to do.  If I add .sh to 
> /usr/local/etc/rc.d/postgresql, in my /etc/rc.conf do I change my 
> reference line to 'enable_postgresql.sh="YES"'?
Of course not. The rc variables can be set in rc.conf. They will be 
checked by the postgresql.sh script. E.g. it is not the base system that 
checks these variables. Putting variables in rc.conf for programs like 
postgresql is good because usually you want to disable/enable services 
in rc.conf. Configuring postgresql is another story. However, it is the 
startup script of your program that needs to have support for rc variables.

I hope this helps.

Best,

   Laszlo



More information about the freebsd-questions mailing list