Skip to content

Commit aaeb063

Browse files
docs: add automatic hub updates section to Docker installation guide
- Add comprehensive cron job setup for Docker run and Docker Compose deployments - Include scripts that handle hub updates and container restarts - Use modern Docker Compose V2 syntax (docker compose instead of docker-compose) - Add full binary paths to handle cron environment limitations - Provide unified script naming for easier user experience - Include setup instructions and troubleshooting tips
1 parent 01a2da1 commit aaeb063

File tree

1 file changed

+97
-0
lines changed
  • crowdsec-docs/unversioned/getting_started/installation

1 file changed

+97
-0
lines changed

crowdsec-docs/unversioned/getting_started/installation/docker.mdx

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,103 @@ Here are the most common environment variables for customizing CrowdSec in Docke
129129
Use a `.env` file or Docker secrets to avoid hardcoding sensitive variables like passwords or API keys.
130130
:::
131131

132+
## Automatic Hub Updates
133+
134+
To keep your CrowdSec installation up to date with the latest parsers, scenarios, and collections from the hub, you can set up an automated cron job that will check for updates and restart the container when needed.
135+
136+
### Docker Run Setup
137+
138+
For containers started with `docker run`, create this script:
139+
140+
```bash
141+
#!/bin/bash
142+
# /usr/local/bin/crowdsec-update.sh
143+
144+
CONTAINER_NAME="crowdsec" # Adjust to your container name
145+
DOCKER_BIN="/usr/bin/docker" # Adjust path if needed
146+
147+
# Check if container is running
148+
if ! $DOCKER_BIN ps --format "table {{.Names}}" | grep -q "^${CONTAINER_NAME}$"; then
149+
echo "Container ${CONTAINER_NAME} is not running"
150+
exit 1
151+
fi
152+
153+
# Update and check for upgrades
154+
$DOCKER_BIN exec ${CONTAINER_NAME} cscli --error hub update >/dev/null
155+
upgraded="$($DOCKER_BIN exec ${CONTAINER_NAME} cscli --error hub upgrade)"
156+
157+
if [ -n "$upgraded" ]; then
158+
echo "Hub updates detected, restarting container..."
159+
$DOCKER_BIN restart ${CONTAINER_NAME}
160+
echo "Container restarted successfully"
161+
else
162+
echo "No hub updates available"
163+
fi
164+
```
165+
166+
### Docker Compose Setup
167+
168+
For Docker Compose deployments, use this script instead:
169+
170+
```bash
171+
#!/bin/bash
172+
# /usr/local/bin/crowdsec-update.sh
173+
174+
cd /path/to/your/docker-compose/directory # Adjust path
175+
DOCKER_BIN="/usr/bin/docker" # Adjust path if needed
176+
177+
# Check if service is running
178+
if ! $DOCKER_BIN compose ps crowdsec | grep -q "Up"; then
179+
echo "CrowdSec service is not running"
180+
exit 1
181+
fi
182+
183+
# Update and check for upgrades
184+
$DOCKER_BIN compose exec crowdsec cscli --error hub update >/dev/null
185+
upgraded="$($DOCKER_BIN compose exec crowdsec cscli --error hub upgrade)"
186+
187+
if [ -n "$upgraded" ]; then
188+
echo "Hub updates detected, restarting service..."
189+
$DOCKER_BIN compose restart crowdsec
190+
echo "Service restarted successfully"
191+
else
192+
echo "No hub updates available"
193+
fi
194+
```
195+
196+
### Setup Instructions
197+
198+
1. **Choose the appropriate script** based on your deployment method
199+
2. **Make it executable:**
200+
```bash
201+
sudo chmod +x /usr/local/bin/crowdsec-update.sh
202+
```
203+
3. **Add to crontab** (daily at 2 AM):
204+
```bash
205+
sudo crontab -e
206+
# Add: 0 2 * * * /usr/local/bin/crowdsec-update.sh
207+
```
208+
209+
:::tip
210+
**Docker Compose is recommended** as it doesn't require knowing the exact container name and works with the service name from your `docker-compose.yml`.
211+
212+
**Finding Docker binary path:**
213+
```bash
214+
# Find docker binary (includes compose subcommand)
215+
which docker
216+
# Common paths: /usr/bin/docker, /usr/local/bin/docker
217+
```
218+
219+
**Cron schedule examples:**
220+
- `0 */6 * * *` - Every 6 hours
221+
- `0 2 * * 0` - Every Sunday at 2 AM
222+
- `0 2 1 * *` - First day of every month at 2 AM
223+
:::
224+
225+
:::warning
226+
Test your script manually before setting up the cron job to ensure it works with your specific setup.
227+
:::
228+
132229
---
133230

134231
## Next Steps?

0 commit comments

Comments
 (0)