1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/pagure_ynh.git synced 2024-09-03 19:56:19 +02:00

Add redis, worker and admin

This commit is contained in:
Jean-Baptiste Holcroft 2018-05-20 23:57:36 +02:00
parent 443463c925
commit b03679c70d
5 changed files with 93 additions and 5 deletions

View file

@ -0,0 +1,14 @@
[Unit]
Description=__APP__ worker for backend git interaction
After=redis.target
[Service]
ExecStart=/usr/bin/celery worker -A pagure.lib.tasks --loglevel=info
Environment="PAGURE_CONFIG=__FINALPATH__/pagure.cfg"
Type=simple
User=__APP__
Group=__APP__
Restart=on-failure
[Install]
WantedBy=multi-user.target

View file

@ -24,7 +24,7 @@ DB_URL = 'postgres://__DB_USER__:__DB_PWD__@localhost/__DB_NAME__'
ADMIN_GROUP = ['sysadmin-main']
### Hard-coded list of global admins
PAGURE_ADMIN_USERS = []
PAGURE_ADMIN_USERS = ['__ADMIN__']
### The email address to which the flask.log will send the errors (tracebacks)
EMAIL_ERROR = 'root@__DOMAIN__'
@ -153,9 +153,9 @@ WEBHOOK = False
### Redis configuration
# A redis server is required for both the Event-Source server or the web-hook
# server.
REDIS_HOST = '0.0.0.0'
REDIS_HOST = '127.0.0.1'
REDIS_PORT = 6379
REDIS_DB = 0
REDIS_DB = __REDIS_DB__
# Authentication related configuration option

View file

@ -1,5 +1,50 @@
#!/bin/bash
#=================================================
#
# Redis HELPERS
#
# Point of contact : Jean-Baptiste Holcroft <jean-baptiste@holcroft.fr>
#=================================================
# get the first available redis database
#
# usage: ynh_redis_get_free_db
# | returns: the database number to use
ynh_redis_get_free_db() {
local result max db
result=$(redis-cli INFO keyspace)
# get the num
max=$(cat /etc/redis/redis.conf | grep ^databases | grep -Eow "[0-9]+")
db=0
# default Debian setting is 15 databases
for i in $(seq 0 "$max")
do
if ! echo "$result" | grep -q "db$i"
then
db=$i
break 1
db=-1
fi
done
test "$db" -eq -1 && ynh_die "No available Redis databases..."
echo "$db"
}
# Create a master password and set up global settings
# Please always call this script in install and restore scripts
#
# usage: ynh_redis_remove_db database
# | arg: database - the database to erase
ynh_redis_remove_db() {
local db=$1
redis-cli -n "$db" flushall
}
ynh_check_global_uwsgi_config () {
uwsgi --version || ynh_die "You need to add uwsgi (and appropriate plugin) as a dependency"

View file

@ -75,7 +75,7 @@ ynh_app_setting_set "$app" final_path "$final_path"
ynh_install_app_dependencies git virtualenv python-virtualenv libgit2-dev \
libjpeg-dev gcc libffi-dev python-dev python-cffi \
python-gdbm python-psycopg2 \
postgresql uwsgi uwsgi-plugin-python
postgresql uwsgi uwsgi-plugin-python redis-server
#=================================================
# CREATE A PostgreSQL DATABASE
@ -106,6 +106,13 @@ ynh_system_user_create "$app" "${final_path}"
#=================================================
# SPECIFIC SETUP
#=================================================
# SETUP SYSTEMD
#=================================================
# Create a dedicated systemd config
ynh_add_systemd_config "$app-worker" "pagure-worker.service"
#=================================================
# setup pagure.cfg
#=================================================
@ -113,13 +120,18 @@ ynh_system_user_create "$app" "${final_path}"
secret_key=$(ynh_string_random)
salt_email=$(ynh_string_random)
redis_db=$(ynh_redis_get_free_db)
ynh_app_setting_set "$app" redis_db "$redis_db"
cp ../conf/pagure.cfg.sample "$final_path/pagure.cfg"
ynh_replace_string "__REDIS_DB__" "$redis_db" "$final_path/pagure.cfg"
ynh_replace_string "__SECRET_KEY__" "$secret_key" "$final_path/pagure.cfg"
ynh_replace_string "__DB_USER__" "$app" "$final_path/pagure.cfg"
ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/pagure.cfg"
ynh_replace_string "__DB_NAME__" "$db_name" "$final_path/pagure.cfg"
ynh_replace_string "__DOMAIN__" "$domain" "$final_path/pagure.cfg"
ynh_replace_string "__SALT_EMAIL__" "$salt_email" "$final_path/pagure.cfg"
ynh_replace_string "__ADMIN__" "$admin" "$final_path/pagure.cfg"
#=================================================
# setup pagure.wsgi
@ -153,7 +165,7 @@ virtualenv "${final_path}/venv"
pip install cffi
pip install pygit2==0.24
pip install -r "${final_path}/pagure/requirements.txt"
pip install psycopg2 cryptography py-bcrypt python-fedora
pip install psycopg2-binary cryptography py-bcrypt python-fedora
)
#=================================================

View file

@ -17,6 +17,16 @@ app=$YNH_APP_INSTANCE_NAME
db_name=$(ynh_app_setting_get "$app" db_name)
domain=$(ynh_app_setting_get "$app" domain)
redis_db=$(ynh_app_setting_get "$app" redis_db)
#=================================================
# STANDARD REMOVE
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
# Remove the dedicated systemd config
ynh_remove_systemd_config "$app-worker"
#=================================================
# REMOVE uwsgi and systemd files
@ -31,6 +41,13 @@ ynh_remove_uwsgi_service
# Remove a database if it exists, along with the associated user
ynh_psql_remove_db "$db_name" "$app"
#=================================================
# REMOVE THE Redis DATABASE
#=================================================
# Remove a database if it exists, along with the associated user
ynh_redis_remove_db "$redis_db"
#=================================================
# REMOVE DEPENDENCIES
#=================================================