Bash Scripts
Documentation for Scheduled Scripts and Application Startup
Overview
This documentation details the Bash scripts utilized for managing scheduled tasks and starting the Flask application using Gunicorn within a virtual environment. These scripts are designed to automate the execution of daily, weekly, and monthly Python functions and to handle the Flask app’s production deployment on a server.
Scripts Breakdown
-
Daily Tasks Script (
daily_functions.sh):- Purpose: Runs a Python script for daily tasks.
- Steps:
- Activates the Python virtual environment located at
/root/apps/Rifbid-Api-Only/venv. - Executes the Python script located at
/root/apps/Rifbid-Api-Only/daily_functions.py. - Deactivates the virtual environment after the script execution.
- Activates the Python virtual environment located at
-
Monthly Tasks Script (
monthly_tasks.sh):- Purpose: Runs a Python script for monthly tasks.
- Steps:
- Similar to the daily tasks script but targets the Python script for monthly tasks located at
/root/apps/Rifbid-Api-Only/monthly_tasks.py.
- Similar to the daily tasks script but targets the Python script for monthly tasks located at
-
Weekly Tasks Script (
weekly_functions.sh):- Purpose: Runs a Python script for weekly tasks.
- Steps:
- Follows the same pattern as the daily and monthly tasks scripts, targeting the weekly tasks Python script at
/root/apps/Rifbid-Api-Only/weekly_functions.py.
- Follows the same pattern as the daily and monthly tasks scripts, targeting the weekly tasks Python script at
-
Application Start-up Script (
start_app.sh):- Purpose: Starts the Flask application using Gunicorn.
- Details:
- Activates the Python virtual environment.
- Starts the Gunicorn server with:
- Workers (
-w): 4 - Timeout (
-t): 400 seconds - Bind Address (
-b):0.0.0.0:8000 - Log Level: Debug
- Workers (
- The Flask app is assumed to be defined in a variable named
appwithin theappmodule (app:app). Adjust the module and variable names as per your project’s configuration.
Usage
These scripts are intended to be used with cron or another task scheduler to automate their execution at specified intervals:
- Daily tasks script: Scheduled to run once every day.
- Weekly tasks script: Scheduled to run once every week.
- Monthly tasks script: Scheduled to run once every month.
- Application start-up script: Used during the server startup or when manually restarting the server to ensure the application is running with the correct configurations.
Notes
- Ensure that these scripts are executable by running
chmod +x script_name.shfor each script. - It is recommended to check and log the output of these scripts to monitor their execution and troubleshoot potential issues.
- For the application start-up script, ensure that the Gunicorn configuration matches your server and application requirements, including the number of workers and timeout settings to optimize performance and resource usage.
By using these scripts, the maintenance and operation of scheduled tasks and the Flask application can be streamlined and automated, improving efficiency and reliability.