mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
mdns and nginx for main service
This commit is contained in:
committed by
Aiden McClelland
parent
9fb57d038a
commit
8dc3377bbd
@@ -8,6 +8,8 @@ use embassy::hostname::get_product_key;
|
|||||||
use embassy::middleware::cors::cors;
|
use embassy::middleware::cors::cors;
|
||||||
use embassy::middleware::encrypt::encrypt;
|
use embassy::middleware::encrypt::encrypt;
|
||||||
use embassy::middleware::recovery::recovery;
|
use embassy::middleware::recovery::recovery;
|
||||||
|
use embassy::net::mdns::MdnsController;
|
||||||
|
use embassy::sound::MARIO_COIN;
|
||||||
use embassy::util::Invoke;
|
use embassy::util::Invoke;
|
||||||
use embassy::{Error, ResultExt};
|
use embassy::{Error, ResultExt};
|
||||||
use http::StatusCode;
|
use http::StatusCode;
|
||||||
@@ -33,8 +35,27 @@ async fn init(cfg_path: Option<&str>) -> Result<(), Error> {
|
|||||||
.await?;
|
.await?;
|
||||||
log::info!("Loaded Disk");
|
log::info!("Loaded Disk");
|
||||||
} else {
|
} else {
|
||||||
|
#[cfg(feature = "avahi")]
|
||||||
|
let mdns = MdnsController::init();
|
||||||
|
tokio::fs::write(
|
||||||
|
"/etc/nginx/sites-available/default",
|
||||||
|
include_str!("../nginx/setup-wizard.conf"),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.with_ctx(|_| {
|
||||||
|
(
|
||||||
|
embassy::ErrorKind::Filesystem,
|
||||||
|
"/etc/nginx/sites-available/default",
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
Command::new("systemctl")
|
||||||
|
.arg("reload")
|
||||||
|
.arg("nginx")
|
||||||
|
.invoke(embassy::ErrorKind::Nginx)
|
||||||
|
.await?;
|
||||||
let ctx = SetupContext::init(cfg_path).await?;
|
let ctx = SetupContext::init(cfg_path).await?;
|
||||||
let encrypt = encrypt(Arc::new(get_product_key().await?));
|
let encrypt = encrypt(Arc::new(get_product_key().await?));
|
||||||
|
MARIO_COIN.play().await?;
|
||||||
rpc_server!({
|
rpc_server!({
|
||||||
command: embassy::setup_api,
|
command: embassy::setup_api,
|
||||||
context: ctx.clone(),
|
context: ctx.clone(),
|
||||||
@@ -99,16 +120,19 @@ async fn init(cfg_path: Option<&str>) -> Result<(), Error> {
|
|||||||
embassy::hostname::sync_hostname().await?;
|
embassy::hostname::sync_hostname().await?;
|
||||||
log::info!("Synced Hostname");
|
log::info!("Synced Hostname");
|
||||||
|
|
||||||
if tokio::fs::metadata("/var/www/html/public").await.is_err() {
|
if tokio::fs::metadata("/var/www/html/main/public")
|
||||||
tokio::fs::create_dir_all("/var/www/html/public").await?
|
.await
|
||||||
|
.is_err()
|
||||||
|
{
|
||||||
|
tokio::fs::create_dir_all("/var/www/html/main/public").await?
|
||||||
}
|
}
|
||||||
if tokio::fs::symlink_metadata("/var/www/html/public/package-data")
|
if tokio::fs::symlink_metadata("/var/www/html/main/public/package-data")
|
||||||
.await
|
.await
|
||||||
.is_err()
|
.is_err()
|
||||||
{
|
{
|
||||||
tokio::fs::symlink(
|
tokio::fs::symlink(
|
||||||
cfg.datadir().join("package-data").join("public"),
|
cfg.datadir().join("package-data").join("public"),
|
||||||
"/var/www/html/public/package-data",
|
"/var/www/html/main/public/package-data",
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
@@ -142,6 +166,24 @@ async fn inner_main(cfg_path: Option<&str>) -> Result<(), Error> {
|
|||||||
log::error!("{}", e.source);
|
log::error!("{}", e.source);
|
||||||
log::debug!("{}", e.source);
|
log::debug!("{}", e.source);
|
||||||
embassy::sound::BEETHOVEN.play().await?;
|
embassy::sound::BEETHOVEN.play().await?;
|
||||||
|
#[cfg(feature = "avahi")]
|
||||||
|
let mdns = MdnsController::init();
|
||||||
|
tokio::fs::write(
|
||||||
|
"/etc/nginx/sites-available/default",
|
||||||
|
include_str!("../nginx/recovery-ui.conf"),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.with_ctx(|_| {
|
||||||
|
(
|
||||||
|
embassy::ErrorKind::Filesystem,
|
||||||
|
"/etc/nginx/sites-available/default",
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
Command::new("systemctl")
|
||||||
|
.arg("reload")
|
||||||
|
.arg("nginx")
|
||||||
|
.invoke(embassy::ErrorKind::Nginx)
|
||||||
|
.await?;
|
||||||
let ctx = RecoveryContext::init(cfg_path, e).await?;
|
let ctx = RecoveryContext::init(cfg_path, e).await?;
|
||||||
rpc_server!({
|
rpc_server!({
|
||||||
command: embassy::recovery_api,
|
command: embassy::recovery_api,
|
||||||
|
|||||||
@@ -2,23 +2,21 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use embassy::context::{RecoveryContext, RpcContext};
|
use embassy::context::{RecoveryContext, RpcContext};
|
||||||
use embassy::db::model::Database;
|
|
||||||
use embassy::db::subscribe;
|
use embassy::db::subscribe;
|
||||||
use embassy::hostname::{get_hostname, get_id};
|
|
||||||
use embassy::middleware::auth::auth;
|
use embassy::middleware::auth::auth;
|
||||||
use embassy::middleware::cors::cors;
|
use embassy::middleware::cors::cors;
|
||||||
use embassy::middleware::recovery::recovery;
|
use embassy::middleware::recovery::recovery;
|
||||||
use embassy::net::tor::{os_key, tor_health_check};
|
use embassy::net::tor::tor_health_check;
|
||||||
use embassy::shutdown::Shutdown;
|
use embassy::shutdown::Shutdown;
|
||||||
use embassy::status::{check_all, synchronize_all};
|
use embassy::status::{check_all, synchronize_all};
|
||||||
use embassy::util::daemon;
|
use embassy::util::{daemon, Invoke};
|
||||||
use embassy::{Error, ErrorKind, ResultExt};
|
use embassy::{Error, ErrorKind, ResultExt};
|
||||||
use futures::{FutureExt, TryFutureExt};
|
use futures::{FutureExt, TryFutureExt};
|
||||||
use log::LevelFilter;
|
use log::LevelFilter;
|
||||||
use patch_db::json_ptr::JsonPointer;
|
|
||||||
use reqwest::{Client, Proxy};
|
use reqwest::{Client, Proxy};
|
||||||
use rpc_toolkit::hyper::{Body, Response, Server, StatusCode};
|
use rpc_toolkit::hyper::{Body, Response, Server, StatusCode};
|
||||||
use rpc_toolkit::{rpc_server, Context};
|
use rpc_toolkit::{rpc_server, Context};
|
||||||
|
use tokio::process::Command;
|
||||||
use tokio::signal::unix::signal;
|
use tokio::signal::unix::signal;
|
||||||
|
|
||||||
fn status_fn(_: i32) -> StatusCode {
|
fn status_fn(_: i32) -> StatusCode {
|
||||||
@@ -64,9 +62,27 @@ async fn inner_main(
|
|||||||
sig_handler_ctx
|
sig_handler_ctx
|
||||||
.shutdown
|
.shutdown
|
||||||
.send(None)
|
.send(None)
|
||||||
|
.map_err(|_| ())
|
||||||
.expect("send shutdown signal");
|
.expect("send shutdown signal");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tokio::fs::write(
|
||||||
|
"/etc/nginx/sites-available/default",
|
||||||
|
include_str!("../nginx/main-ui.conf"),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.with_ctx(|_| {
|
||||||
|
(
|
||||||
|
embassy::ErrorKind::Filesystem,
|
||||||
|
"/etc/nginx/sites-available/default",
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
Command::new("systemctl")
|
||||||
|
.arg("reload")
|
||||||
|
.arg("nginx")
|
||||||
|
.invoke(embassy::ErrorKind::Nginx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
let auth = auth(rpc_ctx.clone());
|
let auth = auth(rpc_ctx.clone());
|
||||||
let ctx = rpc_ctx.clone();
|
let ctx = rpc_ctx.clone();
|
||||||
let server = rpc_server!({
|
let server = rpc_server!({
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use anyhow::anyhow;
|
|
||||||
use tokio::process::Command;
|
use tokio::process::Command;
|
||||||
|
|
||||||
use crate::util::Invoke;
|
use crate::util::Invoke;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::fmt::Display;
|
|
||||||
use std::io::SeekFrom;
|
use std::io::SeekFrom;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::Stdio;
|
use std::process::Stdio;
|
||||||
@@ -9,9 +8,9 @@ use std::sync::Arc;
|
|||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use emver::VersionRange;
|
use emver::VersionRange;
|
||||||
use futures::TryStreamExt;
|
use futures::TryStreamExt;
|
||||||
use http::{HeaderMap, StatusCode};
|
use http::StatusCode;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use patch_db::{DbHandle, OptionModel};
|
use patch_db::DbHandle;
|
||||||
use reqwest::Response;
|
use reqwest::Response;
|
||||||
use rpc_toolkit::command;
|
use rpc_toolkit::command;
|
||||||
use tokio::fs::{File, OpenOptions};
|
use tokio::fs::{File, OpenOptions};
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ server {
|
|||||||
listen 80 default_server;
|
listen 80 default_server;
|
||||||
listen [::]:80 default_server;
|
listen [::]:80 default_server;
|
||||||
|
|
||||||
root /var/www/html;
|
root /var/www/html/main;
|
||||||
|
|
||||||
index index.html index.htm index.nginx-debian.html;
|
index index.html index.htm index.nginx-debian.html;
|
||||||
|
|
||||||
@@ -30,4 +30,4 @@ server {
|
|||||||
location / {
|
location / {
|
||||||
try_files $uri $uri/ =404;
|
try_files $uri $uri/ =404;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
23
appmgr/src/nginx/recovery-ui.conf
Normal file
23
appmgr/src/nginx/recovery-ui.conf
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
server {
|
||||||
|
listen 80 default_server;
|
||||||
|
listen [::]:80 default_server;
|
||||||
|
|
||||||
|
root /var/www/html/recovery;
|
||||||
|
|
||||||
|
index index.html index.htm index.nginx-debian.html;
|
||||||
|
|
||||||
|
server_name _;
|
||||||
|
|
||||||
|
proxy_buffering off;
|
||||||
|
proxy_request_buffering off;
|
||||||
|
proxy_socket_keepalive on;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
|
||||||
|
location /rpc/ {
|
||||||
|
proxy_pass http://localhost:5959/;
|
||||||
|
}
|
||||||
|
|
||||||
|
location / {
|
||||||
|
try_files $uri $uri/ =404;
|
||||||
|
}
|
||||||
|
}
|
||||||
23
appmgr/src/nginx/setup-wizard.conf
Normal file
23
appmgr/src/nginx/setup-wizard.conf
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
server {
|
||||||
|
listen 80 default_server;
|
||||||
|
listen [::]:80 default_server;
|
||||||
|
|
||||||
|
root /var/www/html/setup;
|
||||||
|
|
||||||
|
index index.html index.htm index.nginx-debian.html;
|
||||||
|
|
||||||
|
server_name _;
|
||||||
|
|
||||||
|
proxy_buffering off;
|
||||||
|
proxy_request_buffering off;
|
||||||
|
proxy_socket_keepalive on;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
|
||||||
|
location /rpc/ {
|
||||||
|
proxy_pass http://localhost:5959/;
|
||||||
|
}
|
||||||
|
|
||||||
|
location / {
|
||||||
|
try_files $uri $uri/ =404;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use patch_db::{LockType, PatchDbHandle};
|
||||||
use rpc_toolkit::command;
|
use rpc_toolkit::command;
|
||||||
|
|
||||||
use crate::context::RpcContext;
|
use crate::context::RpcContext;
|
||||||
@@ -8,10 +9,11 @@ use crate::sound::MARIO_DEATH;
|
|||||||
use crate::util::{display_none, Invoke};
|
use crate::util::{display_none, Invoke};
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Shutdown {
|
pub struct Shutdown {
|
||||||
zfs_pool: Arc<String>,
|
zfs_pool: Arc<String>,
|
||||||
restart: bool,
|
restart: bool,
|
||||||
|
db_handle: Arc<PatchDbHandle>,
|
||||||
}
|
}
|
||||||
impl Shutdown {
|
impl Shutdown {
|
||||||
/// BLOCKING
|
/// BLOCKING
|
||||||
@@ -64,22 +66,34 @@ impl Shutdown {
|
|||||||
|
|
||||||
#[command(display(display_none))]
|
#[command(display(display_none))]
|
||||||
pub async fn shutdown(#[context] ctx: RpcContext) -> Result<(), Error> {
|
pub async fn shutdown(#[context] ctx: RpcContext) -> Result<(), Error> {
|
||||||
|
let mut db = ctx.db.handle();
|
||||||
|
crate::db::DatabaseModel::new()
|
||||||
|
.lock(&mut db, LockType::Write)
|
||||||
|
.await;
|
||||||
ctx.shutdown
|
ctx.shutdown
|
||||||
.send(Some(Shutdown {
|
.send(Some(Shutdown {
|
||||||
zfs_pool: ctx.zfs_pool_name.clone(),
|
zfs_pool: ctx.zfs_pool_name.clone(),
|
||||||
restart: false,
|
restart: false,
|
||||||
|
db_handle: Arc::new(db),
|
||||||
}))
|
}))
|
||||||
|
.map_err(|_| ())
|
||||||
.expect("receiver dropped");
|
.expect("receiver dropped");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[command(display(display_none))]
|
#[command(display(display_none))]
|
||||||
pub async fn restart(#[context] ctx: RpcContext) -> Result<(), Error> {
|
pub async fn restart(#[context] ctx: RpcContext) -> Result<(), Error> {
|
||||||
|
let mut db = ctx.db.handle();
|
||||||
|
crate::db::DatabaseModel::new()
|
||||||
|
.lock(&mut db, LockType::Write)
|
||||||
|
.await;
|
||||||
ctx.shutdown
|
ctx.shutdown
|
||||||
.send(Some(Shutdown {
|
.send(Some(Shutdown {
|
||||||
zfs_pool: ctx.zfs_pool_name.clone(),
|
zfs_pool: ctx.zfs_pool_name.clone(),
|
||||||
restart: true,
|
restart: true,
|
||||||
|
db_handle: Arc::new(db),
|
||||||
}))
|
}))
|
||||||
|
.map_err(|_| ())
|
||||||
.expect("receiver dropped");
|
.expect("receiver dropped");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
26
setup-wizard/package-lock.json
generated
26
setup-wizard/package-lock.json
generated
@@ -13,7 +13,7 @@
|
|||||||
"@angular/platform-browser": "^12.2.1",
|
"@angular/platform-browser": "^12.2.1",
|
||||||
"@angular/platform-browser-dynamic": "^12.2.1",
|
"@angular/platform-browser-dynamic": "^12.2.1",
|
||||||
"@angular/router": "^12.2.1",
|
"@angular/router": "^12.2.1",
|
||||||
"@ionic/angular": "^5.6.13",
|
"@ionic/angular": "^5.7.0",
|
||||||
"rxjs": "^6.6.7",
|
"rxjs": "^6.6.7",
|
||||||
"tslib": "^2.3.1",
|
"tslib": "^2.3.1",
|
||||||
"zone.js": "^0.11.4"
|
"zone.js": "^0.11.4"
|
||||||
@@ -18690,7 +18690,9 @@
|
|||||||
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz",
|
||||||
"integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==",
|
"integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {}
|
"requires": {
|
||||||
|
"ajv": "^8.0.0"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"tslib": {
|
"tslib": {
|
||||||
"version": "2.3.0",
|
"version": "2.3.0",
|
||||||
@@ -18770,7 +18772,9 @@
|
|||||||
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz",
|
||||||
"integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==",
|
"integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {}
|
"requires": {
|
||||||
|
"ajv": "^8.0.0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -18831,7 +18835,9 @@
|
|||||||
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz",
|
||||||
"integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==",
|
"integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {}
|
"requires": {
|
||||||
|
"ajv": "^8.0.0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -18941,7 +18947,9 @@
|
|||||||
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz",
|
||||||
"integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==",
|
"integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {}
|
"requires": {
|
||||||
|
"ajv": "^8.0.0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -20779,7 +20787,9 @@
|
|||||||
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz",
|
||||||
"integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==",
|
"integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {}
|
"requires": {
|
||||||
|
"ajv": "^8.0.0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -21377,7 +21387,9 @@
|
|||||||
"integrity": "sha512-Brah4Uo5/U8v76c6euTwtjVFFaVishwnJrQBYpev1JRh4vjA1F4HY3UzQez41YUCszUCXKagG8v6eVRBHV1gkw==",
|
"integrity": "sha512-Brah4Uo5/U8v76c6euTwtjVFFaVishwnJrQBYpev1JRh4vjA1F4HY3UzQez41YUCszUCXKagG8v6eVRBHV1gkw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"peer": true,
|
"peer": true,
|
||||||
"requires": {}
|
"requires": {
|
||||||
|
"ajv": "^8.0.0"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"alphanum-sort": {
|
"alphanum-sort": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
|
|||||||
Reference in New Issue
Block a user