mirror of
https://github.com/YunoHost-Apps/snserver_ynh.git
synced 2024-09-03 20:26:22 +02:00
Update: Add cron and config_panel
This commit is contained in:
parent
23e3f6728b
commit
8a725fd230
8 changed files with 98 additions and 0 deletions
1
conf/cron
Normal file
1
conf/cron
Normal file
|
@ -0,0 +1 @@
|
||||||
|
*/5 * * * * __APP__ __FINALPATH__/cron.sh > /var/log/__APP__/cron.log 2>&1
|
7
conf/cron.env
Normal file
7
conf/cron.env
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
FILES_SIZE=100
|
||||||
|
|
||||||
|
DB_HOST=localhost
|
||||||
|
DB_PORT=3306
|
||||||
|
DB_USERNAME=__DB_USER__
|
||||||
|
DB_PASSWORD=__DB_PWD__
|
||||||
|
DB_DATABASE=__DB_NAME__
|
15
config_panel.toml
Normal file
15
config_panel.toml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
version = "1.0"
|
||||||
|
|
||||||
|
[main]
|
||||||
|
name = "StandardNotes Server configuration"
|
||||||
|
services = ["__APP__"]
|
||||||
|
|
||||||
|
[main.config]
|
||||||
|
name = "Configuration Options"
|
||||||
|
|
||||||
|
[main.config.files_limit]
|
||||||
|
ask = "Default user files limit"
|
||||||
|
type = "string"
|
||||||
|
default = "100"
|
||||||
|
help = "Choose a default limit in MB for the user file upload space.\n 100 = 100 MB, 1024 = 1GB, 10240 = 10GB"
|
||||||
|
bind = "FILES_SIZE:__FINALPATH__/cron.env"
|
|
@ -89,6 +89,13 @@ ynh_backup --src_path="/etc/systemd/system/$app-files.service"
|
||||||
ynh_backup --src_path="/etc/systemd/system/$app-syncing-server.service"
|
ynh_backup --src_path="/etc/systemd/system/$app-syncing-server.service"
|
||||||
ynh_backup --src_path="/etc/systemd/system/$app-syncing-server-worker.service"
|
ynh_backup --src_path="/etc/systemd/system/$app-syncing-server-worker.service"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CRON LOGROTATE
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info "Backing up cron configuration..."
|
||||||
|
|
||||||
|
ynh_backup --src_path="/etc/cron.d/$app"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# END OF SCRIPT
|
# END OF SCRIPT
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -115,6 +115,7 @@ ynh_script_progression --message="Setting up source files..." --weight=2
|
||||||
# Download, check integrity, uncompress and patch the source from app.src
|
# Download, check integrity, uncompress and patch the source from app.src
|
||||||
mkdir -p "$final_path/live"
|
mkdir -p "$final_path/live"
|
||||||
ynh_setup_source --source_id=app --dest_dir="$final_path/live"
|
ynh_setup_source --source_id=app --dest_dir="$final_path/live"
|
||||||
|
cp "$YNH_APP_BASEDIR/sources/extra_files/cron.sh" "$final_path/cron.sh"
|
||||||
|
|
||||||
chmod 750 "$final_path"
|
chmod 750 "$final_path"
|
||||||
chmod -R o-rwx "$final_path"
|
chmod -R o-rwx "$final_path"
|
||||||
|
@ -293,6 +294,17 @@ ynh_systemd_action \
|
||||||
--log_path="/var/log/$app/syncing-server-worker.log" \
|
--log_path="/var/log/$app/syncing-server-worker.log" \
|
||||||
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
|
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SETUP A CRON
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Setup a cron..."
|
||||||
|
|
||||||
|
ynh_add_config --template="../conf/cron.env" --destination="__finalpath__/$app.env"
|
||||||
|
ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app"
|
||||||
|
|
||||||
|
chown root: "/etc/cron.d/$app"
|
||||||
|
chmod 640 "/etc/cron.d/$app"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP FAIL2BAN
|
# SETUP FAIL2BAN
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -249,6 +249,13 @@ ynh_systemd_action \
|
||||||
--log_path="/var/log/$app/syncing-server-worker.log" \
|
--log_path="/var/log/$app/syncing-server-worker.log" \
|
||||||
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
|
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RESTORE THE CRON CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Restoring cron configuration..." --weight=1
|
||||||
|
|
||||||
|
ynh_restore_file --origin_path="/etc/cron.d/$app"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTORE THE LOGROTATE CONFIGURATION
|
# RESTORE THE LOGROTATE CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -265,6 +265,7 @@ then
|
||||||
ynh_secure_remove --file="$final_path/live"
|
ynh_secure_remove --file="$final_path/live"
|
||||||
mkdir -p "$final_path/live"
|
mkdir -p "$final_path/live"
|
||||||
ynh_setup_source --source_id=app --dest_dir="$final_path/live"
|
ynh_setup_source --source_id=app --dest_dir="$final_path/live"
|
||||||
|
cp "$YNH_APP_BASEDIR/sources/extra_files/cron.sh" "$final_path/cron.sh"
|
||||||
|
|
||||||
chmod 750 "$final_path"
|
chmod 750 "$final_path"
|
||||||
chmod -R o-rwx "$final_path"
|
chmod -R o-rwx "$final_path"
|
||||||
|
@ -426,6 +427,17 @@ ynh_systemd_action \
|
||||||
--log_path="/var/log/$app/syncing-server-worker.log" \
|
--log_path="/var/log/$app/syncing-server-worker.log" \
|
||||||
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
|
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SETUP A CRON
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Setup a cron..."
|
||||||
|
|
||||||
|
ynh_add_config --template="../conf/cron.env" --destination="__finalpath__/$app.env"
|
||||||
|
ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app"
|
||||||
|
|
||||||
|
chown root: "/etc/cron.d/$app"
|
||||||
|
chmod 640 "/etc/cron.d/$app"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP FAIL2BAN
|
# SETUP FAIL2BAN
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
37
sources/extra_files/cron.sh
Executable file
37
sources/extra_files/cron.sh
Executable file
|
@ -0,0 +1,37 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ ! -f .env ]
|
||||||
|
then
|
||||||
|
export $(cat cron.env | xargs)
|
||||||
|
fi
|
||||||
|
|
||||||
|
FILE_UPLOAD_BYTES_PER_MB=1048576
|
||||||
|
FILE_UPLOAD_BYTES_LIMIT=$(($FILES_SIZE*$FILE_UPLOAD_BYTES_PER_MB))
|
||||||
|
|
||||||
|
# Searching for new users in the last 10 minutes without a Pro_Plan subscription.
|
||||||
|
mysql --password=$DB_PASSWORD --database=$DB_DATABASE <<< " \
|
||||||
|
SELECT email FROM users WHERE created_at >= DATE_SUB( TIMESTAMP(NOW()), INTERVAL 10 HOUR) AND NOT EXISTS( SELECT * FROM user_subscriptions WHERE user_subscriptions.plan_name = \"PRO_PLAN\" AND user_subscriptions.user_uuid = users.uuid ); \
|
||||||
|
" 2>/dev/null |
|
||||||
|
|
||||||
|
# Read through the piped result until it's empty.
|
||||||
|
while IFS='\n' read email; do
|
||||||
|
if [[ $email = "0" ]]; then
|
||||||
|
echo "No new users registered"
|
||||||
|
fi
|
||||||
|
if [[ ${email} = "email" ]]; then
|
||||||
|
echo "New users found:"
|
||||||
|
echo "----------------------------------------"
|
||||||
|
else
|
||||||
|
# ADD new user with Email $EMAIL a PRO_PLAN subscription
|
||||||
|
echo "[$(date -Iseconds)] User: $email added to the PRO_PLAN subscription."
|
||||||
|
mysql --password=$DB_PASSWORD --database=$DB_DATABASE -e \
|
||||||
|
"INSERT INTO user_roles (role_uuid , user_uuid) VALUES ((SELECT uuid FROM roles WHERE name=\"PRO_USER\" ORDER BY version DESC limit 1) ,(SELECT uuid FROM users WHERE email=\"$email\")) ON DUPLICATE KEY UPDATE role_uuid = VALUES(role_uuid);"
|
||||||
|
mysql --password=$DB_PASSWORD --database=$DB_DATABASE -e \
|
||||||
|
"INSERT INTO user_subscriptions SET uuid=UUID(), plan_name=\"PRO_PLAN\", ends_at=8640000000000000, created_at=0, updated_at=0, user_uuid=(SELECT uuid FROM users WHERE email=\"$email\"), subscription_id=1, subscription_type=\"regular\";"
|
||||||
|
|
||||||
|
# Add new user Files space. Size is 1GB*$FILES_SIZE
|
||||||
|
echo "[$(date -Iseconds)] User: $email added $FILES_SIZE MB of file spcae."
|
||||||
|
mysql --password=$DB_PASSWORD --database=$DB_DATABASE -e \
|
||||||
|
"INSERT INTO subscription_settings(uuid, name, value, created_at, updated_at, user_subscription_uuid) VALUES (UUID(), \"FILE_UPLOAD_BYTES_LIMIT\", \"$FILE_UPLOAD_BYTES_LIMIT\", FLOOR(UNIX_TIMESTAMP(NOW(6))*1000000), FLOOR(UNIX_TIMESTAMP(NOW(6))*1000000), (SELECT us.uuid FROM user_subscriptions us INNER JOIN users u ON us.user_uuid=u.uuid WHERE u.email=\"$email\"));"
|
||||||
|
fi
|
||||||
|
done
|
Loading…
Reference in a new issue