Skip to content

Commit

Permalink
Create directories in tmpfs
Browse files Browse the repository at this point in the history
  • Loading branch information
sdunesme committed Apr 26, 2022
1 parent d512ae7 commit 259e459
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
25 changes: 20 additions & 5 deletions docker-compose.yml → docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ version: "3.9"
services:
db:
image: postgis/postgis:13-3.2-alpine
container_name: woodcamrm_db
restart: always
environment:
TZ: $SCHEDULER_TIMEZONE
POSTGRES_DB: $POSTGRES_DB
POSTGRES_USER: $POSTGRES_USER
POSTGRES_PASSWORD: $POSTGRES_PASSWORD
Expand All @@ -16,18 +18,26 @@ services:
- db-data:/var/lib/postgresql/data

redis:
image: redis:6.2.6-alpine
image: redis:7.0-rc2-alpine
container_name: woodcamrm_redis
restart: always
ports:
- '6379:6379'
environment:
TZ: $SCHEDULER_TIMEZONE
REDIS_PASSWORD: $REDIS_PASSWORD
# volumes:
# - redis-data:/data
command: redis-server --save 20 1 --loglevel warning --stop-writes-on-bgsave-error no --requirepass ${REDIS_PASSWORD}

mqtt:
build:
context: ./mosquitto
args:
mqtt_username: ${MQTT_USERNAME}
mqtt_password: ${MQTT_PASSWORD}
container_name: woodcamrm_mqtt
restart: always
environment:
TZ: $SCHEDULER_TIMEZONE
ports:
- '1883:1883'
- '8883:8883'
Expand All @@ -36,8 +46,10 @@ services:

ftp:
image: delfer/alpine-ftp-server
container_name: woodcamrm_ftp
restart: always
environment:
TZ: $SCHEDULER_TIMEZONE
USERS: ${FTP_USER}|${FTP_PASSWORD}|/data
ADDRESS: ${APP_URL}
ports:
Expand All @@ -48,6 +60,7 @@ services:

app:
build: .
container_name: woodcamrm_app
restart: always
depends_on:
db:
Expand All @@ -58,10 +71,11 @@ services:
TZ: $SCHEDULER_TIMEZONE
volumes:
- ${PWD}/.env:/app/.env
- video-data:/app/ramdisks/ain-chazey
- video-data:/data

worker:
image: woodcam-rm_app:latest
container_name: woodcamrm_worker
restart: always
command: celery -A woodcamrm.celery worker --loglevel=info
depends_on:
Expand All @@ -71,11 +85,12 @@ services:
TZ: $SCHEDULER_TIMEZONE
volumes:
- ${PWD}/.env:/app/.env
- video-data:/app/ramdisks/ain-chazey
- video-data:/data

volumes:
db-data:
mqtt-data:
redis-data:
video-data:
driver_opts:
type: tmpfs
Expand Down
4 changes: 4 additions & 0 deletions woodcamrm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ def save_video_file(filepath, rtsp_url, station_id):
return 0

r.set(f"station_{station_id}:record_task:status", "started")

if not os.path.isdir(filepath):
os.mkdir(filepath)

cap = cv2.VideoCapture(rtsp_url)

# Get current width of frame
Expand Down
5 changes: 4 additions & 1 deletion woodcamrm/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ def records_check():
stations = Stations.query.filter(Stations.storage_path != None).filter().all()

for st in stations:
if not os.path.isdir(st.storage_path):
os.mkdir(st.storage_path)

last_record = r.get(f"station_{st.id}:last_record")
record_status = r.get(f"station_{st.id}:record_task:status")
record_task = r.get(f"station_{st.id}:record_task:id")
Expand Down Expand Up @@ -348,7 +351,7 @@ def records_check():

# TODO: Merge RAM videos in definitive video befor deleting

# Delete RAM files older than 10min
# Delete RAM files older than 10min
for f in os.listdir(st.storage_path):
fpath = os.path.join(st.storage_path, f)
if time.time() - os.stat(fpath).st_mtime > (10 * 60):
Expand Down

0 comments on commit 259e459

Please sign in to comment.