Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,22 @@ your installation by running first
It'll tell you that the `.env` is missing, that is expected as it's the next
step.

Then, you need to setup the environment and the database. To do so execute the
following command
Then, generate the configuration file:

```bash
./script/setup.sh all
./script/setup.sh env
```

This will generate a file in the working directory: `.env` (ee below to
know more about the configuration properties).
This will generate a file in the working directory: `.env` (see below to
know more about the configuration properties). Review it and adjust settings
such as database passwords before continuing.

Then, set up the PostgreSQL database (cluster, users, and databases using
values from your `.env`):

```bash
./script/setup.sh db
```

Then you can prepare the database and environment with

Expand Down
3 changes: 2 additions & 1 deletion debian/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ set -e

case "$1" in
configure)
/usr/share/openhexa/setup.sh -g all
/usr/share/openhexa/setup.sh -g env
/usr/share/openhexa/setup.sh -g db

/usr/share/openhexa/openhexa.sh -g update
/usr/share/openhexa/openhexa.sh -g prepare
Expand Down
42 changes: 19 additions & 23 deletions script/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ function usage() {

COMMANDS:

all sets up all: first the PostgreSQL database, then the environment
env sets up the environment and stores it in a file (requires an
existing PostgreSQL cluster named \`openhexa\`)
db sets up the PostgreSQL database
Expand Down Expand Up @@ -380,9 +379,8 @@ function setup_env() {
echo "Setup environment:"

if ! does_postgresql_cluster_openhexa_exist >/dev/null 2>&1; then
echo "The PostgreSQL cluster for OpenHexa hasn't been created."
echo "Please first run \`$0 db\` or \`$0 all\`."
return 1
prompt_sudo_password_if_needed
ensure_db_cluster || return 1
fi

db_port=$(get_postgresql_port_for_cluster_openhexa)
Expand Down Expand Up @@ -420,15 +418,12 @@ function create_pgsql_cluster() {
$SUDO_COMMAND pg_createcluster "${PGSQL_VERSION}" "${PGSQL_CLUSTER}" --start >/dev/null 2>&1
}

function setup_db() {
local db_port
echo "Setup database:"

function ensure_db_cluster() {
echo -n "- create cluster if it does not exists ... "
if ! does_postgresql_cluster_openhexa_exist; then
create_pgsql_cluster
echo "created"

echo -n "- make the cluster listening on the Docker network ... "
listen_on_docker_network
echo "done"
Expand All @@ -440,14 +435,6 @@ function setup_db() {
echo -n "- restart the cluster to take in account new setup ... "
restart_postgreql
echo "done"

echo -n "- create users and databases for the Open Hexa app and Jupyter Hub ... "
db_port=$(get_postgresql_port_for_cluster_openhexa)
create_postgresql_user "${db_port}" "$(get_config_or_default DATABASE_USER)" "$(get_config_or_default DATABASE_PASSWORD)"
create_postgresql_db "${db_port}" "$(get_config_or_default DATABASE_NAME)" "$(get_config_or_default DATABASE_USER)"
create_postgresql_user "${db_port}" "$(get_config_or_default JUPYTERHUB_DATABASE_USER)" "$(get_config_or_default JUPYTERHUB_DATABASE_PASSWORD)"
create_postgresql_db "${db_port}" "$(get_config_or_default JUPYTERHUB_DATABASE_NAME)" "$(get_config_or_default JUPYTERHUB_DATABASE_USER)"
echo "done"
else
echo "already created"
fi
Expand All @@ -459,6 +446,21 @@ function setup_db() {
echo "running"
}

function setup_db() {
local db_port
echo "Setup database:"

ensure_db_cluster || return 1

echo -n "- create users and databases for the Open Hexa app and Jupyter Hub ... "
db_port=$(get_postgresql_port_for_cluster_openhexa)
create_postgresql_user "${db_port}" "$(get_config_or_default DATABASE_USER)" "$(get_config_or_default DATABASE_PASSWORD)"
create_postgresql_db "${db_port}" "$(get_config_or_default DATABASE_NAME)" "$(get_config_or_default DATABASE_USER)"
create_postgresql_user "${db_port}" "$(get_config_or_default JUPYTERHUB_DATABASE_USER)" "$(get_config_or_default JUPYTERHUB_DATABASE_PASSWORD)"
create_postgresql_db "${db_port}" "$(get_config_or_default JUPYTERHUB_DATABASE_NAME)" "$(get_config_or_default JUPYTERHUB_DATABASE_USER)"
echo "done"
}

function remove_user_and_group() {
local exit_code=0
if [[ $OPTION_GLOBAL == "on" ]]; then
Expand Down Expand Up @@ -681,12 +683,6 @@ function execute() {
local command=$1
local exit_code=0
case "${command}" in
all)
prompt_sudo_password_if_needed
setup_db || exit_properly 1
setup_env || exit_properly 1
exit_properly 0
;;
env)
setup_env
exit_properly 0
Expand Down
Loading