Compare commits
2
Commits
No files matched your search
@@ -10,11 +10,13 @@ param(
|
|||||||
[string]$User = "root",
|
[string]$User = "root",
|
||||||
[string]$RemotePath = "/root/.bin/wakey",
|
[string]$RemotePath = "/root/.bin/wakey",
|
||||||
[string]$AgentRemotePath = "/root/.bin/wakey-agent",
|
[string]$AgentRemotePath = "/root/.bin/wakey-agent",
|
||||||
|
[string]$RemoteInitPath = "/etc/init.d/wakey",
|
||||||
[string]$Target = "armv7-unknown-linux-musleabihf",
|
[string]$Target = "armv7-unknown-linux-musleabihf",
|
||||||
[string]$BinName = "wakey",
|
[string]$BinName = "wakey",
|
||||||
[string]$AgentBinName = "wakey-agent",
|
[string]$AgentBinName = "wakey-agent",
|
||||||
[string]$HostKey,
|
[string]$HostKey,
|
||||||
[switch]$ForcePassword,
|
[switch]$ForcePassword,
|
||||||
|
[switch]$SkipInitScript,
|
||||||
[switch]$Restart = $true,
|
[switch]$Restart = $true,
|
||||||
[switch]$Quiet = $true
|
[switch]$Quiet = $true
|
||||||
)
|
)
|
||||||
@@ -62,7 +64,10 @@ try {
|
|||||||
$agentRemoteTmp = "$AgentRemotePath.tmp"
|
$agentRemoteTmp = "$AgentRemotePath.tmp"
|
||||||
$destTmp = "$User@${HostName}:$remoteTmp"
|
$destTmp = "$User@${HostName}:$remoteTmp"
|
||||||
$agentDestTmp = "$User@${HostName}:$agentRemoteTmp"
|
$agentDestTmp = "$User@${HostName}:$agentRemoteTmp"
|
||||||
|
$initTmp = '/var/tmp/wakey.init.tmp'
|
||||||
|
$initDestTmp = "$User@${HostName}:$initTmp"
|
||||||
$localDeploy = Join-Path $repoRoot 'scripts/remote_deploy_wakey.sh'
|
$localDeploy = Join-Path $repoRoot 'scripts/remote_deploy_wakey.sh'
|
||||||
|
$localInit = Join-Path $repoRoot 'scripts/init/openwrt/wakey'
|
||||||
$deployTmp = '/var/tmp/remote_deploy_wakey.sh'
|
$deployTmp = '/var/tmp/remote_deploy_wakey.sh'
|
||||||
$deployPreferred = '/root/.bin/remote_deploy_wakey.sh'
|
$deployPreferred = '/root/.bin/remote_deploy_wakey.sh'
|
||||||
|
|
||||||
@@ -70,6 +75,11 @@ try {
|
|||||||
Invoke-Scp -Local $localBin -Dest $destTmp -Pass $Pass -HostKey $HostKey -Port $Port -Quiet:$Quiet -ForcePassword:$ForcePassword
|
Invoke-Scp -Local $localBin -Dest $destTmp -Pass $Pass -HostKey $HostKey -Port $Port -Quiet:$Quiet -ForcePassword:$ForcePassword
|
||||||
Invoke-Scp -Local $localAgentBin -Dest $agentDestTmp -Pass $Pass -HostKey $HostKey -Port $Port -Quiet:$Quiet -ForcePassword:$ForcePassword
|
Invoke-Scp -Local $localAgentBin -Dest $agentDestTmp -Pass $Pass -HostKey $HostKey -Port $Port -Quiet:$Quiet -ForcePassword:$ForcePassword
|
||||||
|
|
||||||
|
# Push OpenWrt init script unless explicitly skipped
|
||||||
|
if (-not $SkipInitScript -and (Test-Path $localInit)) {
|
||||||
|
Invoke-Scp -Local $localInit -Dest $initDestTmp -Pass $Pass -HostKey $HostKey -Port $Port -Quiet:$Quiet -ForcePassword:$ForcePassword
|
||||||
|
}
|
||||||
|
|
||||||
# Push deploy helper if exists
|
# Push deploy helper if exists
|
||||||
if (Test-Path $localDeploy) {
|
if (Test-Path $localDeploy) {
|
||||||
Invoke-Scp -Local $localDeploy -Dest "$User@${HostName}:$deployTmp" -Pass $Pass -HostKey $HostKey -Port $Port -Quiet:$Quiet -ForcePassword:$ForcePassword
|
Invoke-Scp -Local $localDeploy -Dest "$User@${HostName}:$deployTmp" -Pass $Pass -HostKey $HostKey -Port $Port -Quiet:$Quiet -ForcePassword:$ForcePassword
|
||||||
@@ -80,6 +90,19 @@ try {
|
|||||||
$script = @"
|
$script = @"
|
||||||
$(Get-DeployScript $deployPreferred $deployTmp $remoteTmp $RemotePath 0)
|
$(Get-DeployScript $deployPreferred $deployTmp $remoteTmp $RemotePath 0)
|
||||||
$(Get-DeployScript $deployPreferred $deployTmp $agentRemoteTmp $AgentRemotePath $restartFlag)
|
$(Get-DeployScript $deployPreferred $deployTmp $agentRemoteTmp $AgentRemotePath $restartFlag)
|
||||||
|
$(if (-not $SkipInitScript) {
|
||||||
|
@"
|
||||||
|
if [ -f $initTmp ]; then
|
||||||
|
sed -i "s/\r$//" $initTmp 2>/dev/null || true
|
||||||
|
if command -v install >/dev/null 2>&1; then
|
||||||
|
install -m 0755 $initTmp $RemoteInitPath
|
||||||
|
else
|
||||||
|
cp -f $initTmp $RemoteInitPath
|
||||||
|
chmod 0755 $RemoteInitPath
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
"@
|
||||||
|
})
|
||||||
"@
|
"@
|
||||||
$remoteCmd = "sh -lc '$($script -replace "`r",'')'"
|
$remoteCmd = "sh -lc '$($script -replace "`r",'')'"
|
||||||
if ($Quiet) { $remoteCmd += " >/dev/null 2>&1" }
|
if ($Quiet) { $remoteCmd += " >/dev/null 2>&1" }
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ pub enum Command {
|
|||||||
Serve(ServeArgs),
|
Serve(ServeArgs),
|
||||||
/// Enroll this router with a control plane and write agent config.
|
/// Enroll this router with a control plane and write agent config.
|
||||||
Enroll(EnrollArgs),
|
Enroll(EnrollArgs),
|
||||||
|
/// Create a local config scaffold for manual bootstrap.
|
||||||
|
InitConfig(InitConfigArgs),
|
||||||
/// Reload a running agent daemon by sending SIGHUP.
|
/// Reload a running agent daemon by sending SIGHUP.
|
||||||
Reload(ReloadArgs),
|
Reload(ReloadArgs),
|
||||||
}
|
}
|
||||||
@@ -52,6 +54,29 @@ pub struct EnrollArgs {
|
|||||||
pub config: PathBuf,
|
pub config: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Args)]
|
||||||
|
pub struct InitConfigArgs {
|
||||||
|
/// Path to the agent config file to write.
|
||||||
|
#[arg(long, default_value = config::DEFAULT_CONFIG_PATH)]
|
||||||
|
pub config: PathBuf,
|
||||||
|
|
||||||
|
/// Base HTTPS URL of the control plane.
|
||||||
|
#[arg(long)]
|
||||||
|
pub server_url: Option<String>,
|
||||||
|
|
||||||
|
/// Persistent agent id obtained from enroll flow.
|
||||||
|
#[arg(long)]
|
||||||
|
pub agent_id: Option<String>,
|
||||||
|
|
||||||
|
/// Persistent agent token obtained from enroll flow.
|
||||||
|
#[arg(long)]
|
||||||
|
pub agent_token: Option<String>,
|
||||||
|
|
||||||
|
/// Replace an existing config file.
|
||||||
|
#[arg(long)]
|
||||||
|
pub force: bool,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Args)]
|
#[derive(Args)]
|
||||||
pub struct ReloadArgs {
|
pub struct ReloadArgs {
|
||||||
/// Path to pid file for reload signaling.
|
/// Path to pid file for reload signaling.
|
||||||
|
|||||||
+28
-1
@@ -9,7 +9,7 @@ mod tracing;
|
|||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use cli::{Cli, Command};
|
use cli::{Cli, Command, InitConfigArgs};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
@@ -23,8 +23,35 @@ async fn main() -> Result<()> {
|
|||||||
println!("agent_id={}", config.agent_id);
|
println!("agent_id={}", config.agent_id);
|
||||||
println!("config={}", args.config.display());
|
println!("config={}", args.config.display());
|
||||||
}
|
}
|
||||||
|
Command::InitConfig(args) => init_config(args)?,
|
||||||
Command::Reload(args) => serve::reload_daemon(&args.pid_file)?,
|
Command::Reload(args) => serve::reload_daemon(&args.pid_file)?,
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn init_config(args: InitConfigArgs) -> Result<()> {
|
||||||
|
if args.config.exists() && !args.force {
|
||||||
|
anyhow::bail!(
|
||||||
|
"config {} already exists; re-run with --force to overwrite",
|
||||||
|
args.config.display()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let cfg = config::AgentConfig {
|
||||||
|
server_url: args
|
||||||
|
.server_url
|
||||||
|
.unwrap_or_else(|| "https://control-plane.example.com".to_string()),
|
||||||
|
agent_id: args.agent_id.unwrap_or_else(|| "REPLACE_ME_AGENT_ID".to_string()),
|
||||||
|
agent_token: args
|
||||||
|
.agent_token
|
||||||
|
.unwrap_or_else(|| "REPLACE_ME_AGENT_TOKEN".to_string()),
|
||||||
|
reconnect_base_ms: 1_000,
|
||||||
|
reconnect_max_ms: 30_000,
|
||||||
|
};
|
||||||
|
|
||||||
|
config::save_config(&args.config, &cfg)?;
|
||||||
|
println!("config={}", args.config.display());
|
||||||
|
println!("next=wakey-agent serve --config {}", args.config.display());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -7,6 +7,14 @@ use crate::cli::ServeArgs;
|
|||||||
use crate::{config, session};
|
use crate::{config, session};
|
||||||
|
|
||||||
pub async fn serve(args: ServeArgs) -> Result<()> {
|
pub async fn serve(args: ServeArgs) -> Result<()> {
|
||||||
|
if !args.config.exists() {
|
||||||
|
anyhow::bail!(
|
||||||
|
"agent config {} not found. Run `wakey-agent enroll --server-url <url> --enroll-token <token>` or `wakey-agent init-config --config {}` first",
|
||||||
|
args.config.display(),
|
||||||
|
args.config.display()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
write_pid_file(&args.pid_file)?;
|
write_pid_file(&args.pid_file)?;
|
||||||
|
|
||||||
let mut cfg = config::load_config(&args.config)?;
|
let mut cfg = config::load_config(&args.config)?;
|
||||||
|
|||||||
Reference in new issue
Block a user