summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--install/celery.service.template21
-rw-r--r--install/celeryd.default.template17
-rwxr-xr-xinstall/ishtar-delete-instance10
-rwxr-xr-xinstall/ishtar-install48
-rwxr-xr-xinstall/ishtar-prepare-instance31
6 files changed, 120 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore
index 68f835be4..fb2ae0068 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,7 @@
.~*
drassm_app/*
cd17_app/*
+ansible/*
django-simple-history/*
django-formwizard/*
ishtar-docs
diff --git a/install/celery.service.template b/install/celery.service.template
new file mode 100644
index 000000000..ecb88526e
--- /dev/null
+++ b/install/celery.service.template
@@ -0,0 +1,21 @@
+[Unit]
+Description=Celery Server #APP_NAME#
+After=network.target
+
+[Service]
+Type=forking
+User=celery
+Group=celery
+EnvironmentFile=/etc/default/celeryd-#APP_NAME#
+WorkingDirectory=#INSTALL_PATH#
+ExecStart=/bin/sh -c '${CELERY_BIN} multi start ${CELERYD_NODES} \
+ -A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} \
+ --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}'
+ExecStop=/bin/sh -c '${CELERY_BIN} multi stopwait ${CELERYD_NODES} \
+ --pidfile=${CELERYD_PID_FILE}'
+ExecReload=/bin/sh -c '${CELERY_BIN} multi restart ${CELERYD_NODES} \
+ -A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} \
+ --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}'
+
+[Install]
+WantedBy=multi-user.target \ No newline at end of file
diff --git a/install/celeryd.default.template b/install/celeryd.default.template
new file mode 100644
index 000000000..4220b6c35
--- /dev/null
+++ b/install/celeryd.default.template
@@ -0,0 +1,17 @@
+# The names of the workers. This example create one workers
+CELERYD_NODES="#APP_NAME#w1"
+#CELERYD_NODES="#APP_NAME#w1 #APP_NAME#w2" # 2 workers
+
+# The name of the Celery App, should be the same as the python file
+# where the Celery tasks are defined
+CELERY_APP="#APP_NAME#"
+
+# Log and PID directories
+CELERYD_LOG_FILE="/var/log/celery/#APP_NAME#%n%I.log"
+CELERYD_PID_FILE="/var/run/celery/#APP_NAME#%n.pid"
+
+# Log level
+CELERYD_LOG_LEVEL=INFO
+
+# Path to celery binary, that is in your virtual environment
+CELERY_BIN=/usr/local/bin/celery \ No newline at end of file
diff --git a/install/ishtar-delete-instance b/install/ishtar-delete-instance
index 0cd004de3..7e4883192 100755
--- a/install/ishtar-delete-instance
+++ b/install/ishtar-delete-instance
@@ -86,6 +86,16 @@ do_delete_instance() {
rm -f "$UWSGI_AVAILABLE_PATH/ishtar-$INSTANCE.ini"
rm -f "$UWSGI_ENABLE_PATH/ishtar-$INSTANCE.ini"
+ if [ -v USE_CELERY ]; then
+ systemctl disable celeryd-$INSTANCE
+ systemctl stop celeryd-$INSTANCE
+ /usr/sbin/rabbitmqctl delete_vhost /ishtar$INSTANCE
+ /usr/sbin/rabbitmqctl delete_user ishtar$INSTANCE
+ rm "/etc/default/celeryd-"$INSTANCE
+ rm "/etc/default/celeryd-"$INSTANCE
+ systemctl daemon-reload
+ fi
+
DB_NAME="ishtar-$INSTANCE"
export DB_NAME
su postgres <<'EOF'
diff --git a/install/ishtar-install b/install/ishtar-install
index bb779a3f6..976c57c2c 100755
--- a/install/ishtar-install
+++ b/install/ishtar-install
@@ -298,6 +298,35 @@ EOF
exit 1
fi
+ install_celery=''
+ cat >&2 <<-'EOF'
+
+-------------------------------------------------------------------------------
+ In order to make the consultation fluid post treatment are made intensively
+ in Ishtar. If you have a lot of data (> 10 000 items) installing a dedicated
+ daemon to do this post treatment is advised. This daemon is a new service
+ that performs background treatments. This daemon require RabbitMQ message
+ broker (auto installed).
+
+EOF
+ MSG=""
+ while [ "$install_celery" == '' ]
+ do
+ cecho y '* Install post treatment daemon? ([no]/yes) '
+ read choice
+ case "$choice" in
+ yes ) install_celery="yes";;
+ y ) install_celery="yes";;
+ no ) install_celery="no";;
+ n ) install_celery="no";;
+ '' ) install_celery="no";;
+ esac
+ done
+
+ echo ""
+ cecho g "*******************************************************************************"
+ echo ""
+
install_libreoffice=''
cat >&2 <<-'EOF'
@@ -450,6 +479,17 @@ EOF
libreoffice libreoffice-script-provider-python python3-uno' )
fi
+ if [ "$install_celery" == 'yes' ]; then
+ ( set -x; $sh_c 'sleep 3; apt-get --no-install-recommends install -y -q \
+ rabbitmq-server' )
+ # buster: python3-celery
+ ( set -x; $sh_c 'pip3 install celery==4.2.1' )
+ mkdir -p /var/log/celery/
+ mkdir -p /var/run/celery/
+ useradd -M --system -s /bin/false celery
+ chown celery:celery /var/log/celery/ /var/run/celery/
+ fi
+
echo "-------------------------------------------------------------------------------";
cecho y "Installing django extra views"
echo "";
@@ -482,11 +522,6 @@ EOF
cecho y "Installing python3-virtualtime"
echo "";
( set -x; $sh_c 'pip3 install virtualtime==1.6' )
- ## not mandatory
- # cecho y "Installing python3-django-background-tasks"
- # echo "";
- #( set -x; $sh_c 'pip3 install django-background-tasks==1.1.11'
- #)
fi
;;
@@ -509,6 +544,9 @@ EOF
echo "ISHTAR_DB="$default_db >> $etc_path"config"
echo "ISHTAR_WEBSERVER="$webserver >> $etc_path"config"
echo "ISHTAR_LOCALE="$current_locale >> $etc_path"config"
+ if [ "$install_celery" == 'yes' ]; then
+ echo "USE_CELERY="$install_celery >> $etc_path"config"
+ fi
echo "# settings added to all instances" >> $etc_path"extra_settings.py"
echo ""
cecho g "*******************************************************************************"
diff --git a/install/ishtar-prepare-instance b/install/ishtar-prepare-instance
index fcc5cb629..60fd0e39f 100755
--- a/install/ishtar-prepare-instance
+++ b/install/ishtar-prepare-instance
@@ -261,11 +261,34 @@ EOF
fi
echo $UWSGI_PORT > $PORT_FILE
- ### __init__.py
+ # manage celery daemon
+ CELERY_CONF=""
+ if [ -v USE_CELERY ]; then
+ RBMQ_PASSWORD=$(apg -a 0 -M ncl -n 1 -x 10 -m 10)
+ /usr/sbin/rabbitmqctl add_vhost /ishtar$INSTANCE
+ /usr/sbin/rabbitmqctl add_user ishtar$INSTANCE $RBMQ_PASSWORD
+ /usr/sbin/rabbitmqctl set_permissions -p /ishtar$INSTANCE ishtar$INSTANCE ".*" ".*" ".*"
+ CELERY_CONF="BROKER_URL = 'ampq://ishtar"$INSTANCE":"$RBMQ_PASSWORD"@localhost//ishtar"$INSTANCE"'"
+ CELERY_CONF=$CELERY_CONF"\nUSE_BACKGROUND_TASK = True"
+ sed -s "s|#APP_NAME#|$INSTANCE|g;" \
+ "install/celeryd.default.template" > \
+ "/etc/default/celeryd-"$INSTANCE
+ sed -s "s|#APP_NAME#|$INSTANCE|g;\
+ s|#INSTALL_PATH#|$INSTALL_PATH|g;"\
+ "install/celery.service.template" > \
+ "/etc/default/celeryd-"$INSTANCE
+ systemctl daemon-reload
+ systemctl enable celeryd-$INSTANCE
+ systemctl start celeryd-$INSTANCE
+ fi
+ ### __init__.py
cd $INSTANCE
- # ln -s __init__.py.celery.sample __init__.py
- ln -s __init__.py.base.sample __init__.py
+ if [ -v USE_CELERY ]; then
+ ln -s __init__.py.celery.sample __init__.py
+ else
+ ln -s __init__.py.base.sample __init__.py
+ fi
### local_settings.py
@@ -282,6 +305,8 @@ EOF
"install/local_settings.py.sample" > \
"$INSTANCE/local_settings.py"
+ echo $CELERY_CONF >> "$INSTANCE/local_settings.py"
+
if [ -f $CONFIG_PATH"extra_settings.py" ]; then
ln -s $CONFIG_PATH"extra_settings.py" >> "$INSTANCE/extra_settings.py"
fi