[CmdletBinding()] param( [string]$Server = '218.93.190.75', [string]$SshUser = 'root', [string]$RemotePath = '/opt/caiwuxitong', [string]$KeyPath, [switch]$DryRun ) $ErrorActionPreference = 'Stop' if ($RemotePath -notmatch '^/[A-Za-z0-9._/-]+$') { throw 'Invalid remote project path.' } $cron = @( 'CRON_TZ=Asia/Shanghai' '# Process details use a dedicated schedule and wait for the shared upstream lock.' "2-59/5 * * * * root CAIWU_BATCH_LOCK_WAIT=900 /usr/bin/flock -n /run/caiwu-ding-process-details.lock /bin/sh $RemotePath/run-finance-batch.sh business-mirror:sync-ding-process-details --quiet >/dev/null 2>&1" ) -join "`n" if ($DryRun) { Write-Output $cron return } $auth = $null try { . (Join-Path $PSScriptRoot 'deploy-auth.ps1') $auth = Start-CaiwuDeploymentAuth -Server $Server -SshUser $SshUser -KeyPath $KeyPath $remoteScript = @( 'set -eu' "test -f '$RemotePath/run-finance-batch.sh'" 'umask 022' "cat > /etc/cron.d/caiwu-ding-process-details <<'CAIWU_CRON'" $cron 'CAIWU_CRON' 'chmod 644 /etc/cron.d/caiwu-ding-process-details' "printf '\nInstalled %s\n' /etc/cron.d/caiwu-ding-process-details" 'cat /etc/cron.d/caiwu-ding-process-details' ) -join "`n" & ssh @($auth.Options) "${SshUser}@${Server}" $remoteScript if ($LASTEXITCODE -ne 0) { throw 'Failed to install the process-details sync cron.' } } finally { if ($auth) { Stop-CaiwuDeploymentAuth $auth } }