What's new

Entware how to auto start pgsql

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

XIYO

Occasional Visitor
Here's the English translation of your text:

Hello, I'm trying to run pgsql on my AC88U(386.11) router.
I know it may not be the best idea, but I want to give it a try.

## I've encountered several issues but have managed to resolve them all.

- Search for `pgsql` in opkg, not `postgresql`.
- `pg_ctl` cannot be run as the root user, so you have to use the `-U` option to change the user.
- Accounts get reset, so I had to create scripts to register accounts (passwd.add, group.add... etc.)
- `pg_ctl` logs issues upon running, so where it is run from is also important.

I've resolved various issues, including allowing external access, and have successfully launched the service.

## Now, the final challenge remains.

### The first method successfully launches the service.
Code:
# In a directory where 'postgres' has write permission
pg_ctl -U postgres -D /mnt/sda1/entware-data/var/pgsql start

### The second method also successfully launches the service.
I've also modified S98postgresql, and it runs well (although the logs aren't pretty...).

S98postgresql
Code:
#!/bin/sh

# Installation prefix

prefix="/mnt/sda1/entware-data"

# Data directory
PGDATA="$prefix/var/pgsql"

PG_DUMP_DIR="$prefix/var/pgsql/15.2/dump"

# Who to run the postmaster as, usually "postgres".  (NOT "root")
PGUSER=postgres

# Where to keep a log file
PGLOG="$PGDATA/serverlog"

# What to use to shut down the postmaster
PGCTL="$prefix/bin/pg_ctl"

# What to use to start up the postmaster (we do NOT use pg_ctl for this,
# as it adds no value and can cause the postmaster to misrecognize a stale
# lock file)

DAEMON="/opt/bin/pg_ctl"

#########
if [ -z "$1" ] ; then
    case `echo "$0" | /bin/sed 's:^.*/\(.*\):\1:g'` in
        S??*) rc="start" ;;
        K??*) rc="stop" ;;
        *) rc="usage" ;;
    esac
else
    rc="$1"
fi

case "$rc" in
    start)
        echo -n "Starting PostgreSQL: "
        cd $PGDATA
        $DAEMON -U $PGUSER -D $PGDATA -l $PGLOG start
        echo ok
        ;;
    stop)
        echo -n "Stopping PostgreSQL: "
        $DAEMON -U $PGUSER -D $PGDATA stop
        echo ok
        ;;
    restart)
        echo -n "Restart POstgreSQL: "
        $DAEMON -U $PGUSER -D $PGDATA restart
        echo ok
        ;;
    dumpall)
        PG_DUMP_FILE=$PG_DUMP_DIR/dumpall-`date +%FT%H%M%S`
        if [ -x $prefix/bin/gzip ]; then
            PG_DUMP_FILE=$PG_DUMP_FILE.gz
            echo -n "PostgreSQL pg_dumpall and gzip to $PG_DUMP_FILE "
            su - $PGUSER -c "$prefix/bin/pg_dumpall | $prefix/bin/gzip -c > $PG_DUMP_FILE"
        else
            echo -n "PostgreSQL pg_dumpall to $PG_DUMP_FILE "
            su - $PGUSER -c "$prefix/bin/pg_dumpall > $PG_DUMP_FILE"
        fi
        echo ok
        ;;
    *)
        echo "Usage: $0 (start|stop|restart|dumpall|usage)"
        ;;
esac

Code:
/opt/etc/init.d/S98postgresql start
This command works fine.

My final challenge is to ensure that the service starts automatically after a reboot.

In /jffs/script/services-start,
Code:
#!/bin/sh
/jffs/addons/amtm/shellhistory # Added by amtm
/opt/etc/init.d/rc.unslung start # Added by xiyo

I've written it like this, but while the nginx I installed for comparison starts normally, PostgreSQL does not. I suspect it's a permissions issue, but I don't even know how to check the logs...

Any help would be greatly appreciated.

I wish everyone a happy day.
 
...
Code:
/opt/etc/init.d/S98postgresql start
This command works fine.

My final challenge is to ensure that the service starts automatically after a reboot.

In /jffs/script/services-start,
Code:
#!/bin/sh
/jffs/addons/amtm/shellhistory # Added by amtm
/opt/etc/init.d/rc.unslung start # Added by xiyo
When the "/jffs/scripts/services-start" script runs during a reboot, there's no guarantee that the USB-attached disk drive partition (where Entware is installed) has been fully mounted every time, so the recommended place to start Entware services is the "/jffs/scripts/post-mount" script.

If you installed Entware via the built-in AMTM utility, the "/jffs/scripts/post-mount" script should already exist and include the "/jffs/addons/diversion/mount-entware.div" script which mounts Entware and starts all service scripts found in the "/opt/etc/init.d" directory. If, for some reason, this is not working for you, first make sure that the code is included in your "post-mount" script:
Bash:
. /jffs/addons/diversion/mount-entware.div
If it's not found or not working for your specific case, the "post-mount" script is still the place where you should add your own code to start the specific Entware service that you want to run and troubleshoot.

HTH
 
Thank you. It was resolved all at once.


What I did was:
- Made slight modifications to `/opt/etc/init.d/S98postgresql`
Bash:
# add post-mount-start sciprt
    post-mount-start)
        echo -n "Starting PostgreSQL: "
        cd $PGDATA
        $DAEMON -U $PGUSER -D $PGDATA -l $PGLOG start
        echo ok
        ;;

# change start script
    start)
        echo "This script should not be run before the storage is mounted."
        echo "Run manually with '/opt/etc/init.d/S98postgres post-mount-start',"
        echo "or add the script to /jfft/script/post-mount."
        ;;

- Added the execution command to `/jfft/script/post-mount`
Bash:
# added last line
/opt/etc/init.d/S98postgresql post-mount-start
 

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top