Make paths configurable via environment variables
- Replace hardcoded paths with INPUT_DIR and OUTPUT_DIR env vars - Add sensible generic defaults if env vars not set - Update service example with all environment variables - Document environment variables in README - Makes codebase more portable and configuration-driven
This commit is contained in:
parent
6bf2eb38aa
commit
a7206fa325
|
@ -53,9 +53,9 @@ cp deploy.sh.example deploy.sh
|
||||||
|
|
||||||
### Environment Variables
|
### Environment Variables
|
||||||
|
|
||||||
|
- `INPUT_DIR`: Directory to monitor for new MP4 files (default: `/home/user/livestreams`)
|
||||||
|
- `OUTPUT_DIR`: Local output directory for processed files (default: `/media/archive/livestreams`)
|
||||||
- `PC_SYNC_TARGET`: Remote sync destination (e.g., `user@server:/path/to/destination/`)
|
- `PC_SYNC_TARGET`: Remote sync destination (e.g., `user@server:/path/to/destination/`)
|
||||||
- `INPUT_DIR`: Directory to monitor for new files
|
|
||||||
- `OUTPUT_DIR`: Local output directory for processed files
|
|
||||||
|
|
||||||
### Service Configuration
|
### Service Configuration
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,9 @@ User=<service-user>
|
||||||
Group=<service-group>
|
Group=<service-group>
|
||||||
WorkingDirectory=/path/to/livestream-archiver
|
WorkingDirectory=/path/to/livestream-archiver
|
||||||
ExecStart=/path/to/livestream-archiver/target/release/livestream_archiver
|
ExecStart=/path/to/livestream-archiver/target/release/livestream_archiver
|
||||||
Environment=PC_SYNC_TARGET=user@server:/path/to/destination/
|
Environment="PC_SYNC_TARGET=user@server:/path/to/destination/"
|
||||||
|
Environment="INPUT_DIR=/path/to/input/livestreams"
|
||||||
|
Environment="OUTPUT_DIR=/path/to/output/archive"
|
||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=10
|
RestartSec=10
|
||||||
|
|
||||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -1,4 +1,5 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::env;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use notify::{Watcher, RecursiveMode, Event, EventKind};
|
use notify::{Watcher, RecursiveMode, Event, EventKind};
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
@ -10,8 +11,18 @@ use services::livestream_archiver::LivestreamArchiver;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
let watch_path = PathBuf::from("/home/rockvilleav/Sync/Livestreams");
|
let watch_path = PathBuf::from(
|
||||||
let output_path = PathBuf::from("/media/archive/jellyfin/livestreams");
|
env::var("INPUT_DIR").unwrap_or_else(|_| {
|
||||||
|
eprintln!("INPUT_DIR not set, using default: /home/user/livestreams");
|
||||||
|
"/home/user/livestreams".to_string()
|
||||||
|
})
|
||||||
|
);
|
||||||
|
let output_path = PathBuf::from(
|
||||||
|
env::var("OUTPUT_DIR").unwrap_or_else(|_| {
|
||||||
|
eprintln!("OUTPUT_DIR not set, using default: /media/archive/livestreams");
|
||||||
|
"/media/archive/livestreams".to_string()
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
// Ensure directories exist
|
// Ensure directories exist
|
||||||
if !watch_path.exists() {
|
if !watch_path.exists() {
|
||||||
|
|
Loading…
Reference in a new issue