fix config reload/override config args, no path updates
This commit is contained in:
parent
c58fc6fdd5
commit
41e531f963
@ -41,7 +41,7 @@ use tokio::fs;
|
|||||||
use crate::db::models::Role;
|
use crate::db::models::Role;
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
channels::{create_channel, delete_channel},
|
channels::{create_channel, delete_channel},
|
||||||
config::{PlayoutConfig, Template},
|
config::{get_config, PlayoutConfig, Template},
|
||||||
control::{control_state, send_message, ControlParams, Process, ProcessCtl},
|
control::{control_state, send_message, ControlParams, Process, ProcessCtl},
|
||||||
errors::ServiceError,
|
errors::ServiceError,
|
||||||
files::{
|
files::{
|
||||||
@ -597,7 +597,7 @@ async fn update_advanced_config(
|
|||||||
let manager = controllers.lock().unwrap().get(*id).unwrap();
|
let manager = controllers.lock().unwrap().get(*id).unwrap();
|
||||||
|
|
||||||
handles::update_advanced_configuration(&pool, *id, data.clone()).await?;
|
handles::update_advanced_configuration(&pool, *id, data.clone()).await?;
|
||||||
let new_config = PlayoutConfig::new(&pool, *id).await;
|
let new_config = get_config(&pool, *id).await?;
|
||||||
|
|
||||||
manager.update_config(new_config);
|
manager.update_config(new_config);
|
||||||
|
|
||||||
@ -653,7 +653,7 @@ async fn update_playout_config(
|
|||||||
let config_id = manager.config.lock().unwrap().general.id;
|
let config_id = manager.config.lock().unwrap().general.id;
|
||||||
|
|
||||||
handles::update_configuration(&pool, config_id, data.clone()).await?;
|
handles::update_configuration(&pool, config_id, data.clone()).await?;
|
||||||
let new_config = PlayoutConfig::new(&pool, *id).await;
|
let new_config = get_config(&pool, *id).await?;
|
||||||
|
|
||||||
manager.update_config(new_config);
|
manager.update_config(new_config);
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ use argon2::{
|
|||||||
Argon2, PasswordHasher,
|
Argon2, PasswordHasher,
|
||||||
};
|
};
|
||||||
|
|
||||||
use log::*;
|
|
||||||
use rand::{distributions::Alphanumeric, Rng};
|
use rand::{distributions::Alphanumeric, Rng};
|
||||||
use sqlx::{sqlite::SqliteQueryResult, Pool, Row, Sqlite};
|
use sqlx::{sqlite::SqliteQueryResult, Pool, Row, Sqlite};
|
||||||
use tokio::task;
|
use tokio::task;
|
||||||
@ -13,9 +12,8 @@ use crate::db::models::{Channel, GlobalSettings, Role, TextPreset, User};
|
|||||||
use crate::utils::{advanced_config::AdvancedConfig, config::PlayoutConfig, local_utc_offset};
|
use crate::utils::{advanced_config::AdvancedConfig, config::PlayoutConfig, local_utc_offset};
|
||||||
|
|
||||||
pub async fn db_migrate(conn: &Pool<Sqlite>) -> Result<&'static str, Box<dyn std::error::Error>> {
|
pub async fn db_migrate(conn: &Pool<Sqlite>) -> Result<&'static str, Box<dyn std::error::Error>> {
|
||||||
match sqlx::migrate!("../migrations").run(conn).await {
|
if let Err(e) = sqlx::migrate!("../migrations").run(conn).await {
|
||||||
Ok(_) => info!("Database migration successfully"),
|
panic!("{e}");
|
||||||
Err(e) => panic!("{e}"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if select_global(conn).await.is_err() {
|
if select_global(conn).await.is_err() {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::io::{stdin, stdout, Write};
|
||||||
|
|
||||||
use sqlx::{migrate::MigrateDatabase, Pool, Sqlite, SqlitePool};
|
use sqlx::{migrate::MigrateDatabase, Pool, Sqlite, SqlitePool};
|
||||||
|
|
||||||
pub mod handles;
|
pub mod handles;
|
||||||
@ -16,3 +18,23 @@ pub async fn db_pool() -> Result<Pool<Sqlite>, sqlx::Error> {
|
|||||||
|
|
||||||
Ok(conn)
|
Ok(conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn db_drop() {
|
||||||
|
let mut drop_answer = String::new();
|
||||||
|
|
||||||
|
print!("Drop Database [Y/n]: ");
|
||||||
|
stdout().flush().unwrap();
|
||||||
|
|
||||||
|
stdin()
|
||||||
|
.read_line(&mut drop_answer)
|
||||||
|
.expect("Did not enter a yes or no?");
|
||||||
|
|
||||||
|
let drop = drop_answer.trim().to_lowercase().starts_with('y');
|
||||||
|
|
||||||
|
if drop {
|
||||||
|
match Sqlite::drop_database(db_path().unwrap()).await {
|
||||||
|
Ok(_) => println!("Successfully dropped DB"),
|
||||||
|
Err(e) => eprintln!("{e}"),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@ -2,7 +2,7 @@ use std::{
|
|||||||
collections::HashSet,
|
collections::HashSet,
|
||||||
env,
|
env,
|
||||||
fs::File,
|
fs::File,
|
||||||
io::{self, stdin, stdout, Write},
|
io,
|
||||||
process::exit,
|
process::exit,
|
||||||
sync::{atomic::AtomicBool, Arc, Mutex},
|
sync::{atomic::AtomicBool, Arc, Mutex},
|
||||||
thread,
|
thread,
|
||||||
@ -14,7 +14,6 @@ use actix_web::{
|
|||||||
};
|
};
|
||||||
use actix_web_grants::authorities::AttachAuthorities;
|
use actix_web_grants::authorities::AttachAuthorities;
|
||||||
use actix_web_httpauth::{extractors::bearer::BearerAuth, middleware::HttpAuthentication};
|
use actix_web_httpauth::{extractors::bearer::BearerAuth, middleware::HttpAuthentication};
|
||||||
use sqlx::{migrate::MigrateDatabase, Sqlite};
|
|
||||||
|
|
||||||
#[cfg(all(not(debug_assertions), feature = "embed_frontend"))]
|
#[cfg(all(not(debug_assertions), feature = "embed_frontend"))]
|
||||||
use actix_web_static_files::ResourceFiles;
|
use actix_web_static_files::ResourceFiles;
|
||||||
@ -25,7 +24,7 @@ use path_clean::PathClean;
|
|||||||
use ffplayout::{
|
use ffplayout::{
|
||||||
api::{auth, routes::*},
|
api::{auth, routes::*},
|
||||||
db::{
|
db::{
|
||||||
db_pool, handles,
|
db_drop, db_pool, handles,
|
||||||
models::{init_globales, UserMeta},
|
models::{init_globales, UserMeta},
|
||||||
},
|
},
|
||||||
player::{
|
player::{
|
||||||
@ -36,7 +35,6 @@ use ffplayout::{
|
|||||||
utils::{
|
utils::{
|
||||||
args_parse::run_args,
|
args_parse::run_args,
|
||||||
config::get_config,
|
config::get_config,
|
||||||
db_path,
|
|
||||||
logging::{init_logging, MailQueue},
|
logging::{init_logging, MailQueue},
|
||||||
playlist::generate_playlist,
|
playlist::generate_playlist,
|
||||||
},
|
},
|
||||||
@ -292,23 +290,7 @@ async fn main() -> std::io::Result<()> {
|
|||||||
Arc::new(AtomicBool::new(false)),
|
Arc::new(AtomicBool::new(false)),
|
||||||
);
|
);
|
||||||
} else if ARGS.drop_db {
|
} else if ARGS.drop_db {
|
||||||
let mut drop_answer = String::new();
|
db_drop().await;
|
||||||
|
|
||||||
print!("Drop Database [Y/n]: ");
|
|
||||||
stdout().flush().unwrap();
|
|
||||||
|
|
||||||
stdin()
|
|
||||||
.read_line(&mut drop_answer)
|
|
||||||
.expect("Did not enter a yes or no?");
|
|
||||||
|
|
||||||
let drop = drop_answer.trim().to_lowercase().starts_with('y');
|
|
||||||
|
|
||||||
if drop {
|
|
||||||
match Sqlite::drop_database(db_path().unwrap()).await {
|
|
||||||
Ok(_) => info!("Successfully dropped DB"),
|
|
||||||
Err(e) => error!("{e}"),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} else if !ARGS.init {
|
} else if !ARGS.init {
|
||||||
error!("Run ffplayout with parameters! Run ffplayout -h for more information.");
|
error!("Run ffplayout with parameters! Run ffplayout -h for more information.");
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ use sqlx::{Pool, Sqlite};
|
|||||||
use super::logging::MailQueue;
|
use super::logging::MailQueue;
|
||||||
use crate::db::{handles, models::Channel};
|
use crate::db::{handles, models::Channel};
|
||||||
use crate::player::controller::{ChannelController, ChannelManager};
|
use crate::player::controller::{ChannelController, ChannelManager};
|
||||||
use crate::utils::{config::PlayoutConfig, errors::ServiceError};
|
use crate::utils::{config::get_config, errors::ServiceError};
|
||||||
|
|
||||||
async fn map_global_admins(conn: &Pool<Sqlite>) -> Result<(), ServiceError> {
|
async fn map_global_admins(conn: &Pool<Sqlite>) -> Result<(), ServiceError> {
|
||||||
let channels = handles::select_related_channels(conn, None).await?;
|
let channels = handles::select_related_channels(conn, None).await?;
|
||||||
@ -88,7 +88,7 @@ pub async fn create_channel(
|
|||||||
handles::insert_advanced_configuration(conn, channel.id).await?;
|
handles::insert_advanced_configuration(conn, channel.id).await?;
|
||||||
handles::insert_configuration(conn, channel.id, output_param).await?;
|
handles::insert_configuration(conn, channel.id, output_param).await?;
|
||||||
|
|
||||||
let config = PlayoutConfig::new(conn, channel.id).await;
|
let config = get_config(conn, channel.id).await?;
|
||||||
let m_queue = Arc::new(Mutex::new(MailQueue::new(channel.id, config.mail.clone())));
|
let m_queue = Arc::new(Mutex::new(MailQueue::new(channel.id, config.mail.clone())));
|
||||||
let manager = ChannelManager::new(Some(conn.clone()), channel.clone(), config);
|
let manager = ChannelManager::new(Some(conn.clone()), channel.clone(), config);
|
||||||
|
|
||||||
|
@ -184,12 +184,12 @@ pub struct Channel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Channel {
|
impl Channel {
|
||||||
pub fn new(config: &models::GlobalSettings) -> Self {
|
pub fn new(config: &models::GlobalSettings, channel: models::Channel) -> Self {
|
||||||
Self {
|
Self {
|
||||||
logging_path: PathBuf::from(config.logging_path.clone()),
|
logging_path: PathBuf::from(config.logging_path.clone()),
|
||||||
hls_path: PathBuf::from(config.public_root.clone()),
|
hls_path: PathBuf::from(channel.hls_path.clone()),
|
||||||
playlist_path: PathBuf::from(config.playlist_root.clone()),
|
playlist_path: PathBuf::from(channel.playlist_path.clone()),
|
||||||
storage_path: PathBuf::from(config.storage_root.clone()),
|
storage_path: PathBuf::from(channel.storage_path.clone()),
|
||||||
shared_storage: config.shared_storage,
|
shared_storage: config.shared_storage,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -553,6 +553,9 @@ impl PlayoutConfig {
|
|||||||
let global = handles::select_global(pool)
|
let global = handles::select_global(pool)
|
||||||
.await
|
.await
|
||||||
.expect("Can't read globals");
|
.expect("Can't read globals");
|
||||||
|
let channel = handles::select_channel(pool, &channel_id)
|
||||||
|
.await
|
||||||
|
.expect("Can't read channel");
|
||||||
let config = handles::select_configuration(pool, channel_id)
|
let config = handles::select_configuration(pool, channel_id)
|
||||||
.await
|
.await
|
||||||
.expect("Can't read config");
|
.expect("Can't read config");
|
||||||
@ -560,7 +563,7 @@ impl PlayoutConfig {
|
|||||||
.await
|
.await
|
||||||
.expect("Can't read advanced config");
|
.expect("Can't read advanced config");
|
||||||
|
|
||||||
let mut channel = Channel::new(&global);
|
let channel = Channel::new(&global, channel);
|
||||||
let advanced = AdvancedConfig::new(adv_config);
|
let advanced = AdvancedConfig::new(adv_config);
|
||||||
let general = General::new(&config);
|
let general = General::new(&config);
|
||||||
let mail = Mail::new(&config);
|
let mail = Mail::new(&config);
|
||||||
@ -572,10 +575,6 @@ impl PlayoutConfig {
|
|||||||
let task = Task::new(&config);
|
let task = Task::new(&config);
|
||||||
let mut output = Output::new(&config);
|
let mut output = Output::new(&config);
|
||||||
|
|
||||||
if global.shared_storage {
|
|
||||||
channel.storage_path = channel.storage_path.join(channel_id.to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
if !channel.storage_path.is_dir() {
|
if !channel.storage_path.is_dir() {
|
||||||
tokio::fs::create_dir_all(&channel.storage_path)
|
tokio::fs::create_dir_all(&channel.storage_path)
|
||||||
.await
|
.await
|
||||||
@ -586,11 +585,6 @@ impl PlayoutConfig {
|
|||||||
|
|
||||||
let mut storage = Storage::new(&config, channel.storage_path.clone());
|
let mut storage = Storage::new(&config, channel.storage_path.clone());
|
||||||
|
|
||||||
if channel_id > 1 || !global.shared_storage {
|
|
||||||
channel.playlist_path = channel.playlist_path.join(channel_id.to_string());
|
|
||||||
channel.hls_path = channel.hls_path.join(channel_id.to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
if !channel.playlist_path.is_dir() {
|
if !channel.playlist_path.is_dir() {
|
||||||
tokio::fs::create_dir_all(&channel.playlist_path)
|
tokio::fs::create_dir_all(&channel.playlist_path)
|
||||||
.await
|
.await
|
||||||
|
Loading…
Reference in New Issue
Block a user