Fix .env file parsing errors with better validation and error handling
This commit is contained in:
@@ -56,9 +56,11 @@ SMTP_USERNAME=your-email@gmail.com
|
||||
SMTP_PASSWORD=your-app-password
|
||||
SMTP_SECURE=true
|
||||
MAIL_FROM_ADDRESS=your-email@gmail.com
|
||||
MAIL_FROM_NAME=Docmost
|
||||
MAIL_FROM_NAME="Docmost"
|
||||
```
|
||||
|
||||
**Important**: Values with spaces must be quoted with double quotes.
|
||||
|
||||
### S3 Storage
|
||||
|
||||
To use Amazon S3 or compatible storage:
|
||||
@@ -110,6 +112,34 @@ cloudron exec --app docmost -- env | grep -E "(MAIL|STORAGE|S3)" | sort
|
||||
cloudron logs --app docmost
|
||||
```
|
||||
|
||||
### .env File Format Errors
|
||||
|
||||
If you see errors like `line 1: Docmost: command not found`, your .env file has syntax errors:
|
||||
|
||||
1. **Values with spaces must be quoted**:
|
||||
```bash
|
||||
# Wrong:
|
||||
MAIL_FROM_NAME=My Company
|
||||
|
||||
# Correct:
|
||||
MAIL_FROM_NAME="My Company"
|
||||
```
|
||||
|
||||
2. **No spaces around equals sign**:
|
||||
```bash
|
||||
# Wrong:
|
||||
MAIL_DRIVER = smtp
|
||||
|
||||
# Correct:
|
||||
MAIL_DRIVER=smtp
|
||||
```
|
||||
|
||||
3. **Check for invalid characters**:
|
||||
```bash
|
||||
# Validate your .env file:
|
||||
cloudron exec --app docmost -- cat /app/data/.env
|
||||
```
|
||||
|
||||
### Reset to Defaults
|
||||
|
||||
To reset to Cloudron defaults, simply remove the custom .env file:
|
||||
|
12
start.sh
12
start.sh
@@ -102,9 +102,19 @@ fi
|
||||
# Load custom environment variables if they exist
|
||||
if [ -f "/app/data/.env" ]; then
|
||||
echo "=> Loading custom environment variables from /app/data/.env"
|
||||
# Validate .env file format before sourcing
|
||||
if grep -q "^[[:space:]]*[^#][^=]*=" /app/data/.env 2>/dev/null; then
|
||||
set -a # automatically export all variables
|
||||
source /app/data/.env
|
||||
if source /app/data/.env 2>/dev/null; then
|
||||
echo "=> Custom .env file loaded successfully"
|
||||
else
|
||||
echo "=> Warning: Error loading .env file, using Cloudron defaults"
|
||||
echo "=> Check /app/data/.env for syntax errors (values with spaces need quotes)"
|
||||
fi
|
||||
set +a # stop automatically exporting
|
||||
else
|
||||
echo "=> Warning: /app/data/.env appears to be empty or invalid, using Cloudron defaults"
|
||||
fi
|
||||
else
|
||||
echo "=> No custom .env file found, using Cloudron defaults"
|
||||
fi
|
||||
|
Reference in New Issue
Block a user