mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 10:21:52 +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::encrypt::encrypt;
|
||||
use embassy::middleware::recovery::recovery;
|
||||
use embassy::net::mdns::MdnsController;
|
||||
use embassy::sound::MARIO_COIN;
|
||||
use embassy::util::Invoke;
|
||||
use embassy::{Error, ResultExt};
|
||||
use http::StatusCode;
|
||||
@@ -33,8 +35,27 @@ async fn init(cfg_path: Option<&str>) -> Result<(), Error> {
|
||||
.await?;
|
||||
log::info!("Loaded Disk");
|
||||
} 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 encrypt = encrypt(Arc::new(get_product_key().await?));
|
||||
MARIO_COIN.play().await?;
|
||||
rpc_server!({
|
||||
command: embassy::setup_api,
|
||||
context: ctx.clone(),
|
||||
@@ -99,16 +120,19 @@ async fn init(cfg_path: Option<&str>) -> Result<(), Error> {
|
||||
embassy::hostname::sync_hostname().await?;
|
||||
log::info!("Synced Hostname");
|
||||
|
||||
if tokio::fs::metadata("/var/www/html/public").await.is_err() {
|
||||
tokio::fs::create_dir_all("/var/www/html/public").await?
|
||||
if tokio::fs::metadata("/var/www/html/main/public")
|
||||
.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
|
||||
.is_err()
|
||||
{
|
||||
tokio::fs::symlink(
|
||||
cfg.datadir().join("package-data").join("public"),
|
||||
"/var/www/html/public/package-data",
|
||||
"/var/www/html/main/public/package-data",
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
@@ -142,6 +166,24 @@ async fn inner_main(cfg_path: Option<&str>) -> Result<(), Error> {
|
||||
log::error!("{}", e.source);
|
||||
log::debug!("{}", e.source);
|
||||
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?;
|
||||
rpc_server!({
|
||||
command: embassy::recovery_api,
|
||||
|
||||
@@ -2,23 +2,21 @@ use std::time::Duration;
|
||||
|
||||
use anyhow::anyhow;
|
||||
use embassy::context::{RecoveryContext, RpcContext};
|
||||
use embassy::db::model::Database;
|
||||
use embassy::db::subscribe;
|
||||
use embassy::hostname::{get_hostname, get_id};
|
||||
use embassy::middleware::auth::auth;
|
||||
use embassy::middleware::cors::cors;
|
||||
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::status::{check_all, synchronize_all};
|
||||
use embassy::util::daemon;
|
||||
use embassy::util::{daemon, Invoke};
|
||||
use embassy::{Error, ErrorKind, ResultExt};
|
||||
use futures::{FutureExt, TryFutureExt};
|
||||
use log::LevelFilter;
|
||||
use patch_db::json_ptr::JsonPointer;
|
||||
use reqwest::{Client, Proxy};
|
||||
use rpc_toolkit::hyper::{Body, Response, Server, StatusCode};
|
||||
use rpc_toolkit::{rpc_server, Context};
|
||||
use tokio::process::Command;
|
||||
use tokio::signal::unix::signal;
|
||||
|
||||
fn status_fn(_: i32) -> StatusCode {
|
||||
@@ -64,9 +62,27 @@ async fn inner_main(
|
||||
sig_handler_ctx
|
||||
.shutdown
|
||||
.send(None)
|
||||
.map_err(|_| ())
|
||||
.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 ctx = rpc_ctx.clone();
|
||||
let server = rpc_server!({
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use std::path::Path;
|
||||
|
||||
use anyhow::anyhow;
|
||||
use tokio::process::Command;
|
||||
|
||||
use crate::util::Invoke;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use std::collections::HashSet;
|
||||
use std::fmt::Display;
|
||||
use std::io::SeekFrom;
|
||||
use std::path::Path;
|
||||
use std::process::Stdio;
|
||||
@@ -9,9 +8,9 @@ use std::sync::Arc;
|
||||
use anyhow::anyhow;
|
||||
use emver::VersionRange;
|
||||
use futures::TryStreamExt;
|
||||
use http::{HeaderMap, StatusCode};
|
||||
use http::StatusCode;
|
||||
use indexmap::IndexMap;
|
||||
use patch_db::{DbHandle, OptionModel};
|
||||
use patch_db::DbHandle;
|
||||
use reqwest::Response;
|
||||
use rpc_toolkit::command;
|
||||
use tokio::fs::{File, OpenOptions};
|
||||
|
||||
@@ -2,7 +2,7 @@ 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;
|
||||
|
||||
@@ -30,4 +30,4 @@ server {
|
||||
location / {
|
||||
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 patch_db::{LockType, PatchDbHandle};
|
||||
use rpc_toolkit::command;
|
||||
|
||||
use crate::context::RpcContext;
|
||||
@@ -8,10 +9,11 @@ use crate::sound::MARIO_DEATH;
|
||||
use crate::util::{display_none, Invoke};
|
||||
use crate::Error;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Clone)]
|
||||
pub struct Shutdown {
|
||||
zfs_pool: Arc<String>,
|
||||
restart: bool,
|
||||
db_handle: Arc<PatchDbHandle>,
|
||||
}
|
||||
impl Shutdown {
|
||||
/// BLOCKING
|
||||
@@ -64,22 +66,34 @@ impl Shutdown {
|
||||
|
||||
#[command(display(display_none))]
|
||||
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
|
||||
.send(Some(Shutdown {
|
||||
zfs_pool: ctx.zfs_pool_name.clone(),
|
||||
restart: false,
|
||||
db_handle: Arc::new(db),
|
||||
}))
|
||||
.map_err(|_| ())
|
||||
.expect("receiver dropped");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[command(display(display_none))]
|
||||
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
|
||||
.send(Some(Shutdown {
|
||||
zfs_pool: ctx.zfs_pool_name.clone(),
|
||||
restart: true,
|
||||
db_handle: Arc::new(db),
|
||||
}))
|
||||
.map_err(|_| ())
|
||||
.expect("receiver dropped");
|
||||
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-dynamic": "^12.2.1",
|
||||
"@angular/router": "^12.2.1",
|
||||
"@ionic/angular": "^5.6.13",
|
||||
"@ionic/angular": "^5.7.0",
|
||||
"rxjs": "^6.6.7",
|
||||
"tslib": "^2.3.1",
|
||||
"zone.js": "^0.11.4"
|
||||
@@ -18690,7 +18690,9 @@
|
||||
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz",
|
||||
"integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==",
|
||||
"dev": true,
|
||||
"requires": {}
|
||||
"requires": {
|
||||
"ajv": "^8.0.0"
|
||||
}
|
||||
},
|
||||
"tslib": {
|
||||
"version": "2.3.0",
|
||||
@@ -18770,7 +18772,9 @@
|
||||
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz",
|
||||
"integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==",
|
||||
"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",
|
||||
"integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==",
|
||||
"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",
|
||||
"integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==",
|
||||
"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",
|
||||
"integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==",
|
||||
"dev": true,
|
||||
"requires": {}
|
||||
"requires": {
|
||||
"ajv": "^8.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -21377,7 +21387,9 @@
|
||||
"integrity": "sha512-Brah4Uo5/U8v76c6euTwtjVFFaVishwnJrQBYpev1JRh4vjA1F4HY3UzQez41YUCszUCXKagG8v6eVRBHV1gkw==",
|
||||
"dev": true,
|
||||
"peer": true,
|
||||
"requires": {}
|
||||
"requires": {
|
||||
"ajv": "^8.0.0"
|
||||
}
|
||||
},
|
||||
"alphanum-sort": {
|
||||
"version": "1.0.2",
|
||||
|
||||
Reference in New Issue
Block a user