move worker_task.rs into proxmox-rest-server crate

Also moved pbs-datastore/src/task.rs to pbs-tools, which now depends on 'log'.
This commit is contained in:
Dietmar Maurer 2021-09-23 10:09:19 +02:00
parent 81867f0539
commit b9700a9fe5
46 changed files with 176 additions and 183 deletions

View File

@ -9,10 +9,9 @@ use proxmox::tools::fs::{CreateOptions, create_path, create_dir};
use pbs_api_types::GarbageCollectionStatus;
use pbs_tools::process_locker::{self, ProcessLocker};
use pbs_tools::{task_log, task::TaskState};
use crate::DataBlob;
use crate::task_log;
use crate::task::TaskState;
/// File system based chunk store
pub struct ChunkStore {
@ -306,7 +305,7 @@ impl ChunkStore {
for (entry, percentage, bad) in self.get_chunk_iterator()? {
if last_percentage != percentage {
last_percentage = percentage;
crate::task_log!(
task_log!(
worker,
"processed {}% ({} chunks)",
percentage,

View File

@ -179,7 +179,6 @@ pub mod paperkey;
pub mod prune;
pub mod read_chunk;
pub mod store_progress;
pub mod task;
pub mod dynamic_index;
pub mod fixed_index;

View File

@ -17,6 +17,7 @@ foreign-types = "0.3"
futures = "0.3"
lazy_static = "1.4"
libc = "0.2"
log = "0.4"
nix = "0.19.1"
nom = "5.1"
openssl = "0.10"

View File

@ -24,6 +24,7 @@ pub mod str;
pub mod stream;
pub mod sync;
pub mod sys;
pub mod task;
pub mod ticket;
pub mod tokio;
pub mod xattr;

View File

@ -15,6 +15,7 @@ lazy_static = "1.4"
libc = "0.2"
log = "0.4"
nix = "0.19.1"
once_cell = "1.3.1"
percent-encoding = "2.1"
regex = "1.2"
serde = { version = "1.0", features = [] }

View File

@ -1,9 +1,12 @@
use std::os::unix::io::RawFd;
use anyhow::{bail, format_err, Error};
use nix::unistd::Pid;
use proxmox::tools::fd::Fd;
use proxmox::sys::linux::procfs::PidStat;
use proxmox::api::UserInformation;
use proxmox::tools::fs::CreateOptions;
mod compression;
pub use compression::*;
@ -29,6 +32,9 @@ pub use api_config::ApiConfig;
mod rest;
pub use rest::{RestServer, handle_api_request};
mod worker_task;
pub use worker_task::*;
pub enum AuthError {
Generic(Error),
NoData,
@ -48,6 +54,40 @@ pub trait ApiAuth {
) -> Result<(String, Box<dyn UserInformation + Sync + Send>), AuthError>;
}
lazy_static::lazy_static!{
static ref PID: i32 = unsafe { libc::getpid() };
static ref PSTART: u64 = PidStat::read_from_pid(Pid::from_raw(*PID)).unwrap().starttime;
}
pub fn pid() -> i32 {
*PID
}
pub fn pstart() -> u64 {
*PSTART
}
pub fn write_pid(pid_fn: &str) -> Result<(), Error> {
let pid_str = format!("{}\n", *PID);
proxmox::tools::fs::replace_file(pid_fn, pid_str.as_bytes(), CreateOptions::new())
}
pub fn read_pid(pid_fn: &str) -> Result<i32, Error> {
let pid = proxmox::tools::fs::file_get_contents(pid_fn)?;
let pid = std::str::from_utf8(&pid)?.trim();
pid.parse().map_err(|err| format_err!("could not parse pid - {}", err))
}
pub fn ctrl_sock_from_pid(pid: i32) -> String {
// Note: The control socket always uses @/run/proxmox-backup/ as prefix
// for historc reason.
format!("\0{}/control-{}.sock", "/run/proxmox-backup", pid)
}
pub fn our_ctrl_sock() -> String {
ctrl_sock_from_pid(*PID)
}
static mut SHUTDOWN_REQUESTED: bool = false;
pub fn request_shutdown() {

View File

@ -21,7 +21,8 @@ use proxmox::tools::fs::{create_path, replace_file, atomic_open_or_create_file,
use proxmox::api::upid::UPID;
use pbs_tools::logrotate::{LogRotate, LogRotateFiles};
use proxmox_rest_server::{CommandoSocket, FileLogger, FileLogOptions};
use crate::{CommandoSocket, FileLogger, FileLogOptions};
struct TaskListLockGuard(File);
@ -280,7 +281,7 @@ lazy_static! {
/// checks if the task UPID refers to a worker from this process
fn is_local_worker(upid: &UPID) -> bool {
upid.pid == crate::server::pid() && upid.pstart == crate::server::pstart()
upid.pid == crate::pid() && upid.pstart == crate::pstart()
}
/// Test if the task is still running
@ -293,14 +294,14 @@ pub async fn worker_is_active(upid: &UPID) -> Result<bool, Error> {
return Ok(false);
}
let sock = crate::server::ctrl_sock_from_pid(upid.pid);
let sock = crate::ctrl_sock_from_pid(upid.pid);
let cmd = json!({
"command": "worker-task-status",
"args": {
"upid": upid.to_string(),
},
});
let status = proxmox_rest_server::send_command(sock, &cmd).await?;
let status = crate::send_command(sock, &cmd).await?;
if let Some(active) = status.as_bool() {
Ok(active)
@ -366,14 +367,14 @@ pub fn abort_worker_async(upid: UPID) {
pub async fn abort_worker(upid: UPID) -> Result<(), Error> {
let sock = crate::server::ctrl_sock_from_pid(upid.pid);
let sock = crate::ctrl_sock_from_pid(upid.pid);
let cmd = json!({
"command": "worker-task-abort",
"args": {
"upid": upid.to_string(),
},
});
proxmox_rest_server::send_command(sock, &cmd).map_ok(|_| ()).await
crate::send_command(sock, &cmd).map_ok(|_| ()).await
}
fn parse_worker_status_line(line: &str) -> Result<(String, UPID, Option<TaskState>), Error> {
@ -476,27 +477,6 @@ pub struct TaskListInfo {
pub state: Option<TaskState>, // endtime, status
}
impl Into<pbs_api_types::TaskListItem> for TaskListInfo {
fn into(self) -> pbs_api_types::TaskListItem {
let (endtime, status) = self
.state
.map_or_else(|| (None, None), |a| (Some(a.endtime()), Some(a.to_string())));
pbs_api_types::TaskListItem {
upid: self.upid_str,
node: "localhost".to_string(),
pid: self.upid.pid as i64,
pstart: self.upid.pstart,
starttime: self.upid.starttime,
worker_type: self.upid.worker_type,
worker_id: self.upid.worker_id,
user: self.upid.auth_id,
endtime,
status,
}
}
}
fn render_task_line(info: &TaskListInfo) -> String {
let mut raw = String::new();
if let Some(status) = &info.state {
@ -715,7 +695,7 @@ impl WorkerTask {
{
let mut hash = WORKER_TASK_LIST.lock().unwrap();
hash.insert(task_id, worker.clone());
proxmox_rest_server::set_worker_count(hash.len());
crate::set_worker_count(hash.len());
}
setup.update_active_workers(Some(&upid))?;
@ -802,7 +782,7 @@ impl WorkerTask {
WORKER_TASK_LIST.lock().unwrap().remove(&self.upid.task_id);
let _ = self.setup.update_active_workers(None);
proxmox_rest_server::set_worker_count(WORKER_TASK_LIST.lock().unwrap().len());
crate::set_worker_count(WORKER_TASK_LIST.lock().unwrap().len());
}
/// Log a message.
@ -879,7 +859,7 @@ impl WorkerTask {
}
}
impl pbs_datastore::task::TaskState for WorkerTask {
impl pbs_tools::task::TaskState for WorkerTask {
fn check_abort(&self) -> Result<(), Error> {
self.fail_on_abort()
}

View File

@ -13,7 +13,7 @@ use proxmox_acme_rs::{Authorization, Challenge};
use crate::acme::AcmeClient;
use crate::api2::types::AcmeDomain;
use crate::server::WorkerTask;
use proxmox_rest_server::WorkerTask;
use crate::config::acme::plugin::{DnsPlugin, PluginData};

View File

@ -54,7 +54,7 @@ use pbs_tools::blocking::WrappedReaderStream;
use pbs_tools::stream::{AsyncReaderStream, AsyncChannelWriter};
use pbs_tools::json::{required_integer_param, required_string_param};
use pbs_config::CachedUserInfo;
use proxmox_rest_server::formatter;
use proxmox_rest_server::{WorkerTask, formatter};
use crate::api2::node::rrd::create_value_from_rrd;
use crate::backup::{
@ -62,7 +62,7 @@ use crate::backup::{
DataStore, LocalChunkReader,
};
use crate::server::{jobstate::Job, WorkerTask};
use crate::server::jobstate::Job;
const GROUP_NOTES_FILE_NAME: &str = "notes";

View File

@ -15,10 +15,10 @@ use pbs_datastore::backup_info::{BackupDir, BackupInfo};
use pbs_datastore::dynamic_index::DynamicIndexWriter;
use pbs_datastore::fixed_index::FixedIndexWriter;
use pbs_api_types::Authid;
use proxmox_rest_server::formatter::*;
use proxmox_rest_server::{WorkerTask, formatter::*};
use crate::backup::{verify_backup_dir_with_lock, DataStore};
use crate::server::WorkerTask;
use hyper::{Body, Response};
#[derive(Copy, Clone, Serialize)]

View File

@ -23,8 +23,9 @@ use pbs_datastore::PROXMOX_BACKUP_PROTOCOL_ID_V1;
use pbs_datastore::backup_info::{BackupDir, BackupGroup, BackupInfo};
use pbs_datastore::index::IndexFile;
use pbs_datastore::manifest::{archive_type, ArchiveType};
use proxmox_rest_server::WorkerTask;
use crate::server::{WorkerTask, H2Service};
use crate::server::H2Service;
use crate::backup::DataStore;
use pbs_config::CachedUserInfo;

View File

@ -24,7 +24,7 @@ use crate::api2::types::{AcmeAccountName, AcmeChallengeSchema, KnownAcmeDirector
use crate::config::acme::plugin::{
self, DnsPlugin, DnsPluginCore, DnsPluginCoreUpdater, PLUGIN_ID_SCHEMA,
};
use crate::server::WorkerTask;
use proxmox_rest_server::WorkerTask;
pub(crate) const ROUTER: Router = Router::new()
.get(&list_subdirs_api_method!(SUBDIRS))

View File

@ -9,7 +9,6 @@ use proxmox::api::section_config::SectionConfigData;
use proxmox::api::schema::{ApiType, parse_property_string};
use pbs_datastore::chunk_store::ChunkStore;
use pbs_datastore::task::TaskState;
use pbs_config::BackupLockGuard;
use pbs_api_types::{
Authid, DatastoreNotify,
@ -17,6 +16,7 @@ use pbs_api_types::{
PRIV_DATASTORE_ALLOCATE, PRIV_DATASTORE_AUDIT, PRIV_DATASTORE_MODIFY,
DataStoreConfig, DataStoreConfigUpdater,
};
use pbs_tools::task::TaskState;
use crate::api2::config::sync::delete_sync_job;
use crate::api2::config::verify::delete_verification_job;
@ -26,8 +26,9 @@ use crate::api2::admin::{
verify::list_verification_jobs,
};
use pbs_config::CachedUserInfo;
use proxmox_rest_server::WorkerTask;
use crate::server::{jobstate, WorkerTask};
use crate::server::jobstate;
#[api(
input: {

View File

@ -19,7 +19,7 @@ use pbs_api_types::{
};
use crate::config::node;
use crate::server::WorkerTask;
use proxmox_rest_server::WorkerTask;
use crate::tools::{
apt,
pbs_simple_http,

View File

@ -18,7 +18,7 @@ use pbs_tools::cert;
use crate::acme::AcmeClient;
use crate::api2::types::AcmeDomain;
use crate::config::node::NodeConfig;
use crate::server::WorkerTask;
use proxmox_rest_server::WorkerTask;
pub const ROUTER: Router = Router::new()
.get(&list_subdirs_api_method!(SUBDIRS))

View File

@ -17,7 +17,7 @@ use crate::tools::disks::{
};
use crate::tools::systemd::{self, types::*};
use crate::server::WorkerTask;
use proxmox_rest_server::WorkerTask;
const BASE_MOUNT_DIR: &str = "/mnt/datastore/";

View File

@ -15,7 +15,7 @@ use crate::tools::disks::{
DiskUsageInfo, DiskUsageType, DiskManage, SmartData,
get_disks, get_smart_data, get_disk_usage_info, inititialize_gpt_disk,
};
use crate::server::WorkerTask;
use proxmox_rest_server::WorkerTask;
pub mod directory;
pub mod zfs;

View File

@ -19,7 +19,7 @@ use crate::tools::disks::{
DiskUsageType,
};
use crate::server::WorkerTask;
use proxmox_rest_server::WorkerTask;
#[api(

View File

@ -24,7 +24,7 @@ use pbs_api_types::{Authid, NODE_SCHEMA, PRIV_SYS_CONSOLE};
use pbs_tools::auth::private_auth_key;
use pbs_tools::ticket::{self, Empty, Ticket};
use crate::server::WorkerTask;
use proxmox_rest_server::WorkerTask;
use crate::tools;
pub mod apt;

View File

@ -13,7 +13,7 @@ use pbs_api_types::{
};
use pbs_config::network::{self, NetworkConfig};
use crate::server::{WorkerTask};
use proxmox_rest_server::WorkerTask;
fn split_interface_list(list: &str) -> Result<Vec<String>, Error> {
let value = parse_property_string(&list, &NETWORK_INTERFACE_ARRAY_SCHEMA)?;

View File

@ -9,7 +9,7 @@ use proxmox::api::router::SubdirMap;
use pbs_api_types::{Authid, NODE_SCHEMA, SERVICE_ID_SCHEMA, PRIV_SYS_AUDIT, PRIV_SYS_MODIFY};
use crate::server::WorkerTask;
use proxmox_rest_server::WorkerTask;
static SERVICE_NAME_LIST: [&str; 7] = [
"proxmox-backup",

View File

@ -16,7 +16,8 @@ use pbs_api_types::{
};
use crate::api2::pull::check_pull_privs;
use crate::server::{self, upid_log_path, upid_read_status, TaskState, TaskListInfoIterator};
use proxmox_rest_server::{upid_log_path, upid_read_status, TaskState, TaskListInfoIterator};
use pbs_config::CachedUserInfo;
// matches respective job execution privileges
@ -125,6 +126,25 @@ pub fn tasktype(state: &TaskState) -> TaskStateType {
}
}
fn into_task_list_item(info: proxmox_rest_server::TaskListInfo) -> pbs_api_types::TaskListItem {
let (endtime, status) = info
.state
.map_or_else(|| (None, None), |a| (Some(a.endtime()), Some(a.to_string())));
pbs_api_types::TaskListItem {
upid: info.upid_str,
node: "localhost".to_string(),
pid: info.upid.pid as i64,
pstart: info.upid.pstart,
starttime: info.upid.starttime,
worker_type: info.upid.worker_type,
worker_id: info.upid.worker_id,
user: info.upid.auth_id,
endtime,
status,
}
}
#[api(
input: {
properties: {
@ -217,7 +237,7 @@ async fn get_task_status(
result["tokenid"] = Value::from(task_auth_id.tokenname().unwrap().as_str());
}
if crate::server::worker_is_active(&upid).await? {
if proxmox_rest_server::worker_is_active(&upid).await? {
result["status"] = Value::from("running");
} else {
let exitstatus = upid_read_status(&upid).unwrap_or(TaskState::Unknown { endtime: 0 });
@ -314,7 +334,7 @@ async fn read_task_log(
rpcenv["total"] = Value::from(count);
if test_status {
let active = crate::server::worker_is_active(&upid).await?;
let active = proxmox_rest_server::worker_is_active(&upid).await?;
rpcenv["active"] = Value::from(active);
}
@ -354,7 +374,7 @@ fn stop_task(
user_info.check_privs(&auth_id, &["system", "tasks"], PRIV_SYS_MODIFY, false)?;
}
server::abort_worker_async(upid);
proxmox_rest_server::abort_worker_async(upid);
Ok(Value::Null)
}
@ -502,7 +522,7 @@ pub fn list_tasks(
match (&info.state, &statusfilter) {
(Some(_), _) if running => continue,
(Some(crate::server::TaskState::OK { .. }), _) if errors => continue,
(Some(TaskState::OK { .. }), _) if errors => continue,
(Some(state), Some(filters)) => {
if !filters.contains(&tasktype(state)) {
continue;
@ -517,7 +537,7 @@ pub fn list_tasks(
continue;
}
result.push(info.into());
result.push(into_task_list_item(info));
if result.len() >= limit {
break;

View File

@ -13,8 +13,9 @@ use pbs_api_types::{
DATASTORE_SCHEMA, REMOTE_ID_SCHEMA, REMOVE_VANISHED_BACKUPS_SCHEMA,
PRIV_DATASTORE_BACKUP, PRIV_DATASTORE_PRUNE, PRIV_REMOTE_READ,
};
use proxmox_rest_server::WorkerTask;
use crate::server::{WorkerTask, jobstate::Job, pull::pull_store};
use crate::server::{jobstate::Job, pull::pull_store};
use crate::backup::DataStore;
use pbs_config::CachedUserInfo;

View File

@ -10,7 +10,7 @@ use pbs_api_types::Authid;
use proxmox_rest_server::formatter::*;
use crate::backup::DataStore;
use crate::server::WorkerTask;
use proxmox_rest_server::WorkerTask;
//use proxmox::tools;

View File

@ -39,12 +39,12 @@ use pbs_datastore::backup_info::BackupDir;
use pbs_datastore::index::IndexFile;
use pbs_datastore::manifest::{archive_type, ArchiveType};
use pbs_config::CachedUserInfo;
use proxmox_rest_server::WorkerTask;
use crate::{
api2::helpers,
backup::DataStore,
server::{
WorkerTask,
H2Service,
},
};

View File

@ -20,10 +20,11 @@ use pbs_api_types::{
UPID_SCHEMA, JOB_ID_SCHEMA, PRIV_DATASTORE_READ, PRIV_TAPE_AUDIT, PRIV_TAPE_WRITE,
};
use pbs_datastore::{task_log, task_warn, StoreProgress};
use pbs_datastore::StoreProgress;
use pbs_datastore::backup_info::{BackupDir, BackupInfo};
use pbs_datastore::task::TaskState;
use pbs_tools::{task_log, task_warn, task::TaskState};
use pbs_config::CachedUserInfo;
use proxmox_rest_server::WorkerTask;
use crate::{
server::{
@ -36,7 +37,6 @@ use crate::{
},
},
backup::{DataStore, SnapshotReader},
server::WorkerTask,
tape::{
TAPE_STATUS_DIR,
Inventory,

View File

@ -28,7 +28,6 @@ use pbs_api_types::{
LtoDriveAndMediaStatus, Lp17VolumeStatistics,
};
use pbs_datastore::task_log;
use pbs_api_types::{PRIV_TAPE_AUDIT, PRIV_TAPE_READ, PRIV_TAPE_WRITE};
use pbs_config::CachedUserInfo;
use pbs_tape::{
@ -36,13 +35,14 @@ use pbs_tape::{
sg_tape::tape_alert_flags_critical,
linux_list_drives::{lto_tape_device_list, lookup_device_identification, open_lto_tape_device},
};
use pbs_tools::task_log;
use proxmox_rest_server::WorkerTask;
use crate::{
api2::tape::restore::{
fast_catalog_restore,
restore_media,
},
server::WorkerTask,
tape::{
TAPE_STATUS_DIR,
Inventory,

View File

@ -34,26 +34,24 @@ use pbs_api_types::{
UPID_SCHEMA, TAPE_RESTORE_SNAPSHOT_SCHEMA,
PRIV_DATASTORE_BACKUP, PRIV_DATASTORE_MODIFY, PRIV_TAPE_READ,
};
use pbs_datastore::{task_log, task_warn, DataBlob};
use pbs_datastore::DataBlob;
use pbs_datastore::backup_info::BackupDir;
use pbs_datastore::dynamic_index::DynamicIndexReader;
use pbs_datastore::fixed_index::FixedIndexReader;
use pbs_datastore::index::IndexFile;
use pbs_datastore::manifest::{archive_type, ArchiveType, BackupManifest, MANIFEST_BLOB_NAME};
use pbs_datastore::task::TaskState;
use pbs_config::CachedUserInfo;
use pbs_tape::{
TapeRead, BlockReadError, MediaContentHeader,
PROXMOX_BACKUP_CONTENT_HEADER_MAGIC_1_0,
};
use pbs_tools::{task_log, task_warn, task::TaskState};
use proxmox_rest_server::WorkerTask;
use crate::{
tools::ParallelHandler,
backup::DataStore,
server::{
lookup_user_email,
WorkerTask,
},
server::lookup_user_email,
tape::{
TAPE_STATUS_DIR,
MediaId,

View File

@ -12,7 +12,6 @@ use lazy_static::lazy_static;
use proxmox::tools::fs::{replace_file, file_read_optional_string, CreateOptions};
use pbs_api_types::{UPID, DataStoreConfig, Authid, GarbageCollectionStatus};
use pbs_datastore::{task_log, task_warn};
use pbs_datastore::DataBlob;
use pbs_datastore::backup_info::{BackupGroup, BackupDir};
use pbs_datastore::chunk_store::ChunkStore;
@ -24,10 +23,10 @@ use pbs_datastore::manifest::{
ArchiveType, BackupManifest,
archive_type,
};
use pbs_datastore::task::TaskState;
use pbs_tools::format::HumanByte;
use pbs_tools::fs::{lock_dir_noblock, DirLockGuard};
use pbs_tools::process_locker::ProcessLockSharedGuard;
use pbs_tools::{task_log, task_warn, task::TaskState};
use pbs_config::{open_backup_lockfile, BackupLockGuard};
use proxmox_rest_server::fail_on_shutdown;

View File

@ -7,12 +7,12 @@ use std::time::Instant;
use anyhow::{bail, format_err, Error};
use pbs_api_types::{Authid, CryptMode, VerifyState, UPID, SnapshotVerifyState};
use pbs_datastore::{task_log, DataBlob, StoreProgress};
use pbs_datastore::{DataBlob, StoreProgress};
use pbs_datastore::backup_info::{BackupGroup, BackupDir, BackupInfo};
use pbs_datastore::index::IndexFile;
use pbs_datastore::manifest::{archive_type, ArchiveType, BackupManifest, FileInfo};
use pbs_datastore::task::TaskState;
use pbs_tools::fs::lock_dir_noblock_shared;
use pbs_tools::{task_log, task::TaskState};
use crate::{
backup::DataStore,

View File

@ -10,14 +10,9 @@ use proxmox::api::RpcEnvironmentType;
use proxmox::tools::fs::CreateOptions;
use pbs_tools::auth::private_auth_key;
use proxmox_rest_server::{ApiConfig, RestServer};
use proxmox_backup::server::{
self,
auth::default_api_auth,
};
use proxmox_rest_server::daemon;
use proxmox_rest_server::{daemon, ApiConfig, RestServer};
use proxmox_backup::server::auth::default_api_auth;
use proxmox_backup::auth_helpers::*;
use proxmox_backup::config;
@ -86,7 +81,7 @@ async fn run() -> Result<(), Error> {
)?;
let backup_user = pbs_config::backup_user()?;
let mut commando_sock = proxmox_rest_server::CommandoSocket::new(crate::server::our_ctrl_sock(), backup_user.gid);
let mut commando_sock = proxmox_rest_server::CommandoSocket::new(proxmox_rest_server::our_ctrl_sock(), backup_user.gid);
let dir_opts = CreateOptions::new().owner(backup_user.uid).group(backup_user.gid);
let file_opts = CreateOptions::new().owner(backup_user.uid).group(backup_user.gid);
@ -107,7 +102,7 @@ async fn run() -> Result<(), Error> {
let rest_server = RestServer::new(config);
proxmox_backup::server::init_worker_tasks(pbs_buildcfg::PROXMOX_BACKUP_LOG_DIR_M!().into(), file_opts.clone())?;
proxmox_rest_server::init_worker_tasks(pbs_buildcfg::PROXMOX_BACKUP_LOG_DIR_M!().into(), file_opts.clone())?;
// http server future:
let server = daemon::create_daemon(
@ -130,11 +125,11 @@ async fn run() -> Result<(), Error> {
"proxmox-backup.service",
);
server::write_pid(pbs_buildcfg::PROXMOX_BACKUP_API_PID_FN)?;
proxmox_rest_server::write_pid(pbs_buildcfg::PROXMOX_BACKUP_API_PID_FN)?;
daemon::systemd_notify(daemon::SystemdNotify::Ready)?;
let init_result: Result<(), Error> = try_block!({
server::register_task_control_commands(&mut commando_sock)?;
proxmox_rest_server::register_task_control_commands(&mut commando_sock)?;
commando_sock.spawn()?;
proxmox_rest_server::server_state_init()?;
Ok(())

View File

@ -14,9 +14,10 @@ use pbs_api_types::{
IGNORE_VERIFIED_BACKUPS_SCHEMA, VERIFICATION_OUTDATED_AFTER_SCHEMA,
};
use proxmox_rest_server::wait_for_local_worker;
use proxmox_backup::config;
use proxmox_backup::api2;
use proxmox_backup::server::wait_for_local_worker;
mod proxmox_backup_manager;
use proxmox_backup_manager::*;

View File

@ -19,18 +19,16 @@ use proxmox::api::RpcEnvironmentType;
use proxmox::sys::linux::socket::set_tcp_keepalive;
use proxmox::tools::fs::CreateOptions;
use proxmox_rest_server::{ApiConfig, RestServer};
use proxmox_rest_server::{rotate_task_log_archive, ApiConfig, RestServer, WorkerTask};
use proxmox_backup::{
backup::DataStore,
server::{
auth::default_api_auth,
WorkerTask,
jobstate::{
self,
Job,
},
rotate_task_log_archive,
},
};
@ -188,7 +186,7 @@ async fn run() -> Result<(), Error> {
config.register_template("console", "/usr/share/pve-xtermjs/index.html.hbs")?;
let backup_user = pbs_config::backup_user()?;
let mut commando_sock = proxmox_rest_server::CommandoSocket::new(crate::server::our_ctrl_sock(), backup_user.gid);
let mut commando_sock = proxmox_rest_server::CommandoSocket::new(proxmox_rest_server::our_ctrl_sock(), backup_user.gid);
let dir_opts = CreateOptions::new().owner(backup_user.uid).group(backup_user.gid);
let file_opts = CreateOptions::new().owner(backup_user.uid).group(backup_user.gid);
@ -208,7 +206,7 @@ async fn run() -> Result<(), Error> {
)?;
let rest_server = RestServer::new(config);
proxmox_backup::server::init_worker_tasks(pbs_buildcfg::PROXMOX_BACKUP_LOG_DIR_M!().into(), file_opts.clone())?;
proxmox_rest_server::init_worker_tasks(pbs_buildcfg::PROXMOX_BACKUP_LOG_DIR_M!().into(), file_opts.clone())?;
//openssl req -x509 -newkey rsa:4096 -keyout /etc/proxmox-backup/proxy.key -out /etc/proxmox-backup/proxy.pem -nodes
@ -266,11 +264,11 @@ async fn run() -> Result<(), Error> {
"proxmox-backup-proxy.service",
);
server::write_pid(pbs_buildcfg::PROXMOX_BACKUP_PROXY_PID_FN)?;
proxmox_rest_server::write_pid(pbs_buildcfg::PROXMOX_BACKUP_PROXY_PID_FN)?;
daemon::systemd_notify(daemon::SystemdNotify::Ready)?;
let init_result: Result<(), Error> = try_block!({
server::register_task_control_commands(&mut commando_sock)?;
proxmox_rest_server::register_task_control_commands(&mut commando_sock)?;
commando_sock.spawn()?;
proxmox_rest_server::server_state_init()?;
Ok(())
@ -806,11 +804,11 @@ async fn schedule_task_log_rotate() {
async fn command_reopen_access_logfiles() -> Result<(), Error> {
// only care about the most recent daemon instance for each, proxy & api, as other older ones
// should not respond to new requests anyway, but only finish their current one and then exit.
let sock = crate::server::our_ctrl_sock();
let sock = proxmox_rest_server::our_ctrl_sock();
let f1 = proxmox_rest_server::send_command(sock, "{\"command\":\"api-access-log-reopen\"}\n");
let pid = crate::server::read_pid(pbs_buildcfg::PROXMOX_BACKUP_API_PID_FN)?;
let sock = crate::server::ctrl_sock_from_pid(pid);
let pid = proxmox_rest_server::read_pid(pbs_buildcfg::PROXMOX_BACKUP_API_PID_FN)?;
let sock = proxmox_rest_server::ctrl_sock_from_pid(pid);
let f2 = proxmox_rest_server::send_command(sock, "{\"command\":\"api-access-log-reopen\"}\n");
match futures::join!(f1, f2) {
@ -824,11 +822,11 @@ async fn command_reopen_access_logfiles() -> Result<(), Error> {
async fn command_reopen_auth_logfiles() -> Result<(), Error> {
// only care about the most recent daemon instance for each, proxy & api, as other older ones
// should not respond to new requests anyway, but only finish their current one and then exit.
let sock = crate::server::our_ctrl_sock();
let sock = proxmox_rest_server::our_ctrl_sock();
let f1 = proxmox_rest_server::send_command(sock, "{\"command\":\"api-auth-log-reopen\"}\n");
let pid = crate::server::read_pid(pbs_buildcfg::PROXMOX_BACKUP_API_PID_FN)?;
let sock = crate::server::ctrl_sock_from_pid(pid);
let pid = proxmox_rest_server::read_pid(pbs_buildcfg::PROXMOX_BACKUP_API_PID_FN)?;
let sock = proxmox_rest_server::ctrl_sock_from_pid(pid);
let f2 = proxmox_rest_server::send_command(sock, "{\"command\":\"api-auth-log-reopen\"}\n");
match futures::join!(f1, f2) {

View File

@ -11,7 +11,7 @@ async fn wait_for_local_worker(upid_str: &str) -> Result<(), Error> {
let sleep_duration = core::time::Duration::new(0, 100_000_000);
loop {
if !proxmox_backup::server::worker_is_active_local(&upid) {
if !proxmox_rest_server::worker_is_active_local(&upid) {
break;
}
tokio::time::sleep(sleep_duration).await;

View File

@ -235,12 +235,12 @@ async fn handle_worker(upid_str: &str) -> Result<(), Error> {
let abort_future = async move {
while signal_stream.recv().await.is_some() {
println!("got shutdown request (SIGINT)");
proxmox_backup::server::abort_local_worker(upid.clone());
proxmox_rest_server::abort_local_worker(upid.clone());
}
Ok::<_, Error>(())
};
let result_future = proxmox_backup::server::wait_for_local_worker(upid_str);
let result_future = proxmox_rest_server::wait_for_local_worker(upid_str);
futures::select! {
result = result_future.fuse() => result?,

View File

@ -2,9 +2,9 @@ use std::sync::Arc;
use anyhow::Error;
use pbs_api_types::Authid;
use proxmox_rest_server::WorkerTask;
use crate::{
server::WorkerTask,
server::jobstate::Job,
backup::DataStore,
};

View File

@ -11,11 +11,9 @@ use hyper::{Body, Request, Response, StatusCode};
use proxmox::api::{ApiResponseFuture, HttpError, Router, RpcEnvironment};
use proxmox::http_err;
use proxmox_rest_server::normalize_uri_path;
use proxmox_rest_server::{normalize_uri_path, WorkerTask};
use proxmox_rest_server::formatter::*;
use crate::server::WorkerTask;
/// Hyper Service implementation to handle stateful H2 connections.
///
/// We use this kind of service to handle backup protocol

View File

@ -14,7 +14,7 @@
//! an example usage would be
//! ```no_run
//! # use anyhow::{bail, Error};
//! # use proxmox_backup::server::TaskState;
//! # use proxmox_rest_server::TaskState;
//! # use proxmox_backup::server::jobstate::*;
//! # fn some_code() -> TaskState { TaskState::OK { endtime: 0 } }
//! # fn code() -> Result<(), Error> {
@ -50,11 +50,7 @@ use proxmox_systemd::time::{compute_next_event, parse_calendar_event};
use pbs_config::{open_backup_lockfile, BackupLockGuard};
use pbs_api_types::{UPID, JobScheduleStatus};
use crate::server::{
TaskState,
upid_read_status,
worker_is_active_local,
};
use proxmox_rest_server::{upid_read_status, worker_is_active_local, TaskState};
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]

View File

@ -4,51 +4,13 @@
//! services. We want async IO, so this is built on top of
//! tokio/hyper.
use anyhow::{format_err, Error};
use lazy_static::lazy_static;
use nix::unistd::Pid;
use anyhow::Error;
use serde_json::Value;
use proxmox::sys::linux::procfs::PidStat;
use proxmox::tools::fs::{create_path, CreateOptions};
use pbs_buildcfg;
lazy_static! {
static ref PID: i32 = unsafe { libc::getpid() };
static ref PSTART: u64 = PidStat::read_from_pid(Pid::from_raw(*PID)).unwrap().starttime;
}
pub fn pid() -> i32 {
*PID
}
pub fn pstart() -> u64 {
*PSTART
}
pub fn write_pid(pid_fn: &str) -> Result<(), Error> {
let pid_str = format!("{}\n", *PID);
proxmox::tools::fs::replace_file(pid_fn, pid_str.as_bytes(), CreateOptions::new())
}
pub fn read_pid(pid_fn: &str) -> Result<i32, Error> {
let pid = proxmox::tools::fs::file_get_contents(pid_fn)?;
let pid = std::str::from_utf8(&pid)?.trim();
pid.parse().map_err(|err| format_err!("could not parse pid - {}", err))
}
pub fn ctrl_sock_from_pid(pid: i32) -> String {
format!("\0{}/control-{}.sock", pbs_buildcfg::PROXMOX_BACKUP_RUN_DIR, pid)
}
pub fn our_ctrl_sock() -> String {
ctrl_sock_from_pid(*PID)
}
mod worker_task;
pub use worker_task::*;
mod h2service;
pub use h2service::*;
@ -76,16 +38,16 @@ pub mod auth;
pub mod pull;
pub(crate) async fn reload_proxy_certificate() -> Result<(), Error> {
let proxy_pid = crate::server::read_pid(pbs_buildcfg::PROXMOX_BACKUP_PROXY_PID_FN)?;
let sock = crate::server::ctrl_sock_from_pid(proxy_pid);
let proxy_pid = proxmox_rest_server::read_pid(pbs_buildcfg::PROXMOX_BACKUP_PROXY_PID_FN)?;
let sock = proxmox_rest_server::ctrl_sock_from_pid(proxy_pid);
let _: Value = proxmox_rest_server::send_raw_command(sock, "{\"command\":\"reload-certificate\"}\n")
.await?;
Ok(())
}
pub(crate) async fn notify_datastore_removed() -> Result<(), Error> {
let proxy_pid = crate::server::read_pid(pbs_buildcfg::PROXMOX_BACKUP_PROXY_PID_FN)?;
let sock = crate::server::ctrl_sock_from_pid(proxy_pid);
let proxy_pid = proxmox_rest_server::read_pid(pbs_buildcfg::PROXMOX_BACKUP_PROXY_PID_FN)?;
let sock = proxmox_rest_server::ctrl_sock_from_pid(proxy_pid);
let _: Value = proxmox_rest_server::send_raw_command(sock, "{\"command\":\"datastore-removed\"}\n")
.await?;
Ok(())

View File

@ -2,16 +2,16 @@ use std::sync::Arc;
use anyhow::Error;
use pbs_datastore::{task_log, task_warn};
use pbs_datastore::backup_info::BackupInfo;
use pbs_datastore::prune::compute_prune_info;
use pbs_api_types::{Authid, PRIV_DATASTORE_MODIFY, PruneOptions};
use pbs_config::CachedUserInfo;
use pbs_tools::{task_log, task_warn};
use proxmox_rest_server::WorkerTask;
use crate::{
backup::DataStore,
server::jobstate::Job,
server::WorkerTask,
};
pub fn prune_datastore(

View File

@ -13,7 +13,7 @@ use serde_json::json;
use proxmox::api::error::{HttpError, StatusCode};
use pbs_api_types::{Authid, SnapshotListItem, GroupListItem};
use pbs_datastore::{task_log, BackupInfo, BackupDir, BackupGroup, StoreProgress};
use pbs_datastore::{BackupInfo, BackupDir, BackupGroup, StoreProgress};
use pbs_datastore::data_blob::DataBlob;
use pbs_datastore::dynamic_index::DynamicIndexReader;
use pbs_datastore::fixed_index::FixedIndexReader;
@ -22,11 +22,12 @@ use pbs_datastore::manifest::{
CLIENT_LOG_BLOB_NAME, MANIFEST_BLOB_NAME, ArchiveType, BackupManifest, FileInfo, archive_type
};
use pbs_tools::sha::sha256;
use pbs_tools::task_log;
use pbs_client::{BackupReader, BackupRepository, HttpClient, HttpClientOptions, RemoteChunkReader};
use proxmox_rest_server::WorkerTask;
use crate::{
backup::DataStore,
server::WorkerTask,
tools::ParallelHandler,
};

View File

@ -1,10 +1,10 @@
use anyhow::{format_err, Error};
use pbs_datastore::task_log;
use pbs_tools::task_log;
use pbs_api_types::{Authid, VerificationJobConfig};
use proxmox_rest_server::WorkerTask;
use crate::{
server::WorkerTask,
server::jobstate::Job,
backup::{
DataStore,

View File

@ -30,19 +30,16 @@ use proxmox::{
use pbs_api_types::{VirtualTapeDrive, LtoTapeDrive, Fingerprint};
use pbs_config::key_config::KeyConfig;
use pbs_datastore::task::TaskState;
use pbs_datastore::task_log;
use pbs_tools::{task_log, task::TaskState};
use pbs_tape::{
TapeWrite, TapeRead, BlockReadError, MediaContentHeader,
sg_tape::TapeAlertFlags,
};
use proxmox_rest_server::WorkerTask;
use crate::{
server::{
send_load_media_email,
WorkerTask,
},
server::send_load_media_email,
tape::{
MediaId,
drive::{

View File

@ -13,16 +13,16 @@ use anyhow::{bail, Error};
use proxmox::tools::Uuid;
use pbs_datastore::task_log;
use pbs_tools::task_log;
use pbs_config::tape_encryption_keys::load_key_configs;
use pbs_tape::{
TapeWrite,
sg_tape::tape_alert_flags_critical,
};
use proxmox_rest_server::WorkerTask;
use crate::{
backup::{DataStore, SnapshotReader},
server::WorkerTask,
tape::{
TAPE_STATUS_DIR,
MAX_CHUNK_ARCHIVE_SIZE,

View File

@ -6,13 +6,13 @@ extern crate tokio;
extern crate nix;
use proxmox::try_block;
use proxmox::tools::fs::CreateOptions;
use pbs_api_types::{Authid, UPID};
use proxmox_rest_server::{flog, CommandoSocket};
use proxmox_backup::server;
use proxmox_rest_server::{flog, CommandoSocket, WorkerTask};
fn garbage_collection(worker: &server::WorkerTask) -> Result<(), Error> {
fn garbage_collection(worker: &WorkerTask) -> Result<(), Error> {
worker.log("start garbage collection");
@ -33,8 +33,11 @@ fn garbage_collection(worker: &server::WorkerTask) -> Result<(), Error> {
#[test]
#[ignore]
fn worker_task_abort() -> Result<(), Error> {
let uid = nix::unistd::Uid::current();
let gid = nix::unistd::Gid::current();
server::create_task_log_dirs()?;
let file_opts = CreateOptions::new().owner(uid).group(gid);
proxmox_rest_server::init_worker_tasks("./target/tasklogtestdir".into(), file_opts.clone())?;
use std::sync::{Arc, Mutex};
@ -44,10 +47,11 @@ fn worker_task_abort() -> Result<(), Error> {
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async move {
let mut commando_sock = CommandoSocket::new(server::our_ctrl_sock(), nix::unistd::Gid::current());
let mut commando_sock = CommandoSocket::new(
proxmox_rest_server::our_ctrl_sock(), nix::unistd::Gid::current());
let init_result: Result<(), Error> = try_block!({
server::register_task_control_commands(&mut commando_sock)?;
proxmox_rest_server::register_task_control_commands(&mut commando_sock)?;
proxmox_rest_server::server_state_init()?;
Ok(())
});
@ -63,10 +67,10 @@ fn worker_task_abort() -> Result<(), Error> {
}
let errmsg = errmsg1.clone();
let res = server::WorkerTask::new_thread(
let res = WorkerTask::new_thread(
"garbage_collection",
None,
Authid::root_auth_id().clone(),
Authid::root_auth_id().to_string(),
true,
move |worker| {
println!("WORKER {}", worker);
@ -91,8 +95,8 @@ fn worker_task_abort() -> Result<(), Error> {
}
Ok(wid) => {
println!("WORKER: {}", wid);
server::abort_worker_async(wid.parse::<UPID>().unwrap());
server::wait_for_local_worker(&wid).await.unwrap();
proxmox_rest_server::abort_worker_async(wid.parse::<UPID>().unwrap());
proxmox_rest_server::wait_for_local_worker(&wid).await.unwrap();
}
}
});