This guide explains how to set up automatic startup and graceful shutdown for BasicChat with Redis integration.
# Make scripts executable
chmod +x start_basicchat.sh launch_basicchat.sh
# Start BasicChat with automatic Redis management
./start_basicchat.sh# Use the simple launcher
./launch_basicchat.sh- Detects if Redis is already running
- Starts Redis automatically if not running
- Supports multiple Redis installation methods:
- Direct
redis-servercommand - Homebrew services (macOS)
- systemctl (Linux)
- Direct
- Graceful Redis shutdown on exit
- Port availability checking
- Service readiness verification
- Automatic retry logic
- Clear status reporting with colors
- Handles Ctrl+C gracefully
- Stops all Celery workers
- Terminates Streamlit process
- Cleans up Redis if started by script
- Waits for processes to finish
- Automatic virtual environment activation
- Environment variable configuration
- Directory setup
- Service dependency checking
# Install Redis
brew install redis
# Start Redis service (optional - script will handle this)
brew services start redis# Install Redis
sudo apt-get update
sudo apt-get install redis-server
# Start Redis service
sudo systemctl start redis
sudo systemctl enable redis# Download and compile Redis
wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make
sudo make install# Start with full background task support
./start_basicchat.sh# Use Docker Compose for production
docker-compose up --build# Start without background tasks
streamlit run app.py-
Edit
com.basicchat.startup.plist:# Replace YOUR_USERNAME with your actual username sed -i '' 's/YOUR_USERNAME/'$USER'/g' com.basicchat.startup.plist
-
Install the LaunchAgent:
cp com.basicchat.startup.plist ~/Library/LaunchAgents/ launchctl load ~/Library/LaunchAgents/com.basicchat.startup.plist
-
Start the service:
launchctl start com.basicchat.startup
-
Edit
basicchat.service:# Replace paths and username sed -i 's|YOUR_USERNAME|'$USER'|g' basicchat.service sed -i 's|/path/to/basic-chat-template|'$(pwd)'|g' basicchat.service
-
Install the service:
sudo cp basicchat.service /etc/systemd/system/ sudo systemctl daemon-reload sudo systemctl enable basicchat.service -
Start the service:
sudo systemctl start basicchat.service
Create basicchat.env for custom configuration:
# Copy the template
cp basicchat.env.example basicchat.env
# Edit configuration
nano basicchat.envDefault ports (can be changed in basicchat.env):
- Streamlit App: 8501
- Redis: 6379
- Flower Monitor: 5555
- Ollama: 11434
# Check if services are running
./start_basicchat.sh --status
# View logs
tail -f basicchat.log
tail -f basicchat_error.log- Main App: http://localhost:8501
- Task Monitor: http://localhost:5555
- Redis CLI:
redis-cli
# Check if Redis is running
redis-cli ping
# Start Redis manually
redis-server --port 6379 --daemonize yes# Check what's using the port
lsof -i :8501
# Kill the process
kill -9 <PID># Make scripts executable
chmod +x *.sh
# Check file permissions
ls -la *.sh- Application Log:
app.log - Startup Log:
basicchat.log - Error Log:
basicchat_error.log - Redis Log: Check system logs or
redis_data/redis.log
# Create custom Redis config
cat > redis.conf << EOF
port 6379
dir ./redis_data
appendonly yes
maxmemory 256mb
maxmemory-policy allkeys-lru
EOF
# Start with custom config
redis-server redis.conf# Start multiple BasicChat instances on different ports
REDIS_PORT=6380 STREAMLIT_PORT=8502 ./start_basicchat.sh- Enable persistence with
appendonly yes - Set appropriate
maxmemorylimits - Use
maxmemory-policy allkeys-lrufor caching - Monitor memory usage with
redis-cli info memory
- Adjust worker concurrency based on CPU cores
- Use separate queues for different task types
- Monitor task queue length in Flower
- Set appropriate task timeouts
When everything is working correctly, you should see:
- ✅ All services started successfully
- ✅ Redis responding on port 6379
- ✅ Streamlit app accessible at http://localhost:8501
- ✅ Flower monitoring at http://localhost:5555
- ✅ Graceful shutdown on Ctrl+C
If you encounter issues:
- Check the log files for error messages
- Verify all dependencies are installed
- Ensure ports are not in use by other applications
- Check system resources (CPU, memory, disk space)