While looking through your scripts, there are 2 things which strike me.
in rc.local, you have a line mkdir /var/run/http. Is that for postgresql? If that line is necessary, it’s not strange the service won’t start.
You start the service with ‘start’. The script contains a function boot(), so I assume that is used when starting the script at boot. The difference between ‘start’ and ‘boot’ is in the line [ "$_BOOT" = "1" ] && [ "$(procd_get_mountpoints $pgdata)" ] && return 0
It’s hard to say what happens here, except that it is possible the lines below are not executed, and it has something to do with mountpoints. Is it possible that your database is on a filesystem which is not yet mounted?
mkdir /var/run/http has nothing to do with postgresql, it is for web service.
I changed the startup sequence for postgresql from original 50 to 93 and also tried 99, nothing happened. I am pretty sure the mount point is ok because another script is using the same partition and it started ok at boot.
Any code can be added to the postgresql script so it can be seen in the log?
I put “logger postgresql 1” before and “logger postgresql 2” after, i can see “postgresql 1” in the log, “postgresql 2” is not in the log, postgresql does not start.
then I move “start” above “_BOOT=1”:
boot() {
logger "postgresql boot"
start
_BOOT=1
}
It works. I can see both “postgresql 1” and “postgresql 2” in the log. Not sure why.
‘start’ somehow calls start_service(). When ‘_BOOT=1’ is set before that, it will bail out on [ "$(procd_get_mountpoints $pgdata)" ] && return 0 . When it’s not set, this code isn’t run.
So maybe you should put a logger "$(procd_get_mountpoints $pgdata)" before that, to see why it evalutates to true.
I completely remove and re-install postgresql, with all default settings, postgresql starts every time when router reboots. I took a deep look at the configuration file /etc/config/postgresql:
However, directory /var in openwrt is actually /tmp, it will be deleted on every reboot. When executing /etc/init.d/postgresql at boot, “$(procd_get_mountpoints $pgdata)” does not find /var/postgresql/data, then it executes the following lines to create new database. In my configuration, pgdata is in /opt/postgresql/data which persists after rebooting, then it will execute “return 0” without start the service.
I add “service postgresql start: to Local StartUp, it is working on evert reboot.