Skip to content
Snippets Groups Projects
Commit 2597f6c9 authored by David Schmitz's avatar David Schmitz
Browse files

add possibility to install postfix and to install+init mysql/mariadb instead...

add possibility to install postfix and to install+init mysql/mariadb instead of sqlite db in install-debian.sh
parent 5dd986e6
No related branches found
No related tags found
No related merge requests found
...@@ -57,10 +57,10 @@ SECRET_KEY = '@sa@5234#$%345345^@#$%*()123^@12!&!()$JMNDF#$@(@#8FRNJWX_' ...@@ -57,10 +57,10 @@ SECRET_KEY = '@sa@5234#$%345345^@#$%*()123^@12!&!()$JMNDF#$@(@#8FRNJWX_'
DATABASES = { DATABASES = {
'default': { 'default': {
'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 'ENGINE': 'django.db.backends.', # DB_ENGINE # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': '', 'NAME': '', # DB_NAME
'USER': '', 'USER': '', # DB_USER
'PASSWORD': '', 'PASSWORD': '', # DB_PASSWORD
'HOST': '', # Set to empty string for localhost. 'HOST': '', # Set to empty string for localhost.
'PORT': '', # Set to empty string for default. 'PORT': '', # Set to empty string for default.
} }
......
--- settings.py.dist 2020-05-27 16:04:09.459076296 +0200 --- settings.py.dist 2022-05-18 09:27:15.260147119 +0000
+++ settings.py 2020-05-27 16:06:59.378164956 +0200 +++ settings.py 2022-05-18 12:10:24.085777698 +0000
@@ -30,7 +30,7 @@ @@ -33,7 +33,7 @@
import os ##############################################################################
from celery.schedules import crontab ##############################################################################
-DEBUG = False -DEBUG = False
+DEBUG = True +DEBUG = True
TEMPLATE_DEBUG = DEBUG TEMPLATE_DEBUG = DEBUG
ADMINS = ( ##
@@ -51,8 +51,8 @@ @@ -57,8 +57,8 @@
DATABASES = { DATABASES = {
'default': { 'default': {
- 'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. - 'ENGINE': 'django.db.backends.', # DB_ENGINE # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
- 'NAME': '', - 'NAME': '', # DB_NAME
+ 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. + 'ENGINE': 'django.db.backends.sqlite3', # DB_ENGINE # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
+ 'NAME': 'example-data', + 'NAME': 'example-data', # DB_NAME
'USER': '', 'USER': '', # DB_USER
'PASSWORD': '', 'PASSWORD': '', # DB_PASSWORD
'HOST': '', # Set to empty string for localhost. 'HOST': '', # Set to empty string for localhost.
@@ -195,25 +195,20 @@ @@ -81,25 +81,20 @@
LOGGING = { LOGGING = {
'version': 1, 'version': 1,
'disable_existing_loggers': False, 'disable_existing_loggers': False,
...@@ -54,22 +54,22 @@ ...@@ -54,22 +54,22 @@
+ }, + },
} }
LOGIN_URL = '/welcome' ##############################################################################
@@ -292,7 +287,7 @@ @@ -372,7 +367,7 @@
CELERY_IMPORTS = ("flowspec.tasks", ) # email config
# Notifications # Notifications
-DISABLE_EMAIL_NOTIFICATION = True -DISABLE_EMAIL_NOTIFICATION = True
+DISABLE_EMAIL_NOTIFICATION = False +DISABLE_EMAIL_NOTIFICATION = False
SERVER_EMAIL = "Example FoD Service <noreply@example.com>" SERVER_EMAIL = "Example FoD Service <noreply@example.com>"
EMAIL_SUBJECT_PREFIX = "[FoD] " EMAIL_SUBJECT_PREFIX = "[FoD] "
EXPIRATION_NOTIFY_DAYS = 4 #DEFAULT_FROM_EMAIL = "myemail@gmail.com"
@@ -491,7 +486,7 @@ @@ -629,7 +624,7 @@
'LANGUAGE_CODE', ##############################################################################
] # special test installation
-ENABLE_SETUP_VIEW = False -ENABLE_SETUP_VIEW = False
+ENABLE_SETUP_VIEW = True +ENABLE_SETUP_VIEW = True
# Maximum size of stream of notification messages per each peer tag ##############################################################################
NOTIF_STREAM_MAXSIZE = 50 ##############################################################################
...@@ -13,6 +13,83 @@ install_fodproper=1 ...@@ -13,6 +13,83 @@ install_fodproper=1
install_systemd_services=0 install_systemd_services=0
ensure_installed_pythonenv_wrapper=1 ensure_installed_pythonenv_wrapper=1
install_mta=""
#
install_db=""
init_db=""
conf_db_access=""
DB__FOD_DBNAME=""
DB__FOD_USER=""
DB__FOD_PASSWORD=""
##############################################################################
##############################################################################
function init_mysqllikedb() {
DB__FOD_DBNAME="$1"
shift 1
DB__FOD_USER="$1"
shift 1
DB__FOD_PASSWORD="$1"
shift 1
set -e
echo 1>&2
echo "trying to init mysqllike database '$DB__FOD_DBNAME' for DB USER '$DB__FOD_USER'" 1>&2
echo "CREATE DATABASE IF NOT EXISTS $DB__FOD_DBNAME;" | mysql
echo "ALTER DATABASE $DB__FOD_DBNAME CHARACTER SET utf8;" | mysql
echo "DROP USER IF EXISTS '$DB__FOD_USER'@'%';" | mysql
echo "CREATE USER IF NOT EXISTS '$DB__FOD_USER'@'%' IDENTIFIED BY '$DB__FOD_PASSWORD';" | mysql
#echo "GRANT ALL PRIVILEGES ON *.* TO '$DB__FOD_USER'@'%';" | mysql
#echo "GRANT ALL ON *.* to '$DB__FOD_USER'@'172.18.0.2' IDENTIFIED BY '$DB__FOD_PASSWORD' WITH GRANT OPTION;" | mysql
echo "GRANT ALL PRIVILEGES ON *.* to '$DB__FOD_USER'@'%' WITH GRANT OPTION;" | mysql
echo "current users:" 1>&2
echo "SELECT User,Host FROM mysql.user;" | mysql
echo 1>&2
echo "current grants:" 1>&2
echo "SHOW GRANTS FOR '$DB__FOD_USER'@'%';" | mysql
mysqladmin flush-privileges
echo "done with initalizing mysqllike database '$DB__FOD_DBNAME' for DB USER '$DB__FOD_USER'" 1>&2
echo 1>&2
}
function get_random_password() {
dd status=noxfer bs=1 count=16 < /dev/random 2> /dev/null | hexdump | grep "0000000" | awk '{ OFS=""; $1=""; print; }'
}
function conf_db_access () {
fod_dir="$1"
shift 1
conf_db_access="$1"
shift 1
DB__FOD_DBNAME="$1"
shift 1
DB__FOD_USER="$1"
shift 1
DB__FOD_PASSWORD="$1"
shift 1
(set -e
sed -i "s/^\s*'ENGINE':.*#\s*DB_ENGINE/ 'ENGINE': 'django.db.backends.$conf_db_access', # DB_ENGINE # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'./" "$fod_dir/flowspy/settings.py"
sed -i "s/^\s*'NAME':.*#\s*DB_NAME/ 'NAME': '$DB__FOD_DBNAME', # DB_NAME/" "$fod_dir/flowspy/settings.py"
sed -i "s/^\s*'USER':.*#\s*DB_USER/ 'USER': '$DB__FOD_USER', # DB_USER/" "$fod_dir/flowspy/settings.py"
sed -i "s/^\s*'PASSWORD':.*#\s*DB_PASSWORD/ 'PASSWORD': '$DB__FOD_PASSWORD', # DB_PASSWORD/" "$fod_dir/flowspy/settings.py"
)
}
##############################################################################
##############################################################################
if grep -q -E '^systemd$' /proc/1/comm; then if grep -q -E '^systemd$' /proc/1/comm; then
echo "system is running systemd as init process, setting default install_systemd_services=1" 1>&2 echo "system is running systemd as init process, setting default install_systemd_services=1" 1>&2
install_systemd_services=1 install_systemd_services=1
...@@ -21,7 +98,8 @@ elif [ -e "/.dockenv" ]; then ...@@ -21,7 +98,8 @@ elif [ -e "/.dockenv" ]; then
install_systemd_services=0 install_systemd_services=0
fi fi
# ##############################################################################
##############################################################################
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
...@@ -61,12 +139,43 @@ while [ $# -gt 0 ]; do ...@@ -61,12 +139,43 @@ while [ $# -gt 0 ]; do
elif [ $# -ge 1 -a "$1" = "--no_systemd" ]; then elif [ $# -ge 1 -a "$1" = "--no_systemd" ]; then
shift 1 shift 1
install_systemd_services=0 install_systemd_services=0
elif [ $# -ge 1 -a "$1" = "--with_mta_postfix" ]; then
shift 1
install_mta="postfix"
elif [ $# -ge 1 -a "$1" = "--with_db_sqlite" ]; then
shift 1
install_db="sqlite3"
init_db="sqlite3"
conf_db_access="sqlite3"
DB__FOD_DBNAME="example-data"
DB__FOD_USER=""
DB__FOD_PASSWORD=""
elif [ $# -ge 1 -a "$1" = "--with_db_mysql" ]; then
shift 1
install_db="mysql"
init_db="mysql"
conf_db_access="mysql"
DB__FOD_DBNAME="fod"
DB__FOD_USER="fod"
DB__FOD_PASSWORD="$(get_random_password)"
elif [ $# -ge 1 -a "$1" = "--with_db_mariadb" ]; then
shift 1
install_db="mariadb"
init_db="mariadb"
conf_db_access="mysql"
DB__FOD_DBNAME="fod"
DB__FOD_USER="fod"
DB__FOD_PASSWORD="$(get_random_password)"
else else
break break
fi fi
done done
##
echo "conf_db_access=$conf_db_access DB_NAME=$DB__FOD_DBNAME DB_USER=$DB__FOD_USER DB_PASSWORD=$DB__FOD_PASSWORD" 1>&2
## ##
venv_dir_base="$(dirname "$venv_dir")" venv_dir_base="$(dirname "$venv_dir")"
...@@ -86,24 +195,77 @@ fi ...@@ -86,24 +195,77 @@ fi
echo "$0: inst_dir=$inst_dir fod_dir=$fod_dir => inst_dir_is_fod_dir=$inst_dir_is_fod_dir venv_dir=$venv_dir static_dir=$static_dir" 1>&2 echo "$0: inst_dir=$inst_dir fod_dir=$fod_dir => inst_dir_is_fod_dir=$inst_dir_is_fod_dir venv_dir=$venv_dir static_dir=$static_dir" 1>&2
#exit #exit
##
if [ "$install_basesw" = 1 ]; then if [ "$install_basesw" = 1 ]; then
set -e set -e
echo "Install dependencies" echo 1>&2
echo "Install dependencies" 1>&2
apt-get -qqy update apt-get -qqy update
apt-get -qqy install virtualenv python3-venv python3-setuptools \ apt-get -qqy install virtualenv python3-venv python3-setuptools \
python3-dev vim git build-essential libevent-dev libxml2-dev libxslt1-dev \ python3-dev vim git build-essential libevent-dev libxml2-dev libxslt1-dev \
mariadb-server libmariadb-dev patch redis-server sqlite3 \ mariadb-server libmariadb-dev patch redis-server sqlite3 \
rustc libssl-dev \ rustc libssl-dev \
procps procps
echo 1>&2
set +e
fi
##
if [ -n "$install_mta" ]; then
set -e
echo 1>&2
if [ -x "/usr/sbin/sendmail" ]; then
echo "MTA /usr/sbin/sendmail seems to be already available, not trying to install another one" 1>&2
elif [ "$install_mta" = "postfix" ]; then
echo "trying to install postfix MTA" 1>&2
apt-get -qqy update
apt-get -qqy install postfix
fi
echo 1>&2
set +e set +e
fi fi
##
if [ -n "$install_db" ]; then
set -e
echo 1>&2
if [ "$install_db" = "mariadb" ]; then
echo "trying to install mariadb"
apt-get -qqy update
apt-get -y install mariadb-server
init_mysqllikedb "$DB__FOD_DBNAME" "$DB__FOD_USER" "$DB__FOD_PASSWORD"
elif [ "$install_db" = "mysql" ]; then
echo "trying to install mysql"
apt-get -qqy update
apt-get -y install mysql-server
init_mysqllikedb "$DB__FOD_DBNAME" "$DB__FOD_USER" "$DB__FOD_PASSWORD"
fi
echo 1>&2
#conf_db_access "$fod_dir" "$conf_db_access" "$DB__FOD_DBNAME" "$DB__FOD_USER" "$DB__FOD_PASSWORD"
set +e
fi
#exit
##
if [ "$install_fodproper" = 0 ]; then if [ "$install_fodproper" = 0 ]; then
echo "Setup partial python environment for FoD" echo "Setup partial python environment for FoD"
...@@ -130,7 +292,7 @@ if [ "$install_fodproper" = 0 ]; then ...@@ -130,7 +292,7 @@ if [ "$install_fodproper" = 0 ]; then
else else
id fod &>/dev/null || useradd -m fod id fod &>/dev/null || useradd -m fod
echo "Setup python environment for FoD" echo "Setup python environment for FoD"
#mkdir -p /var/log/fod /srv #mkdir -p /var/log/fod /srv
...@@ -209,13 +371,32 @@ else ...@@ -209,13 +371,32 @@ else
#mkdir -p /srv/flowspy/static/ #mkdir -p /srv/flowspy/static/
mkdir -p "$static_dir" mkdir -p "$static_dir"
./manage.py collectstatic --noinput ./manage.py collectstatic --noinput
##
#if [ "$init_db" = "mariadb" -o "$init_db" = "mysql" ]; then
# init_mysqllikedb "$DB__FOD_DBNAME" "$DB__FOD_USER" "$DB__FOD_PASSWORD"
#fi
if [ -n "$conf_db_access" ]; then
echo "setting DB access config" 1>&2
conf_db_access "$fod_dir" "$conf_db_access" "$DB__FOD_DBNAME" "$DB__FOD_USER" "$DB__FOD_PASSWORD"
echo 1>&2
fi
##
echo "deploying/updating database schema" 1>&2
./manage.py migrate ./manage.py migrate
./manage.py loaddata initial_data ./manage.py loaddata initial_data
echo 1>&2
# #
echo "providing supervisord config" 1>&2
cp -f "$fod_dir/supervisord.conf.dist" "$fod_dir/supervisord.conf" cp -f "$fod_dir/supervisord.conf.dist" "$fod_dir/supervisord.conf"
sed -i "s#/srv/flowspy#$fod_dir#" "$fod_dir/supervisord.conf" sed -i "s#/srv/flowspy#$fod_dir#" "$fod_dir/supervisord.conf"
echo 1>&2
# #
...@@ -224,33 +405,34 @@ else ...@@ -224,33 +405,34 @@ else
# #
fod_systemd_dir="$fod_dir/systemd"
cp -f "$fod_systemd_dir/fod-gunicorn.service.dist" "$fod_systemd_dir/fod-gunicorn.service"
sed -i "s#/srv/flowspy#$fod_dir#" "$fod_systemd_dir/fod-gunicorn.service"
cp -f "$fod_systemd_dir/fod-celeryd.service.dist" "$fod_systemd_dir/fod-celeryd.service"
sed -i "s#/srv/flowspy#$fod_dir#" "$fod_systemd_dir/fod-celeryd.service"
cp -f "$fod_systemd_dir/fod-status-email-user@.service.dist" "$fod_systemd_dir/fod-status-email-user@.service"
sed -i "s#/srv/flowspy#$fod_dir#" "$fod_systemd_dir/fod-status-email-user@.service"
## ##
if [ "$ensure_installed_pythonenv_wrapper" = 1 -a ! -e "$fod_dir/pythonenv" ]; then if [ "$ensure_installed_pythonenv_wrapper" = 1 -a ! -e "$fod_dir/pythonenv" ]; then
echo "installing pythonev wrapper" 1>&2 echo "adding pythonev wrapper" 1>&2
cat > "$fod_dir/pythonenv" <<EOF cat > "$fod_dir/pythonenv" <<EOF
#!/bin/bash #!/bin/bash
. "$venv_dir/bin/activate" . "$venv_dir/bin/activate"
exec "\$@" exec "\$@"
EOF EOF
chmod +x "$fod_dir/pythonenv" chmod +x "$fod_dir/pythonenv"
echo 1>&2
fi fi
## ##
fod_systemd_dir="$fod_dir/systemd"
cp -f "$fod_systemd_dir/fod-gunicorn.service.dist" "$fod_systemd_dir/fod-gunicorn.service"
sed -i "s#/srv/flowspy#$fod_dir#" "$fod_systemd_dir/fod-gunicorn.service"
cp -f "$fod_systemd_dir/fod-celeryd.service.dist" "$fod_systemd_dir/fod-celeryd.service"
sed -i "s#/srv/flowspy#$fod_dir#" "$fod_systemd_dir/fod-celeryd.service"
cp -f "$fod_systemd_dir/fod-status-email-user@.service.dist" "$fod_systemd_dir/fod-status-email-user@.service"
sed -i "s#/srv/flowspy#$fod_dir#" "$fod_systemd_dir/fod-status-email-user@.service"
if [ "$install_systemd_services" = 1 ]; then if [ "$install_systemd_services" = 1 ]; then
echo 1>&2 echo 1>&2
echo "Install_systemd_services" 1>&2 echo "Installing systemd services" 1>&2
echo 1>&2 echo 1>&2
#cp -f "$fod_systemd_dir/fod-gunicorn.service" "$fod_systemd_dir/fod-celeryd.service" "/etc/systemd/system/" #cp -f "$fod_systemd_dir/fod-gunicorn.service" "$fod_systemd_dir/fod-celeryd.service" "/etc/systemd/system/"
cp -v -f "$fod_systemd_dir/fod-gunicorn.service" "$fod_systemd_dir/fod-celeryd.service" "$fod_systemd_dir/fod-status-email-user@.service" "/etc/systemd/system/" 1>&2 cp -v -f "$fod_systemd_dir/fod-gunicorn.service" "$fod_systemd_dir/fod-celeryd.service" "$fod_systemd_dir/fod-status-email-user@.service" "/etc/systemd/system/" 1>&2
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment