diff options
| author | Armin Kuster <akuster808@gmail.com> | 2018-02-24 09:38:11 -0800 |
|---|---|---|
| committer | Armin Kuster <akuster808@gmail.com> | 2018-03-01 16:10:38 -0800 |
| commit | 742404cc8ab08316b0c02310c89958972d43d22e (patch) | |
| tree | 0fbbb80e1716548f3fe2b9d8383f9da8ad707abc /meta-oe/recipes-dbs/postgresql/files/postgresql-setup | |
| parent | eaff8c24ab1b88efc9340d90c268f4aea3795992 (diff) | |
| download | meta-openembedded-742404cc8ab08316b0c02310c89958972d43d22e.tar.gz | |
postgres: move to recipes-dbs
Signed-off-by: Armin Kuster <akuster808@gmail.com>
Diffstat (limited to 'meta-oe/recipes-dbs/postgresql/files/postgresql-setup')
| -rw-r--r-- | meta-oe/recipes-dbs/postgresql/files/postgresql-setup | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/meta-oe/recipes-dbs/postgresql/files/postgresql-setup b/meta-oe/recipes-dbs/postgresql/files/postgresql-setup new file mode 100644 index 0000000000..75bb01e05f --- /dev/null +++ b/meta-oe/recipes-dbs/postgresql/files/postgresql-setup | |||
| @@ -0,0 +1,73 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | # | ||
| 3 | # postgresql-setup Initialization operation for PostgreSQL | ||
| 4 | |||
| 5 | # For SELinux we need to use 'runuser' not 'su' | ||
| 6 | if [ -x /sbin/runuser ] | ||
| 7 | then | ||
| 8 | SU=runuser | ||
| 9 | else | ||
| 10 | SU=su | ||
| 11 | fi | ||
| 12 | |||
| 13 | PGENGINE=/usr/bin | ||
| 14 | PGDATA=/var/lib/postgresql/data | ||
| 15 | PGLOG=/var/lib/postgresql/pgstartup.log | ||
| 16 | script_result=0 | ||
| 17 | |||
| 18 | initdb(){ | ||
| 19 | if [ -f "$PGDATA/PG_VERSION" ] | ||
| 20 | then | ||
| 21 | echo -n "Data directory is not empty!" | ||
| 22 | echo -n " [FAILED] " | ||
| 23 | echo | ||
| 24 | script_result=1 | ||
| 25 | else | ||
| 26 | echo -n "Initializing database: " | ||
| 27 | if [ ! -e "$PGDATA" -a ! -h "$PGDATA" ] | ||
| 28 | then | ||
| 29 | mkdir -p "$PGDATA" || exit 1 | ||
| 30 | chown postgres:postgres "$PGDATA" | ||
| 31 | chmod go-rwx "$PGDATA" | ||
| 32 | fi | ||
| 33 | # Clean up SELinux tagging for PGDATA | ||
| 34 | [ -x /sbin/restorecon ] && /sbin/restorecon "$PGDATA" | ||
| 35 | |||
| 36 | # Make sure the startup-time log file is OK, too | ||
| 37 | if [ ! -e "$PGLOG" -a ! -h "$PGLOG" ] | ||
| 38 | then | ||
| 39 | touch "$PGLOG" || exit 1 | ||
| 40 | chown postgres:postgres "$PGLOG" | ||
| 41 | chmod go-rwx "$PGLOG" | ||
| 42 | [ -x /sbin/restorecon ] && /sbin/restorecon "$PGLOG" | ||
| 43 | fi | ||
| 44 | |||
| 45 | # Initialize the database | ||
| 46 | $SU -l postgres -c "$PGENGINE/initdb --pgdata='$PGDATA' --auth='ident'" >> "$PGLOG" 2>&1 < /dev/null | ||
| 47 | |||
| 48 | # Create directory for postmaster log | ||
| 49 | mkdir "$PGDATA/pg_log" | ||
| 50 | chown postgres:postgres "$PGDATA/pg_log" | ||
| 51 | chmod go-rwx "$PGDATA/pg_log" | ||
| 52 | |||
| 53 | if [ -f "$PGDATA/PG_VERSION" ] | ||
| 54 | then | ||
| 55 | echo -n " [ OK ] " | ||
| 56 | else | ||
| 57 | echo -n " [FAILED] " | ||
| 58 | script_result=1 | ||
| 59 | fi | ||
| 60 | echo | ||
| 61 | fi | ||
| 62 | } | ||
| 63 | |||
| 64 | case "$1" in | ||
| 65 | initdb) | ||
| 66 | initdb | ||
| 67 | ;; | ||
| 68 | *) | ||
| 69 | echo "Usage: $0 initdb" | ||
| 70 | exit 2 | ||
| 71 | esac | ||
| 72 | |||
| 73 | exit $script_result | ||
