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:
parent
443463c925
commit
b03679c70d
5 changed files with 93 additions and 5 deletions
14
conf/pagure-worker.service
Normal file
14
conf/pagure-worker.service
Normal 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
|
|
@ -24,7 +24,7 @@ DB_URL = 'postgres://__DB_USER__:__DB_PWD__@localhost/__DB_NAME__'
|
||||||
ADMIN_GROUP = ['sysadmin-main']
|
ADMIN_GROUP = ['sysadmin-main']
|
||||||
|
|
||||||
### Hard-coded list of global admins
|
### 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)
|
### The email address to which the flask.log will send the errors (tracebacks)
|
||||||
EMAIL_ERROR = 'root@__DOMAIN__'
|
EMAIL_ERROR = 'root@__DOMAIN__'
|
||||||
|
@ -153,9 +153,9 @@ WEBHOOK = False
|
||||||
### Redis configuration
|
### Redis configuration
|
||||||
# A redis server is required for both the Event-Source server or the web-hook
|
# A redis server is required for both the Event-Source server or the web-hook
|
||||||
# server.
|
# server.
|
||||||
REDIS_HOST = '0.0.0.0'
|
REDIS_HOST = '127.0.0.1'
|
||||||
REDIS_PORT = 6379
|
REDIS_PORT = 6379
|
||||||
REDIS_DB = 0
|
REDIS_DB = __REDIS_DB__
|
||||||
|
|
||||||
# Authentication related configuration option
|
# Authentication related configuration option
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,50 @@
|
||||||
#!/bin/bash
|
#!/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 () {
|
ynh_check_global_uwsgi_config () {
|
||||||
uwsgi --version || ynh_die "You need to add uwsgi (and appropriate plugin) as a dependency"
|
uwsgi --version || ynh_die "You need to add uwsgi (and appropriate plugin) as a dependency"
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ ynh_app_setting_set "$app" final_path "$final_path"
|
||||||
ynh_install_app_dependencies git virtualenv python-virtualenv libgit2-dev \
|
ynh_install_app_dependencies git virtualenv python-virtualenv libgit2-dev \
|
||||||
libjpeg-dev gcc libffi-dev python-dev python-cffi \
|
libjpeg-dev gcc libffi-dev python-dev python-cffi \
|
||||||
python-gdbm python-psycopg2 \
|
python-gdbm python-psycopg2 \
|
||||||
postgresql uwsgi uwsgi-plugin-python
|
postgresql uwsgi uwsgi-plugin-python redis-server
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CREATE A PostgreSQL DATABASE
|
# CREATE A PostgreSQL DATABASE
|
||||||
|
@ -106,6 +106,13 @@ ynh_system_user_create "$app" "${final_path}"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC SETUP
|
# SPECIFIC SETUP
|
||||||
|
#=================================================
|
||||||
|
# SETUP SYSTEMD
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Create a dedicated systemd config
|
||||||
|
ynh_add_systemd_config "$app-worker" "pagure-worker.service"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# setup pagure.cfg
|
# setup pagure.cfg
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -113,13 +120,18 @@ ynh_system_user_create "$app" "${final_path}"
|
||||||
secret_key=$(ynh_string_random)
|
secret_key=$(ynh_string_random)
|
||||||
salt_email=$(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"
|
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 "__SECRET_KEY__" "$secret_key" "$final_path/pagure.cfg"
|
||||||
ynh_replace_string "__DB_USER__" "$app" "$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_PWD__" "$db_pwd" "$final_path/pagure.cfg"
|
||||||
ynh_replace_string "__DB_NAME__" "$db_name" "$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 "__DOMAIN__" "$domain" "$final_path/pagure.cfg"
|
||||||
ynh_replace_string "__SALT_EMAIL__" "$salt_email" "$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
|
# setup pagure.wsgi
|
||||||
|
@ -153,7 +165,7 @@ virtualenv "${final_path}/venv"
|
||||||
pip install cffi
|
pip install cffi
|
||||||
pip install pygit2==0.24
|
pip install pygit2==0.24
|
||||||
pip install -r "${final_path}/pagure/requirements.txt"
|
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
|
||||||
)
|
)
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -17,6 +17,16 @@ app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
db_name=$(ynh_app_setting_get "$app" db_name)
|
db_name=$(ynh_app_setting_get "$app" db_name)
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
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
|
# REMOVE uwsgi and systemd files
|
||||||
|
@ -31,6 +41,13 @@ ynh_remove_uwsgi_service
|
||||||
# Remove a database if it exists, along with the associated user
|
# Remove a database if it exists, along with the associated user
|
||||||
ynh_psql_remove_db "$db_name" "$app"
|
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
|
# REMOVE DEPENDENCIES
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
Loading…
Reference in a new issue