second commit
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
|
||||
case $1 in
|
||||
minute) ;;
|
||||
daily) ;;
|
||||
*) echo "expected [minute|daily]" && exit 1 ;;
|
||||
esac
|
||||
|
||||
SELECTOR=$1
|
||||
|
||||
for i in /var/www/cagettepei/*; do
|
||||
if [[ -d $i ]]; then
|
||||
cd "$i/www" || echo "Folder not found: $i/www"
|
||||
echo "cron-$SELECTOR in: $i"
|
||||
neko index.n cron/$SELECTOR
|
||||
echo
|
||||
fi
|
||||
done
|
||||
@@ -0,0 +1,8 @@
|
||||
Listen {{ env.APP_PORT }}
|
||||
<VirtualHost *:{{ env.APP_PORT }}>
|
||||
DirectoryIndex index.n
|
||||
DocumentRoot /var/www/cagettepei/{{env.APP_NAME}}/www/
|
||||
|
||||
ErrorLog ${APACHE_LOG_DIR}/cagettepei/{{env.APP_NAME}}/debug.log
|
||||
ErrorLogFormat "[%{uc}t] %M"
|
||||
</VirtualHost>
|
||||
@@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=Run batch cagettepei every day
|
||||
|
||||
[Service]
|
||||
User=www-data
|
||||
SyslogIdentifier=cagettepei
|
||||
ExecStart=/var/www/cagettepei/cagettepei-batch daily
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=Timer for batch cagettepei every day
|
||||
Requires=apache2.service
|
||||
|
||||
[Timer]
|
||||
OnCalendar=daily
|
||||
Unit=cagettepei-batch-day.service
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
@@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=Run batch cagettepei every minute
|
||||
|
||||
[Service]
|
||||
User=www-data
|
||||
SyslogIdentifier=cagettepei
|
||||
ExecStart=/var/www/cagettepei/cagettepei-batch minute
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=Timer for batch cagettepei every minute
|
||||
Requires=apache2.service
|
||||
|
||||
[Timer]
|
||||
OnCalendar=minutely
|
||||
Unit=cagettepei-batch-minute.service
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
@@ -0,0 +1,23 @@
|
||||
server {
|
||||
listen {{ APP_PORT }} default_server;
|
||||
|
||||
root /var/www/{{APP_NAME}}/htdocs; # Check this
|
||||
error_log /var/log/nginx/{{APP_NAME}}/error.log;
|
||||
|
||||
index index.php index.html index.htm;
|
||||
charset utf-8;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.php;
|
||||
}
|
||||
|
||||
location ~ [^/]\.php(/|$) {
|
||||
client_max_body_size 50M;
|
||||
try_files $uri =404;
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
fastcgi_read_timeout 600;
|
||||
include fastcgi_params;
|
||||
fastcgi_pass unix:/var/run/php/php{{PHP_VERSION}}-fpm.sock;
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
@@ -0,0 +1,17 @@
|
||||
[options]
|
||||
data_dir = /home/odoo/data-{{ APP_NAME }}
|
||||
|
||||
xmlrpc_port = {{ APP_PORT }}
|
||||
longpolling_port = {{ LONG_PORT }}
|
||||
|
||||
db_host = ct1.lxd
|
||||
db_name = odoo12-{{ APP_NAME }}
|
||||
db_user = odoo12-{{ APP_NAME }}
|
||||
db_password = odoo12-{{ APP_NAME }}
|
||||
list_db = {{ target != 'prod'}}
|
||||
|
||||
workers = 2
|
||||
db_maxconn = 10
|
||||
db_filter = .*
|
||||
syslog = True
|
||||
proxy_mode = True
|
||||
@@ -0,0 +1,14 @@
|
||||
[Unit]
|
||||
Description=Odoo12 {{ APP_NAME }}
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
SyslogIdentifier=odoo12-{{ APP_NAME }}
|
||||
PermissionsStartOnly=true
|
||||
User=odoo
|
||||
Group=odoo
|
||||
ExecStart=/home/odoo/venv/bin/python3 /home/odoo/odoo12/odoo-bin -c /etc/odoo12/{{ APP_NAME }}.conf
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
|
||||
CLIENT=$1
|
||||
ADDON=$2
|
||||
|
||||
function usage() {
|
||||
echo 'usage: <CLIENT> <ADDON>'
|
||||
exit 1
|
||||
}
|
||||
|
||||
# VERIFICATION
|
||||
|
||||
[[ -z "$CLIENT" || -z "$ADDON" ]] && usage
|
||||
[[ ! -d "/home/odoo/data-${CLIENT}" ]] && echo "unknown CLIENT <${CLIENT}>, should exist in folder /home/odoo/data-..." && exit 2
|
||||
|
||||
URL="https://pypi.org/project/odoo12-addon-${ADDON}/"
|
||||
curl --output /dev/null --silent --head --fail "${URL}"
|
||||
[[ $? -ne 0 ]] && echo "unknown ADDON <${ADDON}>, should be downloadable from: ${URL}" && exit 3
|
||||
|
||||
[[ -d "/home/odoo/data-${CLIENT}/addons/12.0/${ADDON}" ]] && echo "ADDON <${ADDON}> already exists, consider removing manually!" && exit 4
|
||||
|
||||
# ACTION
|
||||
|
||||
package=$(curl -Ls ${URL} | rg '<a href="(https://files.pythonhosted.org/.*)">' -r '$1')
|
||||
wget $package -O /tmp/package.zip
|
||||
rm /tmp/ADDON -rf && mkdir /tmp/ADDON
|
||||
unzip /tmp/package.zip 'odoo/addons/*' -d /tmp/ADDON/
|
||||
chown -R odoo:odoo /tmp/ADDON/
|
||||
mv /tmp/ADDON/odoo/addons/* /home/odoo/data-${CLIENT}/addons/12.0/
|
||||
|
||||
echo "FORCE RELOADING ADDONS with: ./web?debug#menu_id=48&action=36"
|
||||
@@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
|
||||
CLIENT=$1
|
||||
ADDON=$2
|
||||
|
||||
function usage() {
|
||||
echo 'usage: <CLIENT> <ADDON>'
|
||||
exit 100
|
||||
}
|
||||
|
||||
# VERIFICATION
|
||||
|
||||
[[ -z "$CLIENT" || -z "$ADDON" ]] && usage
|
||||
[[ ! -d "/home/odoo/data-${CLIENT}" ]] && echo "unknown CLIENT <${CLIENT}>, should exist in folder /home/odoo/data-..." && exit 2
|
||||
|
||||
URL="https://pypi.org/project/odoo-addon-${ADDON}/"
|
||||
curl --output /dev/null --silent --head --fail "${URL}"
|
||||
[[ $? -ne 0 ]] && echo "unknown ADDON <${ADDON}>, should be downloadable from: ${URL}" && exit 3
|
||||
|
||||
[[ -d "/home/odoo/data-${CLIENT}/addons/15.0/${ADDON}" ]] && echo "ADDON <${ADDON}> already exists, consider removing manually!" && exit 4
|
||||
|
||||
# ACTION
|
||||
|
||||
package=$(curl -Ls "$URL" | rg '<a href="(https://files.pythonhosted.org/.*)">' -r '$1')
|
||||
wget $package -O /tmp/package.zip
|
||||
rm /tmp/ADDON -rf && mkdir /tmp/ADDON
|
||||
unzip /tmp/package.zip 'odoo/addons/*' -d /tmp/ADDON/
|
||||
real_name=$(unzip -l /tmp/package.zip | head -n4 | tail -n1 | cut -d'/' -f3)
|
||||
chown -R odoo:odoo /tmp/ADDON/
|
||||
mv /tmp/ADDON/odoo/addons/* "/home/odoo/data-$CLIENT/addons/15.0/"
|
||||
|
||||
# ADD
|
||||
su odoo -c "python3.9 /home/odoo/odoo15/odoo-bin -c /etc/odoo15/$CLIENT.conf -i $real_name -d odoo15-$CLIENT --worker=0 --stop-after-init"
|
||||
@@ -0,0 +1,17 @@
|
||||
[options]
|
||||
data_dir = /home/odoo/data-{{ APP_NAME }}
|
||||
|
||||
xmlrpc_port = {{ APP_PORT }}
|
||||
longpolling_port = {{ LONG_PORT }}
|
||||
|
||||
db_host = ct1.lxd
|
||||
db_name = odoo15-{{ APP_NAME }}
|
||||
db_user = odoo15-{{ APP_NAME }}
|
||||
db_password = odoo15-{{ APP_NAME }}
|
||||
list_db = {{ target != 'prod'}}
|
||||
|
||||
workers = 2
|
||||
db_maxconn = 10
|
||||
db_filter = .*
|
||||
syslog = True
|
||||
proxy_mode = True
|
||||
@@ -0,0 +1,14 @@
|
||||
[Unit]
|
||||
Description=Odoo15 {{ APP_NAME }}
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
SyslogIdentifier=odoo15-{{ APP_NAME }}
|
||||
PermissionsStartOnly=true
|
||||
User=odoo
|
||||
Group=odoo
|
||||
ExecStart=python3.9 /home/odoo/odoo15/odoo-bin -c /etc/odoo15/{{ APP_NAME }}.conf
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/bin/bash
|
||||
|
||||
function detectWordpress() {
|
||||
local result=$(pwd)
|
||||
while [[ ! ("$result" == / || -f "$result/wp-config.php") ]]; do
|
||||
result=$(dirname "$result")
|
||||
done
|
||||
|
||||
if [[ "$result" == / ]]; then
|
||||
echo >&2 "no WORDPRESS detected from current folder <$(pwd)>!"
|
||||
exit 100
|
||||
fi
|
||||
|
||||
echo "$result"
|
||||
}
|
||||
|
||||
## MAIN
|
||||
## ----
|
||||
|
||||
set -Eeuo pipefail
|
||||
WP_BASE=$(detectWordpress)
|
||||
WP_CONFIG="$WP_BASE/wp-config.php"
|
||||
DB_HOST=$(grep DB_HOST $WP_CONFIG | cut -d"'" -f4)
|
||||
DB_NAME=$(grep DB_NAME $WP_CONFIG | cut -d"'" -f4)
|
||||
DB_USER=$(grep DB_USER $WP_CONFIG | cut -d"'" -f4)
|
||||
DB_PASSWORD=$(grep DB_PASSWORD $WP_CONFIG | cut -d"'" -f4)
|
||||
TODAY=$(date +%F)
|
||||
BACKUP_DIR="/mnt/SHARED/wordpress-backup/$DB_NAME-$TODAY"
|
||||
|
||||
[[ -d "$BACKUP_DIR" ]] && find "$BACKUP_DIR" -mindepth 1 -delete || mkdir -p "$BACKUP_DIR"
|
||||
|
||||
echo -n "backing up database..."
|
||||
mariadb-dump -h "$DB_HOST" -u "$DB_NAME" -p"$DB_PASSWORD" "$DB_NAME" | gzip >"$BACKUP_DIR/$DB_NAME".mariadb.gz
|
||||
echo OK
|
||||
|
||||
echo -n "compressing as tar.gz the wp-content folder ..."
|
||||
tar -czvf "$BACKUP_DIR/wp-content.tgz" -C "$WP_BASE" wp-content
|
||||
echo OK
|
||||
|
||||
echo -n "copying wp-config.php file ..."
|
||||
cp "$WP_BASE/wp-config.php" "$BACKUP_DIR"
|
||||
echo OK
|
||||
|
||||
echo "successful backup in $BACKUP_DIR, db + wp-content + wp-config"
|
||||
@@ -0,0 +1,37 @@
|
||||
server {
|
||||
listen {{ env.APP_PORT }} default_server;
|
||||
|
||||
access_log /var/log/nginx/{{ env.APP_NAME }}/wp-access.log;
|
||||
error_log /var/log/nginx/{{ env.APP_NAME }}/wp-error.log;
|
||||
|
||||
client_max_body_size 50M;
|
||||
root /var/www/wordpress/{{ env.APP_NAME }};
|
||||
index index.php index.html index.htm;
|
||||
charset UTF-8;
|
||||
|
||||
location / {
|
||||
try_files $uri/ /index.php?$args;
|
||||
}
|
||||
|
||||
location ~ \.php$ {
|
||||
try_files $uri =404;
|
||||
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||
fastcgi_pass unix:/run/php/php-fpm.sock;
|
||||
fastcgi_index index.php;
|
||||
include fastcgi.conf;
|
||||
}
|
||||
|
||||
location ~* \.(js|css|png|jpg|jpeg|svg|gif|ico|eot|otf|ttf|woff|woff2|mp3|wav|ogg)$ {
|
||||
add_header Access-Control-Allow-Origin *;
|
||||
access_log off; log_not_found off; expires 30d;
|
||||
}
|
||||
|
||||
# Mailpoet - tinyMCE quick fix
|
||||
location ~ /wp-content/plugins/wysija-newsletters/js/tinymce/.*\.(htm|html)$ {
|
||||
add_header Access-Control-Allow-Origin *;
|
||||
access_log off; log_not_found off; expires 30d;
|
||||
}
|
||||
|
||||
location = /robots.txt { access_log off; log_not_found off; }
|
||||
location ~ /\. { deny all; access_log off; log_not_found off; }
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
#!/bin/bash
|
||||
|
||||
### error_handling
|
||||
|
||||
function trap_error() {
|
||||
error_code=$1
|
||||
error_line=$2
|
||||
|
||||
if [[ ${error_code} -lt 100 ]]; then
|
||||
printf "\nEXIT #${error_code} due to error at line ${error_line} : \n-----------------------------------------\n"
|
||||
sed "${error_line}q;d" $0
|
||||
echo
|
||||
fi
|
||||
exit $error_code
|
||||
}
|
||||
set -e
|
||||
trap 'trap_error $? $LINENO' ERR
|
||||
|
||||
### ------------------
|
||||
|
||||
function detectWordpress() {
|
||||
local result=$(pwd)
|
||||
while [[ ! ("$result" == / || -f "$result/wp-config.php") ]]; do
|
||||
result=$(dirname "$result")
|
||||
done
|
||||
|
||||
if [[ "$result" == / ]]; then
|
||||
echo >&2 "no WORDPRESS detected!"
|
||||
exit 100
|
||||
fi
|
||||
|
||||
echo "$result"
|
||||
}
|
||||
|
||||
function getConfigComment() {
|
||||
local result=$(grep -e "^#" $WP_CONFIG | grep "$1" | head -n1 | cut -d ',' -f2 | cut -d \' -f2)
|
||||
if [[ -z "$result" ]]; then
|
||||
echo "config comment: $1 not found!"
|
||||
exit 2
|
||||
fi
|
||||
echo "$result"
|
||||
}
|
||||
function getConfigEntry() {
|
||||
local result=$(grep "$1" $WP_CONFIG | head -n1 | cut -d ',' -f2 | cut -d \' -f2)
|
||||
if [[ -z "$result" ]]; then
|
||||
echo "config entry: $1 not found!"
|
||||
exit 2
|
||||
fi
|
||||
echo "$result"
|
||||
}
|
||||
|
||||
function sql() {
|
||||
local result=$(echo "$1" | mysql -srN -u $DB_USER -h $DB_HOST $DB_NAME -p$DB_PASS 2>&1)
|
||||
if [[ $result =~ ^ERROR ]]; then
|
||||
echo >&2 "sql failure: $result"
|
||||
exit 3
|
||||
else
|
||||
echo "$result"
|
||||
fi
|
||||
}
|
||||
|
||||
function sqlFile() {
|
||||
local result=$(cat "$1" | mysql -srN -u $DB_USER -h $DB_HOST $DB_NAME -p$DB_PASS 2>&1)
|
||||
if [[ $result =~ ^ERROR ]]; then
|
||||
echo >&2 "sql failure: $result"
|
||||
exit 3
|
||||
else
|
||||
echo "$result"
|
||||
fi
|
||||
}
|
||||
function changeHome() {
|
||||
local FROM=$1
|
||||
local TO=$2
|
||||
sql "UPDATE wp_options SET option_value = replace(option_value, '$FROM', '$TO') WHERE option_name = 'home' OR option_name = 'siteurl'"
|
||||
sql "UPDATE wp_posts SET guid = replace(guid, '$FROM','$TO')"
|
||||
sql "UPDATE wp_posts SET post_content = replace(post_content, '$FROM', '$TO')"
|
||||
sql "UPDATE wp_postmeta SET meta_value = replace(meta_value,'$FROM','$TO')"
|
||||
}
|
||||
|
||||
function lastMigration() {
|
||||
sql "SELECT migration_file FROM migrations ORDER BY last_run DESC LIMIT 1"
|
||||
}
|
||||
|
||||
function upgradeMigration() {
|
||||
local LAST_MIGRATION=$1
|
||||
local UPGRADE=false
|
||||
if [[ "$LAST_MIGRATION" == '' ]]; then
|
||||
UPGRADE=true
|
||||
fi
|
||||
|
||||
local MIG_BASE="$WP_BASE/wp-content/migrations"
|
||||
local MIGRATIONS=$(ls -p1 $MIG_BASE | grep -v /)
|
||||
local MIG_FILE
|
||||
for mig in $MIGRATIONS; do
|
||||
if [[ "$UPGRADE" == true ]]; then
|
||||
printf "applying %50s ... " $mig
|
||||
printf "%d %d" $(sqlFile $MIG_BASE/$mig)
|
||||
echo " DONE"
|
||||
MIG_FILE=$mig
|
||||
else
|
||||
printf "useless %50s \n" $mig
|
||||
if [[ "$LAST_MIGRATION" == "$mig" ]]; then
|
||||
UPGRADE=true
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ $UPGRADE == true && $MIG_FILE != '' ]]; then
|
||||
local done=$(sql "INSERT INTO migrations(migration_file, last_run) VALUES ('$mig', NOW())")
|
||||
echo "all migrations succeeded, wrote: $mig"
|
||||
else
|
||||
echo "already up-to-date"
|
||||
fi
|
||||
}
|
||||
|
||||
function buildMigrations() {
|
||||
if [[ ! -d "$WP_BASE"/wp-content/migrations ]]; then
|
||||
mkdir -p "$WP_BASE"/wp-content/migrations
|
||||
echo "migrations folder created!"
|
||||
fi
|
||||
|
||||
sql "CREATE TABLE IF NOT EXISTS migrations (id int(11) NOT NULL AUTO_INCREMENT, migration_file varchar(255) COLLATE utf8_unicode_ci NOT NULL, last_run varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (id) )"
|
||||
|
||||
}
|
||||
|
||||
function playEnvironment() {
|
||||
|
||||
buildMigrations
|
||||
|
||||
local PLATFORM=$1
|
||||
local PLATFORM_BASE="$WP_BASE/wp-content/migrations/$PLATFORM"
|
||||
if [[ -d "$PLATFORM_BASE" ]]; then
|
||||
echo play platform $PLATFORM
|
||||
|
||||
local MIGRATIONS=$(ls -p1 $PLATFORM_BASE | grep -v /)
|
||||
for mig in $MIGRATIONS; do
|
||||
printf "applying %50s ... " $mig
|
||||
printf "%d %d" $(sqlFile $PLATFORM_BASE/$mig)
|
||||
echo " DONE"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
## MAIN
|
||||
## ----
|
||||
|
||||
WP_BASE=$(detectWordpress)
|
||||
WP_CONFIG="$WP_BASE/wp-config.php"
|
||||
echo "WP_BASE = $WP_BASE"
|
||||
|
||||
WP_HOME=$(getConfigComment WP_HOME)
|
||||
echo "WP_HOME = $WP_HOME"
|
||||
|
||||
DB_HOST=$(getConfigEntry DB_HOST)
|
||||
DB_NAME=$(getConfigEntry DB_NAME)
|
||||
DB_USER=$(getConfigEntry DB_USER)
|
||||
DB_PASS=$(getConfigEntry DB_PASSWORD)
|
||||
|
||||
CURRENT_HOME=$(sql "SELECT option_value FROM wp_options WHERE option_name = 'home'")
|
||||
if [[ "$CURRENT_HOME" != "$WP_HOME" ]]; then
|
||||
echo "HOME detected = $CURRENT_HOME , needs to apply changes"
|
||||
$(changeHome "$CURRENT_HOME" "$WP_HOME")
|
||||
fi
|
||||
|
||||
if [[ "$WP_HOME" =~ https?:\/\/beta[0-9]*\..*|https?:\/\/.*\.beta[0-9]*\..* ]]; then
|
||||
playEnvironment BETA
|
||||
else
|
||||
if [[ "$WP_HOME" =~ https?:\/\/dev[0-9]*\..*|https?:\/\/.*\.dev[0-9]*\..* ]]; then
|
||||
playEnvironment DEV
|
||||
else
|
||||
playEnvironment PROD
|
||||
fi
|
||||
fi
|
||||
|
||||
CURRENT_MIGRATION=$(lastMigration)
|
||||
upgradeMigration "$CURRENT_MIGRATION"
|
||||
Reference in New Issue
Block a user