easy-devops 1.3.3 → 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ui/assets/index-BUpPxWmp.css +1 -0
- package/dist/ui/assets/index-DD0JjK0Q.js +475 -0
- package/dist/ui/assets/{socket-K5ttLD2q.js → socket-4tfdap-e.js} +2 -2
- package/dist/ui/index.html +2 -2
- package/package.json +2 -2
- package/src/cli/menus/dashboard.js +7 -134
- package/src/cli/menus/update.js +81 -141
- package/src/core/daemon/run.js +7 -1
- package/src/core/dashboardProcess.js +158 -0
- package/src/core/hub/agent.js +84 -15
- package/src/core/hubPermissions.js +24 -9
- package/src/core/jobs/bus.js +5 -0
- package/src/core/updateStatus.js +115 -0
- package/src/core/updater.js +25 -22
- package/src/dashboard/controllers/hubController.js +60 -1
- package/src/dashboard/controllers/updateController.js +213 -0
- package/src/dashboard/lib/daemonBridge.js +22 -1
- package/src/dashboard/routes/update.js +18 -0
- package/src/dashboard/server.js +2 -0
- package/src/dashboard/updateWorker.js +163 -0
- package/dist/ui/assets/index-BQIUfiNs.js +0 -452
- package/dist/ui/assets/index-D_5mc2NX.css +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const m=e=>new Date(Date.now()+e*864e5).toISOString(),A=()=>({nginx_down:{enabled:!0,channelIds:[]},cert_expiry:{enabled:!0,channelIds:[]},domain_health:{enabled:!0,channelIds:[]}});function g(e){const t=m(-40);return{backendHost:"127.0.0.1",upstreamType:"http",www:!1,wildcard:!1,enabled:!0,configFile:`/etc/nginx/conf.d/${e.name}.conf`,createdAt:t,updatedAt:t,ssl:{enabled:!1,certPath:"",keyPath:"",redirect:!0,hsts:!1,hstsMaxAge:31536e3},performance:{maxBodySize:"10m",readTimeout:60,connectTimeout:10,proxyBuffers:!1,gzip:!0,gzipTypes:"text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript"},security:{rateLimit:!1,rateLimitRate:10,rateLimitBurst:20,securityHeaders:!1,custom404:!1,custom50x:!1},advanced:{accessLog:!0,customLocations:""},certExpiry:null,daysLeft:null,notifications:A(),...e}}const y=e=>({certPath:`/etc/easy-devops/ssl/${e}/fullchain.pem`,keyPath:`/etc/easy-devops/ssl/${e}/privkey.pem`});function P(){return[g({name:"app.example.com",port:3e3,www:!0,ssl:{enabled:!0,...y("app.example.com"),redirect:!0,hsts:!0,hstsMaxAge:31536e3},certExpiry:m(95),daysLeft:95,security:{rateLimit:!0,rateLimitRate:10,rateLimitBurst:20,securityHeaders:!0,custom404:!1,custom50x:!1},notifications:{nginx_down:{enabled:!0,channelIds:["ch-discord-ops"]},cert_expiry:{enabled:!0,channelIds:["ch-discord-ops","ch-telegram-oncall"]},domain_health:{enabled:!1,channelIds:[]}}}),g({name:"api.example.com",port:8080,upstreamType:"https",ssl:{enabled:!0,...y("api.example.com"),redirect:!1,hsts:!1,hstsMaxAge:31536e3},certExpiry:m(12),daysLeft:12,notifications:{nginx_down:{enabled:!1,channelIds:[]},cert_expiry:{enabled:!0,channelIds:["ch-telegram-oncall"]},domain_health:{enabled:!0,channelIds:["ch-telegram-oncall"]}}}),g({name:"blog.example.com",port:4e3,backendHost:"10.0.0.12",security:{rateLimit:!1,rateLimitRate:10,rateLimitBurst:20,securityHeaders:!1,custom404:!0,custom50x:!1},notifications:{nginx_down:{enabled:!1,channelIds:[]},cert_expiry:{enabled:!1,channelIds:[]},domain_health:{enabled:!0,channelIds:["ch-discord-ops"]}}}),g({name:"staging.example.com",port:5e3,enabled:!1,configFile:"/etc/nginx/conf.d/staging.example.com.conf.disabled"})]}function O(){return[{domain:"app.example.com",expiry:m(95),daysLeft:95,status:"valid",autoRenew:"auto",autoRenewDays:7},{domain:"api.example.com",expiry:m(12),daysLeft:12,status:"expiring",autoRenew:"manual",autoRenewDays:7},{domain:"legacy.example.com",expiry:m(-3),daysLeft:-3,status:"expired"},{domain:"broken.example.com",expiry:null,daysLeft:null,status:"error"}]}function M(){return[{id:"ch-discord-ops",name:"Ops Discord",type:"discord",webhookUrl:"https://discord.com/api/webhooks/123456789012345678/example-token",message:"Easy DevOps alert"},{id:"ch-telegram-oncall",name:"On-call Telegram",type:"telegram",botToken:"7123456789:AAExampleTokenForMockOnly",chatId:"-1001234567890"}]}function E(){return{running:!0,version:"1.24.0",pid:1421}}function
|
|
1
|
+
const m=e=>new Date(Date.now()+e*864e5).toISOString(),A=()=>({nginx_down:{enabled:!0,channelIds:[]},cert_expiry:{enabled:!0,channelIds:[]},domain_health:{enabled:!0,channelIds:[]}});function g(e){const t=m(-40);return{backendHost:"127.0.0.1",upstreamType:"http",www:!1,wildcard:!1,enabled:!0,configFile:`/etc/nginx/conf.d/${e.name}.conf`,createdAt:t,updatedAt:t,ssl:{enabled:!1,certPath:"",keyPath:"",redirect:!0,hsts:!1,hstsMaxAge:31536e3},performance:{maxBodySize:"10m",readTimeout:60,connectTimeout:10,proxyBuffers:!1,gzip:!0,gzipTypes:"text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript"},security:{rateLimit:!1,rateLimitRate:10,rateLimitBurst:20,securityHeaders:!1,custom404:!1,custom50x:!1},advanced:{accessLog:!0,customLocations:""},certExpiry:null,daysLeft:null,notifications:A(),...e}}const y=e=>({certPath:`/etc/easy-devops/ssl/${e}/fullchain.pem`,keyPath:`/etc/easy-devops/ssl/${e}/privkey.pem`});function P(){return[g({name:"app.example.com",port:3e3,www:!0,ssl:{enabled:!0,...y("app.example.com"),redirect:!0,hsts:!0,hstsMaxAge:31536e3},certExpiry:m(95),daysLeft:95,security:{rateLimit:!0,rateLimitRate:10,rateLimitBurst:20,securityHeaders:!0,custom404:!1,custom50x:!1},notifications:{nginx_down:{enabled:!0,channelIds:["ch-discord-ops"]},cert_expiry:{enabled:!0,channelIds:["ch-discord-ops","ch-telegram-oncall"]},domain_health:{enabled:!1,channelIds:[]}}}),g({name:"api.example.com",port:8080,upstreamType:"https",ssl:{enabled:!0,...y("api.example.com"),redirect:!1,hsts:!1,hstsMaxAge:31536e3},certExpiry:m(12),daysLeft:12,notifications:{nginx_down:{enabled:!1,channelIds:[]},cert_expiry:{enabled:!0,channelIds:["ch-telegram-oncall"]},domain_health:{enabled:!0,channelIds:["ch-telegram-oncall"]}}}),g({name:"blog.example.com",port:4e3,backendHost:"10.0.0.12",security:{rateLimit:!1,rateLimitRate:10,rateLimitBurst:20,securityHeaders:!1,custom404:!0,custom50x:!1},notifications:{nginx_down:{enabled:!1,channelIds:[]},cert_expiry:{enabled:!1,channelIds:[]},domain_health:{enabled:!0,channelIds:["ch-discord-ops"]}}}),g({name:"staging.example.com",port:5e3,enabled:!1,configFile:"/etc/nginx/conf.d/staging.example.com.conf.disabled"})]}function O(){return[{domain:"app.example.com",expiry:m(95),daysLeft:95,status:"valid",autoRenew:"auto",autoRenewDays:7},{domain:"api.example.com",expiry:m(12),daysLeft:12,status:"expiring",autoRenew:"manual",autoRenewDays:7},{domain:"legacy.example.com",expiry:m(-3),daysLeft:-3,status:"expired"},{domain:"broken.example.com",expiry:null,daysLeft:null,status:"error"}]}function M(){return[{id:"ch-discord-ops",name:"Ops Discord",type:"discord",webhookUrl:"https://discord.com/api/webhooks/123456789012345678/example-token",message:"Easy DevOps alert"},{id:"ch-telegram-oncall",name:"On-call Telegram",type:"telegram",botToken:"7123456789:AAExampleTokenForMockOnly",chatId:"-1001234567890"}]}function E(){return{running:!0,version:"1.24.0",pid:1421}}function L(){return{"app.example.com.conf":`# Generated by Easy DevOps — manual edits are preserved on save only.
|
|
2
2
|
server {
|
|
3
3
|
listen 80;
|
|
4
4
|
server_name app.example.com www.app.example.com;
|
|
@@ -62,4 +62,4 @@ server {
|
|
|
62
62
|
return 404;
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
-
`}}function L(){const e=Date.now(),t=n=>new Date(e-n).toISOString().replace("T"," ").slice(0,19);return['2026/11/13 09:12:02 [notice] 1#1: using the "epoll" event method',"2026/11/13 09:12:02 [notice] 1#1: nginx/1.24.0","2026/11/13 09:12:02 [notice] 1#1: OS: Linux 6.8.0-45-generic",`${t(36e5)} [warn] 1421#1421: *241 an upstream response is buffered to a temporary file`,`${t(9e5)} [error] 1421#1421: *318 connect() failed (111: Connection refused) while connecting to upstream, client: 10.0.0.5, server: blog.example.com, request: "GET / HTTP/1.1", upstream: "http://10.0.0.12:4000/", host: "blog.example.com"`,`${t(24e4)} [warn] 1421#1421: *322 conflicting server name "staging.example.com" on 0.0.0.0:80, ignored`,`${t(3e4)} [error] 1421#1421: *330 open() "/var/www/easy-devops/.well-known/acme-challenge/test" failed (2: No such file or directory)`]}function $(){const e=Date.now(),t=n=>new Date(e-n).toISOString().replace("T"," ").replace("Z","");return[`10.0.0.5 - - [${t(12e4)}] "GET / HTTP/1.1" 200 4321 "-" "Mozilla/5.0"`,`10.0.0.8 - - [${t(9e4)}] "GET /api/health HTTP/1.1" 200 32 "-" "curl/8.5.0"`,`10.0.0.5 - - [${t(45e3)}] "POST /api/orders HTTP/1.1" 201 512 "-" "Mozilla/5.0"`,`10.0.0.9 - - [${t(2e4)}] "GET /assets/app.js HTTP/1.1" 200 18234 "https://app.example.com/" "Mozilla/5.0"`]}function T(){return[{name:"ez-dashboard",pmId:0,pid:2190,status:"online",cpu:1.2,memoryBytes:96468992,startedAt:Date.now()-2*864e5,uptimeMs:2*864e5,restarts:0,unstableRestarts:0,execPath:"/opt/easy-devops/src/cli/index.js",cwd:"/opt/easy-devops",user:"deploy",managed:!0,dataDir:"/var/lib/easy-devops"},{name:"api-worker",pmId:1,pid:2401,status:"online",cpu:2.4,memoryBytes:134217728,startedAt:Date.now()-6*36e5,uptimeMs:6*36e5,restarts:2,unstableRestarts:0,execPath:"/srv/api/worker.js",cwd:"/srv/api",user:"deploy",managed:!1,dataDir:null},{name:"legacy-app",pmId:2,pid:null,status:"stopped",cpu:null,memoryBytes:null,startedAt:null,uptimeMs:null,restarts:14,unstableRestarts:1,execPath:"/srv/legacy/server.js",cwd:"/srv/legacy",user:"deploy",managed:!1,dataDir:null},{name:"pm2-logrotate",pmId:3,pid:2502,status:"online",cpu:0,memoryBytes:0,startedAt:Date.now()-12*36e5,uptimeMs:12*36e5,restarts:1,unstableRestarts:0,execPath:"/home/deploy/.pm2/modules/pm2-logrotate/pm2-logrotate.js",cwd:"/home/deploy/.pm2/modules/pm2-logrotate",user:"deploy",managed:!1,dataDir:null}]}function j(){return{pm2:{installed:!0,version:"5.4.2",path:"/usr/local/bin/pm2"},apps:T(),currentUser:"deploy",pm2Home:"/home/deploy/.pm2"}}function N(){return{pm2:{installed:!0,version:"6.0.14",path:"/usr/local/bin/pm2"},dev:!1,dataDir:"/var/lib/easy-devops",backgroundService:{running:!0,connected:!0,pid:2190,version:"1.2.1",startedAt:Date.now()-2*864e5,heartbeatAgeMs:4e3,jobsRunningHere:!1,jobsOwnerPid:2190,jobsOwnerRole:"daemon",mechanism:"systemd",mode:null,installed:!0,startsAt:"boot",stoppedByUser:!1,stoppedAt:null,dataDir:"/var/lib/easy-devops",serverMode:!1,detail:null,state:"active",enabledOnBoot:!0,restarts:0,crashLooping:!1,warnings:[],runtime:{systemNode:{path:"/usr/bin/node",version:"v22.11.0",abi:"127"},pinned:{kind:"symlink",path:"/var/lib/easy-devops/runtime/node",target:"/usr/bin/node",version:"v22.11.0",exists:!0,broken:!1,differsFromSystem:!1},manager:{managed:!1,manager:null},mixed:{mixed:!1,msiPath:null,managed:null},warnings:[]}},install:{command:"ezz service install",needsElevation:!1,shell:null}}}function C(){return{dashboardPort:6443,nginxDir:"/etc/nginx",sslDir:"/etc/easy-devops/ssl",acmeEmail:"ops@example.com",sslAutoRenew:!0,sslAutoRenewDays:7,sslAutoRenewDaysMin:1,sslAutoRenewDaysMax:30,deployDir:"/home/ops/.config/easy-devops/ez_deploys",deployDirDefault:"/home/ops/.config/easy-devops/ez_deploys",deployDirIsDefault:!0,dashboardBindAddress:"127.0.0.1",bindsToLoopbackOnly:!0,dashboardAuth:"password",canUseNoPassword:!0,hasPassword:!0,platform:"linux"}}const h=[{id:"nginx",label:"Nginx",description:"Control the nginx service and its configuration files.",children:[{id:"nginx.start",label:"Start",description:"Start nginx when it is stopped."},{id:"nginx.stop",label:"Stop",description:"Stop nginx. Your sites go offline until it is started again."},{id:"nginx.restart",label:"Restart",description:"Full restart. Briefly drops connections."},{id:"nginx.reload",label:"Reload",description:"Graceful reload. Picks up config changes without dropping connections."},{id:"nginx.test",label:"Test config",description:"Run nginx -t. Read-only, changes nothing."},{id:"nginx.config.view",label:"View configs",description:"Read the generated nginx config files."},{id:"nginx.config.edit",label:"Edit configs",description:"Edit a config file. Always tested before it is kept, and rolled back if nginx rejects it."},{id:"nginx.logs.view",label:"View logs",description:"Read recent nginx access and error log lines."}]},{id:"domains",label:"Domains",description:"Manage reverse proxy domains and their nginx configs.",children:[{id:"domains.create",label:"Create",description:"Add a new domain and generate its nginx config."},{id:"domains.edit",label:"Edit",description:"Change an existing domain and regenerate its config."},{id:"domains.toggle",label:"Enable / disable",description:"Take a domain in or out of service without deleting it."},{id:"domains.delete",label:"Delete",description:"Remove a domain and its nginx config."}]},{id:"ssl",label:"SSL certificates",description:"Issue, renew and remove Let’s Encrypt certificates.",children:[{id:"ssl.renew",label:"Renew one",description:"Renew a single certificate. nginx keeps running."},{id:"ssl.renewAll",label:"Renew all expiring",description:"Renew every certificate expiring within 30 days."},{id:"ssl.issue",label:"Issue new",description:"Request a new certificate over HTTP-01. nginx keeps running."},{id:"ssl.delete",label:"Delete",description:"Delete certificate files. Refused while an enabled domain still uses them."},{id:"ssl.issueDns",label:"Issue wildcard (DNS-01)",description:"Wildcard certificates need a DNS TXT record you add by hand, so they cannot be driven from the Hub yet.",comingSoon:!0}]},{id:"deploy",label:"Deployments",description:"Deploy the apps on this server from the Hub. Fetching code and running its commands happens here, with this server’s own settings.",children:[{id:"deploy.run",label:"Deploy",description:"Start a deployment of an existing app from its configured repository."},{id:"deploy.rollback",label:"Roll back",description:"Switch an app back to an earlier release that is still on this server."},{id:"deploy.logs",label:"View deployment logs",description:"Read the output of a deployment. Build output can contain whatever the build prints."},{id:"deploy.manage",label:"Create, edit and delete apps",description:"Add an app from a repository, change its settings, issue its deploy token, or remove it. This decides which code runs here."},{id:"deploy.env",label:"Read and edit environment variables",description:"See and change an app’s environment values. They pass through the Hub while being edited and are not stored there."},{id:"deploy.ci",label:"Deploy from CI through the Hub",description:"Let a GitHub Action trigger a deployment by calling the Hub with the app’s own deploy token, so this server needs no inbound port."}]},{id:"process",label:"Processes",description:"Control the PM2 processes on this server, including the Easy DevOps service itself.",children:[{id:"process.start",label:"Start",description:"Start a stopped PM2 process from the Hub.",comingSoon:!0},{id:"process.stop",label:"Stop",description:"Stop a running PM2 process from the Hub. Stopping the dashboard would cut the Hub off from this server.",comingSoon:!0},{id:"process.restart",label:"Restart",description:"Restart a PM2 process from the Hub.",comingSoon:!0}]},{id:"system",label:"System",description:"Server-level operations beyond nginx.",children:[{id:"system.nodeVersions",label:"Manage Node.js versions",description:"Install and switch Node.js versions through nvm.",comingSoon:!0},{id:"system.restartServer",label:"Reboot the server",description:"Reboot the whole machine.",comingSoon:!0}]}],z=h.flatMap(e=>e.children.filter(t=>t.comingSoon).map(t=>t.id));function B(){const e={};for(const t of h)for(const n of t.children)e[n.id]=!1;for(const t of["nginx.reload","nginx.test","nginx.config.view","nginx.logs.view","domains.create","domains.edit","domains.toggle","ssl.renew","ssl.renewAll"])e[t]=!0;return e}function F(e){return{linked:!0,hubUrl:"https://hub.example.com",serverId:"srv_demo_01",permissions:e,tree:h,comingSoon:z,connected:!0,status:"connected",lastError:null,attempts:0,dataDir:"/var/lib/easy-devops",devDataDir:!1}}const v=["dashboard","service-stopped","service-stopped-by-you","service-not-installed","service-elevation","login","setup","setupcode","setupcode-expired","none"],G="ez-mock-state-v4",w="ez-mock-scenario";function U(){try{const e=new URLSearchParams(window.location.search),t=window.location.hash.includes("?")?new URLSearchParams(window.location.hash.slice(window.location.hash.indexOf("?")+1)):null,n=e.get("mock")??t?.get("mock");if(n&&v.includes(n))return sessionStorage.setItem(w,n),n;const a=sessionStorage.getItem(w);if(a&&v.includes(a))return a}catch{}return"dashboard"}function X(e){const t=N(),n=t.backgroundService,a={command:"ezz service install",needsElevation:!1,shell:null};return e==="service-stopped"&&(t.backgroundService={...n,running:!1,connected:!1,pid:null,version:null,startedAt:null,heartbeatAgeMs:null,jobsRunningHere:!0,jobsOwnerPid:null,jobsOwnerRole:"dashboard",state:"inactive",detail:"The service is stopped."}),e==="service-stopped-by-you"&&(t.install=a,t.backgroundService={...n,running:!1,connected:!1,pid:null,version:null,startedAt:null,heartbeatAgeMs:null,jobsRunningHere:!0,jobsOwnerPid:null,jobsOwnerRole:"dashboard",mechanism:"startup-supervisor",mode:"personal",installed:!0,startsAt:"logon",stoppedByUser:!0,stoppedAt:new Date(Date.now()-36e5).toISOString(),state:null,enabledOnBoot:!0,detail:"The service is stopped.",runtime:{systemNode:{path:"C:\\Program Files\\nodejs\\node.exe",version:"v22.11.0",abi:"127"},pinned:{kind:"copy",path:"C:\\Users\\deploy\\AppData\\Local\\easy-devops\\runtime\\node.exe",version:"v20.18.1",exists:!0,broken:!1,differsFromSystem:!0},manager:{managed:!0,manager:"nvm-windows"},mixed:{mixed:!1,msiPath:null,managed:null},warnings:[]}}),e==="service-not-installed"&&(t.install=a,t.backgroundService={...n,running:!1,connected:!1,pid:null,version:null,startedAt:null,heartbeatAgeMs:null,jobsRunningHere:!0,jobsOwnerPid:null,jobsOwnerRole:"dashboard",mechanism:"startup-supervisor",mode:"personal",installed:!1,startsAt:"logon",stoppedByUser:!1,stoppedAt:null,state:null,enabledOnBoot:null,restarts:0,crashLooping:!1,runtime:null,warnings:[],detail:"The service is not installed."}),e==="service-elevation"&&(t.backgroundService={...n,mechanism:"systemd",mode:null,installed:!0,startsAt:"boot"}),t}function q(e){const t=P(),n=T(),a=B(),i=C(),u=e==="dashboard"||e==="none"||e.startsWith("service-"),p=e==="setup"||e==="setupcode"||e==="setupcode-expired";return{scenario:e,authenticated:u,authMode:e==="none"?"none":"password",setupConfigured:!p,hasPassword:!p,domains:t,certs:O(),channels:M(),nginx:E(),configs:H(),errorLog:L(),accessLog:$(),processes:{...j(),apps:n},service:X(e),settings:{...i,dashboardAuth:e==="none"?"none":"password",canUseNoPassword:!0},hub:F(a),pendingDns:{}}}let d=null;function k(e){return`${G}:${e}`}function K(){if(d)return d;const e=U();try{const t=sessionStorage.getItem(k(e));if(t){const n=JSON.parse(t);if(n&&n.scenario===e)return d=n,d}}catch{}return d=q(e),V(),d}function V(){if(d)try{sessionStorage.setItem(k(d.scenario),JSON.stringify(d))}catch{}}const J=e=>structuredClone(e),x=new Set;function W(){try{return J(K().service.backgroundService)}catch{return null}}function Y(e){return x.add(e),()=>{x.delete(e)}}const S={running:!0,version:"1.24.0",pid:1421},_=[{name:"app.example.com",up:!0,port:3e3,host:"127.0.0.1"},{name:"api.example.com",up:!0,port:8080,host:"127.0.0.1"},{name:"blog.example.com",up:!1,port:4e3,host:"10.0.0.12"},{name:"staging.example.com",up:!0,port:5e3,host:"127.0.0.1"}];function D(e,t,n,a={}){return{id:`${e}-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,type:e,severity:t,message:n,timestamp:Date.now(),...a}}async function Q(){const e=new Map;let t=!1,n=[],a=[],i=null,u=0,p=null;const r=(s,o)=>{for(const l of e.get(s)??[])l(o)},I=(s,o)=>{const l=e.get(s)??new Set;l.add(o),e.set(s,l)},R=(s,o)=>{e.get(s)?.delete(o)},f=()=>{n.forEach(clearTimeout),n=[],a.forEach(clearInterval),a=[],i&&clearInterval(i),i=null};return{get connected(){return t},on(s,o){I(s,o)},off(s,o){R(s,o)},emit(s,o){if(s==="logs:unsubscribe"){i&&clearInterval(i),i=null;return}const l=o?.logFile==="access"?"access":"error";i&&clearInterval(i);for(let c=50;c>0;c-=1){const b=new Date(Date.now()-c*3e4).toISOString().replace("T"," ").slice(0,19);r("logs:line",{logFile:l,line:l==="access"?`10.0.0.${5+c%4} - - [${b}] "GET /health HTTP/1.1" 200 ${300+c} "-" "Mozilla/5.0"`:`${b} [warn] 1421#1421: *${100+c} an upstream response is buffered to a temporary file`})}i=setInterval(()=>{u+=1;const c=l==="access"?{line:`10.0.0.${5+u%4} - - [${new Date().toISOString()}] "GET / HTTP/1.1" 200 ${1e3+u*37} "-" "Mozilla/5.0"`,logFile:l}:{line:`${new Date().toISOString().replace("T"," ").slice(0,19)} [warn] 1421#1421: *${400+u} an upstream response is buffered to a temporary file`,logFile:l};r("logs:line",c)},900)},connect(){t||(f(),n.push(setTimeout(()=>{t=!0,r("connect",void 0),r("nginx:status",S),r("domain:health",_);const s=W();s&&r("service:changed",s),p?.(),p=Y(o=>{t&&r("service:changed",o)})},120),setTimeout(()=>{r("notification:new",D("nginx_down","success","Nginx is running again",{subtype:"recovery"}))},2200),setTimeout(()=>{r("notification:new",D("cert_expiry","warning","🔒 SSL cert for api.example.com expires in 12 days",{domain:"api.example.com"}))},5200)),a.push(setInterval(()=>{t&&r("nginx:status",S)},5e3),setInterval(()=>{t&&r("domain:health",_)},6e4)))},disconnect(){t&&(t=!1,f(),p?.(),p=null,r("disconnect",void 0))}}}export{Q as createMockSocket};
|
|
65
|
+
`}}function $(){const e=Date.now(),t=n=>new Date(e-n).toISOString().replace("T"," ").slice(0,19);return['2026/11/13 09:12:02 [notice] 1#1: using the "epoll" event method',"2026/11/13 09:12:02 [notice] 1#1: nginx/1.24.0","2026/11/13 09:12:02 [notice] 1#1: OS: Linux 6.8.0-45-generic",`${t(36e5)} [warn] 1421#1421: *241 an upstream response is buffered to a temporary file`,`${t(9e5)} [error] 1421#1421: *318 connect() failed (111: Connection refused) while connecting to upstream, client: 10.0.0.5, server: blog.example.com, request: "GET / HTTP/1.1", upstream: "http://10.0.0.12:4000/", host: "blog.example.com"`,`${t(24e4)} [warn] 1421#1421: *322 conflicting server name "staging.example.com" on 0.0.0.0:80, ignored`,`${t(3e4)} [error] 1421#1421: *330 open() "/var/www/easy-devops/.well-known/acme-challenge/test" failed (2: No such file or directory)`]}function H(){const e=Date.now(),t=n=>new Date(e-n).toISOString().replace("T"," ").replace("Z","");return[`10.0.0.5 - - [${t(12e4)}] "GET / HTTP/1.1" 200 4321 "-" "Mozilla/5.0"`,`10.0.0.8 - - [${t(9e4)}] "GET /api/health HTTP/1.1" 200 32 "-" "curl/8.5.0"`,`10.0.0.5 - - [${t(45e3)}] "POST /api/orders HTTP/1.1" 201 512 "-" "Mozilla/5.0"`,`10.0.0.9 - - [${t(2e4)}] "GET /assets/app.js HTTP/1.1" 200 18234 "https://app.example.com/" "Mozilla/5.0"`]}function k(){return[{name:"ez-dashboard",pmId:0,pid:2190,status:"online",cpu:1.2,memoryBytes:96468992,startedAt:Date.now()-2*864e5,uptimeMs:2*864e5,restarts:0,unstableRestarts:0,execPath:"/opt/easy-devops/src/cli/index.js",cwd:"/opt/easy-devops",user:"deploy",managed:!0,dataDir:"/var/lib/easy-devops"},{name:"api-worker",pmId:1,pid:2401,status:"online",cpu:2.4,memoryBytes:134217728,startedAt:Date.now()-6*36e5,uptimeMs:6*36e5,restarts:2,unstableRestarts:0,execPath:"/srv/api/worker.js",cwd:"/srv/api",user:"deploy",managed:!1,dataDir:null},{name:"legacy-app",pmId:2,pid:null,status:"stopped",cpu:null,memoryBytes:null,startedAt:null,uptimeMs:null,restarts:14,unstableRestarts:1,execPath:"/srv/legacy/server.js",cwd:"/srv/legacy",user:"deploy",managed:!1,dataDir:null},{name:"pm2-logrotate",pmId:3,pid:2502,status:"online",cpu:0,memoryBytes:0,startedAt:Date.now()-12*36e5,uptimeMs:12*36e5,restarts:1,unstableRestarts:0,execPath:"/home/deploy/.pm2/modules/pm2-logrotate/pm2-logrotate.js",cwd:"/home/deploy/.pm2/modules/pm2-logrotate",user:"deploy",managed:!1,dataDir:null}]}function j(){return{pm2:{installed:!0,version:"5.4.2",path:"/usr/local/bin/pm2"},apps:k(),currentUser:"deploy",pm2Home:"/home/deploy/.pm2"}}function N(){return{pm2:{installed:!0,version:"6.0.14",path:"/usr/local/bin/pm2"},dev:!1,dataDir:"/var/lib/easy-devops",backgroundService:{running:!0,connected:!0,pid:2190,version:"1.2.1",startedAt:Date.now()-2*864e5,heartbeatAgeMs:4e3,jobsRunningHere:!1,jobsOwnerPid:2190,jobsOwnerRole:"daemon",mechanism:"systemd",mode:null,installed:!0,startsAt:"boot",stoppedByUser:!1,stoppedAt:null,dataDir:"/var/lib/easy-devops",serverMode:!1,detail:null,state:"active",enabledOnBoot:!0,restarts:0,crashLooping:!1,warnings:[],runtime:{systemNode:{path:"/usr/bin/node",version:"v22.11.0",abi:"127"},pinned:{kind:"symlink",path:"/var/lib/easy-devops/runtime/node",target:"/usr/bin/node",version:"v22.11.0",exists:!0,broken:!1,differsFromSystem:!1},manager:{managed:!1,manager:null},mixed:{mixed:!1,msiPath:null,managed:null},warnings:[]}},install:{command:"ezz service install",needsElevation:!1,shell:null}}}function C(){return{dashboardPort:6443,nginxDir:"/etc/nginx",sslDir:"/etc/easy-devops/ssl",acmeEmail:"ops@example.com",sslAutoRenew:!0,sslAutoRenewDays:7,sslAutoRenewDaysMin:1,sslAutoRenewDaysMax:30,deployDir:"/home/ops/.config/easy-devops/ez_deploys",deployDirDefault:"/home/ops/.config/easy-devops/ez_deploys",deployDirIsDefault:!0,dashboardBindAddress:"127.0.0.1",bindsToLoopbackOnly:!0,dashboardAuth:"password",canUseNoPassword:!0,hasPassword:!0,platform:"linux"}}const h=[{id:"nginx",label:"Nginx",description:"Control the nginx service and its configuration files.",children:[{id:"nginx.start",label:"Start",description:"Start nginx when it is stopped."},{id:"nginx.stop",label:"Stop",description:"Stop nginx. Your sites go offline until it is started again."},{id:"nginx.restart",label:"Restart",description:"Full restart. Briefly drops connections."},{id:"nginx.reload",label:"Reload",description:"Graceful reload. Picks up config changes without dropping connections."},{id:"nginx.test",label:"Test config",description:"Run nginx -t. Read-only, changes nothing."},{id:"nginx.config.view",label:"View configs",description:"Read the generated nginx config files."},{id:"nginx.config.edit",label:"Edit configs",description:"Edit a config file. Always tested before it is kept, and rolled back if nginx rejects it."},{id:"nginx.logs.view",label:"View logs",description:"Read recent nginx access and error log lines."}]},{id:"domains",label:"Domains",description:"Manage reverse proxy domains and their nginx configs.",children:[{id:"domains.create",label:"Create",description:"Add a new domain and generate its nginx config."},{id:"domains.edit",label:"Edit",description:"Change an existing domain and regenerate its config."},{id:"domains.toggle",label:"Enable / disable",description:"Take a domain in or out of service without deleting it."},{id:"domains.delete",label:"Delete",description:"Remove a domain and its nginx config."}]},{id:"ssl",label:"SSL certificates",description:"Issue, renew and remove Let’s Encrypt certificates.",children:[{id:"ssl.renew",label:"Renew one",description:"Renew a single certificate. nginx keeps running."},{id:"ssl.renewAll",label:"Renew all expiring",description:"Renew every certificate expiring within 30 days."},{id:"ssl.issue",label:"Issue new",description:"Request a new certificate over HTTP-01. nginx keeps running."},{id:"ssl.delete",label:"Delete",description:"Delete certificate files. Refused while an enabled domain still uses them."},{id:"ssl.issueDns",label:"Issue wildcard (DNS-01)",description:"Wildcard certificates need a DNS TXT record you add by hand, so they cannot be driven from the Hub yet.",comingSoon:!0}]},{id:"deploy",label:"Deployments",description:"Deploy the apps on this server from the Hub. Fetching code and running its commands happens here, with this server’s own settings.",children:[{id:"deploy.run",label:"Deploy",description:"Start a deployment of an existing app from its configured repository."},{id:"deploy.rollback",label:"Roll back",description:"Switch an app back to an earlier release that is still on this server."},{id:"deploy.logs",label:"View deployment logs",description:"Read the output of a deployment. Build output can contain whatever the build prints."},{id:"deploy.manage",label:"Create, edit and delete apps",description:"Add an app from a repository, change its settings, issue its deploy token, or remove it. This decides which code runs here."},{id:"deploy.env",label:"Read and edit environment variables",description:"See and change an app’s environment values. They pass through the Hub while being edited and are not stored there."},{id:"deploy.ci",label:"Deploy from CI through the Hub",description:"Let a GitHub Action trigger a deployment by calling the Hub with the app’s own deploy token, so this server needs no inbound port."}]},{id:"process",label:"Processes",description:"Control the PM2 processes on this server. Easy DevOps itself runs as a background service, not a PM2 app, so it cannot be controlled from here.",children:[{id:"process.start",label:"Start",description:"Start a stopped PM2 process from the Hub."},{id:"process.stop",label:"Stop",description:"Stop a running PM2 process from the Hub."},{id:"process.restart",label:"Restart",description:"Restart a PM2 process from the Hub."}]},{id:"system",label:"System",description:"Server-level operations beyond nginx.",children:[{id:"system.nodeVersions",label:"Manage Node.js versions",description:"Install and switch Node.js versions through nvm.",comingSoon:!0},{id:"system.restartServer",label:"Reboot the server",description:"Reboot the whole machine.",comingSoon:!0}]}],z=h.flatMap(e=>e.children.filter(t=>t.comingSoon).map(t=>t.id));function B(){const e={};for(const t of h)for(const n of t.children)e[n.id]=!1;for(const t of["nginx.reload","nginx.test","nginx.config.view","nginx.logs.view","domains.create","domains.edit","domains.toggle","ssl.renew","ssl.renewAll"])e[t]=!0;return e}function F(e){return{linked:!0,hubUrl:"https://hub.example.com",serverId:"srv_demo_01",permissions:e,tree:h,comingSoon:z,connected:!0,status:"connected",lastError:null,attempts:0,agentOwner:"dashboard",agentReported:!0,dataDir:"/var/lib/easy-devops",devDataDir:!1}}const v=["dashboard","service-stopped","service-stopped-by-you","service-not-installed","service-elevation","login","setup","setupcode","setupcode-expired","none"],U="ez-mock-state-v5",w="ez-mock-scenario";function G(){try{const e=new URLSearchParams(window.location.search),t=window.location.hash.includes("?")?new URLSearchParams(window.location.hash.slice(window.location.hash.indexOf("?")+1)):null,n=e.get("mock")??t?.get("mock");if(n&&v.includes(n))return sessionStorage.setItem(w,n),n;const a=sessionStorage.getItem(w);if(a&&v.includes(a))return a}catch{}return"dashboard"}function X(e){const t=N(),n=t.backgroundService,a={command:"ezz service install",needsElevation:!1,shell:null};return e==="service-stopped"&&(t.backgroundService={...n,running:!1,connected:!1,pid:null,version:null,startedAt:null,heartbeatAgeMs:null,jobsRunningHere:!0,jobsOwnerPid:null,jobsOwnerRole:"dashboard",state:"inactive",detail:"The service is stopped."}),e==="service-stopped-by-you"&&(t.install=a,t.backgroundService={...n,running:!1,connected:!1,pid:null,version:null,startedAt:null,heartbeatAgeMs:null,jobsRunningHere:!0,jobsOwnerPid:null,jobsOwnerRole:"dashboard",mechanism:"startup-supervisor",mode:"personal",installed:!0,startsAt:"logon",stoppedByUser:!0,stoppedAt:new Date(Date.now()-36e5).toISOString(),state:null,enabledOnBoot:!0,detail:"The service is stopped.",runtime:{systemNode:{path:"C:\\Program Files\\nodejs\\node.exe",version:"v22.11.0",abi:"127"},pinned:{kind:"copy",path:"C:\\Users\\deploy\\AppData\\Local\\easy-devops\\runtime\\node.exe",version:"v20.18.1",exists:!0,broken:!1,differsFromSystem:!0},manager:{managed:!0,manager:"nvm-windows"},mixed:{mixed:!1,msiPath:null,managed:null},warnings:[]}}),e==="service-not-installed"&&(t.install=a,t.backgroundService={...n,running:!1,connected:!1,pid:null,version:null,startedAt:null,heartbeatAgeMs:null,jobsRunningHere:!0,jobsOwnerPid:null,jobsOwnerRole:"dashboard",mechanism:"startup-supervisor",mode:"personal",installed:!1,startsAt:"logon",stoppedByUser:!1,stoppedAt:null,state:null,enabledOnBoot:null,restarts:0,crashLooping:!1,runtime:null,warnings:[],detail:"The service is not installed."}),e==="service-elevation"&&(t.backgroundService={...n,mechanism:"systemd",mode:null,installed:!0,startsAt:"boot"}),t}function q(e){const t=P(),n=k(),a=B(),i=C(),u=e==="dashboard"||e==="none"||e.startsWith("service-"),p=e==="setup"||e==="setupcode"||e==="setupcode-expired";return{scenario:e,authenticated:u,authMode:e==="none"?"none":"password",setupConfigured:!p,hasPassword:!p,domains:t,certs:O(),channels:M(),nginx:E(),configs:L(),errorLog:$(),accessLog:H(),processes:{...j(),apps:n},service:X(e),settings:{...i,dashboardAuth:e==="none"?"none":"password",canUseNoPassword:!0},hub:F(a),update:{current:"1.3.4",latest:"1.3.5",reachable:!0,updateAvailable:!0,source:{kind:"npm",reason:"an npm-installed package at /usr/lib/node_modules/easy-devops",npmUpdatable:!0,howToUpdate:[]},run:null},pendingDns:{}}}let d=null;function T(e){return`${U}:${e}`}function K(){if(d)return d;const e=G();try{const t=sessionStorage.getItem(T(e));if(t){const n=JSON.parse(t);if(n&&n.scenario===e)return d=n,d}}catch{}return d=q(e),V(),d}function V(){if(d)try{sessionStorage.setItem(T(d.scenario),JSON.stringify(d))}catch{}}const J=e=>structuredClone(e),x=new Set;function W(){try{return J(K().service.backgroundService)}catch{return null}}function Y(e){return x.add(e),()=>{x.delete(e)}}const S={running:!0,version:"1.24.0",pid:1421},_=[{name:"app.example.com",up:!0,port:3e3,host:"127.0.0.1"},{name:"api.example.com",up:!0,port:8080,host:"127.0.0.1"},{name:"blog.example.com",up:!1,port:4e3,host:"10.0.0.12"},{name:"staging.example.com",up:!0,port:5e3,host:"127.0.0.1"}];function D(e,t,n,a={}){return{id:`${e}-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,type:e,severity:t,message:n,timestamp:Date.now(),...a}}async function Q(){const e=new Map;let t=!1,n=[],a=[],i=null,u=0,p=null;const r=(s,o)=>{for(const l of e.get(s)??[])l(o)},R=(s,o)=>{const l=e.get(s)??new Set;l.add(o),e.set(s,l)},I=(s,o)=>{e.get(s)?.delete(o)},f=()=>{n.forEach(clearTimeout),n=[],a.forEach(clearInterval),a=[],i&&clearInterval(i),i=null};return{get connected(){return t},on(s,o){R(s,o)},off(s,o){I(s,o)},emit(s,o){if(s==="logs:unsubscribe"){i&&clearInterval(i),i=null;return}const l=o?.logFile==="access"?"access":"error";i&&clearInterval(i);for(let c=50;c>0;c-=1){const b=new Date(Date.now()-c*3e4).toISOString().replace("T"," ").slice(0,19);r("logs:line",{logFile:l,line:l==="access"?`10.0.0.${5+c%4} - - [${b}] "GET /health HTTP/1.1" 200 ${300+c} "-" "Mozilla/5.0"`:`${b} [warn] 1421#1421: *${100+c} an upstream response is buffered to a temporary file`})}i=setInterval(()=>{u+=1;const c=l==="access"?{line:`10.0.0.${5+u%4} - - [${new Date().toISOString()}] "GET / HTTP/1.1" 200 ${1e3+u*37} "-" "Mozilla/5.0"`,logFile:l}:{line:`${new Date().toISOString().replace("T"," ").slice(0,19)} [warn] 1421#1421: *${400+u} an upstream response is buffered to a temporary file`,logFile:l};r("logs:line",c)},900)},connect(){t||(f(),n.push(setTimeout(()=>{t=!0,r("connect",void 0),r("nginx:status",S),r("domain:health",_);const s=W();s&&r("service:changed",s),p?.(),p=Y(o=>{t&&r("service:changed",o)})},120),setTimeout(()=>{r("notification:new",D("nginx_down","success","Nginx is running again",{subtype:"recovery"}))},2200),setTimeout(()=>{r("notification:new",D("cert_expiry","warning","🔒 SSL cert for api.example.com expires in 12 days",{domain:"api.example.com"}))},5200)),a.push(setInterval(()=>{t&&r("nginx:status",S)},5e3),setInterval(()=>{t&&r("domain:health",_)},6e4)))},disconnect(){t&&(t=!1,f(),p?.(),p=null,r("disconnect",void 0))}}}export{Q as createMockSocket};
|
package/dist/ui/index.html
CHANGED
|
@@ -62,8 +62,8 @@
|
|
|
62
62
|
}
|
|
63
63
|
})();
|
|
64
64
|
</script>
|
|
65
|
-
<script type="module" crossorigin src="./assets/index-
|
|
66
|
-
<link rel="stylesheet" crossorigin href="./assets/index-
|
|
65
|
+
<script type="module" crossorigin src="./assets/index-DD0JjK0Q.js"></script>
|
|
66
|
+
<link rel="stylesheet" crossorigin href="./assets/index-BUpPxWmp.css">
|
|
67
67
|
</head>
|
|
68
68
|
<body>
|
|
69
69
|
<div id="root"></div>
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "easy-devops",
|
|
3
|
-
"version": "1.3.
|
|
4
|
-
"description": "A unified DevOps management tool with CLI and web dashboard for managing Nginx, SSL certificates, and Node.js on Linux and Windows servers.",
|
|
3
|
+
"version": "1.3.5",
|
|
4
|
+
"description": "A unified DevOps management tool with CLI and web dashboard for managing Nginx, SSL certificates, deployment apps, and Node.js on Linux and Windows servers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"devops",
|
|
7
7
|
"nginx",
|
|
@@ -1,145 +1,18 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
import inquirer from 'inquirer';
|
|
3
3
|
import ora from 'ora';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import path from 'path';
|
|
11
|
-
import { loadConfig } from '../../core/config.js';
|
|
12
|
-
import { dbGet, dbSet } from '../../core/db.js';
|
|
13
|
-
import { getDataDir } from '../../core/platform.js';
|
|
4
|
+
import {
|
|
5
|
+
findFreePort,
|
|
6
|
+
getDashboardStatus,
|
|
7
|
+
startDashboard,
|
|
8
|
+
stopDashboard,
|
|
9
|
+
} from '../../core/dashboardProcess.js';
|
|
14
10
|
import { run } from '../../core/shell.js';
|
|
15
11
|
|
|
16
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
17
|
-
const isWindows = process.platform === 'win32';
|
|
18
|
-
// Principle IV: logs live in the user's data directory, never inside the
|
|
19
|
-
// package — a package-relative path is wiped by `npm update`. Follows
|
|
20
|
-
// EASY_DEVOPS_DATA_DIR in dev mode like the database and sessions do.
|
|
21
|
-
const LOG_PATH = path.join(getDataDir(), 'logs', 'dashboard.log');
|
|
22
|
-
const SERVER_PATH = path.resolve(__dirname, '../../dashboard/server.js');
|
|
23
|
-
|
|
24
|
-
// ─── Port helpers ─────────────────────────────────────────────────────────────
|
|
25
|
-
|
|
26
|
-
function isPortFree(port) {
|
|
27
|
-
return new Promise((resolve) => {
|
|
28
|
-
const srv = createServer();
|
|
29
|
-
srv.once('error', () => resolve(false));
|
|
30
|
-
srv.once('listening', () => srv.close(() => resolve(true)));
|
|
31
|
-
srv.listen(port, '127.0.0.1');
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async function findFreePort(startPort) {
|
|
36
|
-
let port = startPort;
|
|
37
|
-
while (!(await isPortFree(port))) {
|
|
38
|
-
port++;
|
|
39
|
-
if (port > 65535) throw new Error('No free port found');
|
|
40
|
-
}
|
|
41
|
-
return port;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// ─── HTTP ping — most reliable way to know Express is actually up ─────────────
|
|
45
|
-
|
|
46
|
-
function httpPing(port, timeoutMs = 2000) {
|
|
47
|
-
return new Promise((resolve) => {
|
|
48
|
-
const req = http.get(`http://localhost:${port}/`, (res) => {
|
|
49
|
-
res.destroy();
|
|
50
|
-
resolve(true);
|
|
51
|
-
});
|
|
52
|
-
req.on('error', () => resolve(false));
|
|
53
|
-
req.setTimeout(timeoutMs, () => { req.destroy(); resolve(false); });
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Poll every 500 ms for up to `maxWaitMs`
|
|
58
|
-
async function waitForServer(port, maxWaitMs = 8000) {
|
|
59
|
-
const deadline = Date.now() + maxWaitMs;
|
|
60
|
-
while (Date.now() < deadline) {
|
|
61
|
-
if (await httpPing(port, 1000)) return true;
|
|
62
|
-
await new Promise(r => setTimeout(r, 500));
|
|
63
|
-
}
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// ─── PID check ────────────────────────────────────────────────────────────────
|
|
68
|
-
|
|
69
|
-
function isPidAlive(pid) {
|
|
70
|
-
if (!pid) return false;
|
|
71
|
-
try { process.kill(pid, 0); return true; } catch { return false; }
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// ─── Status ───────────────────────────────────────────────────────────────────
|
|
75
|
-
|
|
76
|
-
export async function getDashboardStatus() {
|
|
77
|
-
const { dashboardPort } = loadConfig();
|
|
78
|
-
const storedPid = dbGet('dashboard-pid');
|
|
79
|
-
const storedPort = dbGet('dashboard-port') ?? dashboardPort;
|
|
80
|
-
const pidAlive = isPidAlive(storedPid);
|
|
81
|
-
const responding = pidAlive && await httpPing(storedPort, 1000);
|
|
82
|
-
|
|
83
|
-
if (storedPid && !responding) {
|
|
84
|
-
dbSet('dashboard-pid', null);
|
|
85
|
-
dbSet('dashboard-port', null);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return {
|
|
89
|
-
running: responding,
|
|
90
|
-
port: storedPort,
|
|
91
|
-
configPort: dashboardPort,
|
|
92
|
-
pid: responding ? storedPid : null,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// ─── Start ────────────────────────────────────────────────────────────────────
|
|
97
|
-
|
|
98
|
-
export async function startDashboard(port) {
|
|
99
|
-
await fs.mkdir(path.dirname(LOG_PATH), { recursive: true });
|
|
100
|
-
|
|
101
|
-
// openSync gives a real fd immediately — required by spawn's stdio option
|
|
102
|
-
const logFd = openSync(LOG_PATH, 'a');
|
|
103
|
-
writeSync(logFd, `\n--- dashboard start ${new Date().toISOString()} port=${port} ---\n`);
|
|
104
|
-
|
|
105
|
-
const child = spawn(process.execPath, [SERVER_PATH], {
|
|
106
|
-
detached: true,
|
|
107
|
-
stdio: ['ignore', logFd, logFd],
|
|
108
|
-
windowsHide: true,
|
|
109
|
-
env: { ...process.env, DASHBOARD_PORT: String(port) },
|
|
110
|
-
});
|
|
111
|
-
child.unref();
|
|
112
|
-
// Parent closes its copy of the fd; the child keeps its own inherited copy
|
|
113
|
-
closeSync(logFd);
|
|
114
|
-
|
|
115
|
-
dbSet('dashboard-pid', child.pid);
|
|
116
|
-
dbSet('dashboard-port', port);
|
|
117
|
-
|
|
118
|
-
// Wait up to 8 s for Express to respond (polls every 500 ms)
|
|
119
|
-
const up = await waitForServer(port, 8000);
|
|
120
|
-
return { success: up, pid: child.pid, port, logPath: LOG_PATH };
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// ─── Stop ─────────────────────────────────────────────────────────────────────
|
|
124
|
-
|
|
125
|
-
export async function stopDashboard(pid) {
|
|
126
|
-
if (!pid) return { success: false };
|
|
127
|
-
try {
|
|
128
|
-
if (isWindows) {
|
|
129
|
-
await run(`taskkill /PID ${pid} /F`);
|
|
130
|
-
} else {
|
|
131
|
-
process.kill(pid, 'SIGTERM');
|
|
132
|
-
}
|
|
133
|
-
} catch { /* already gone */ }
|
|
134
|
-
dbSet('dashboard-pid', null);
|
|
135
|
-
dbSet('dashboard-port', null);
|
|
136
|
-
return { success: true };
|
|
137
|
-
}
|
|
138
|
-
|
|
139
12
|
// ─── Browser ──────────────────────────────────────────────────────────────────
|
|
140
13
|
|
|
141
14
|
function openBrowser(url) {
|
|
142
|
-
const cmd =
|
|
15
|
+
const cmd = process.platform === 'win32' ? `Start-Process "${url}"` : `xdg-open "${url}"`;
|
|
143
16
|
run(cmd).catch(() => {});
|
|
144
17
|
}
|
|
145
18
|
|
package/src/cli/menus/update.js
CHANGED
|
@@ -13,8 +13,10 @@
|
|
|
13
13
|
* key that lets a crash mid-update still bring the dashboard back on the next
|
|
14
14
|
* launch.
|
|
15
15
|
*
|
|
16
|
-
* Nothing
|
|
16
|
+
* Nothing in this file runs from the Hub, and `whyCliOnly()` in
|
|
17
17
|
* core/updater.js is what explains that to the user rather than a comment.
|
|
18
|
+
* The dashboard has its own entry point for the same flow —
|
|
19
|
+
* dashboard/updateWorker.js — which is why this file owns only the CLI side.
|
|
18
20
|
*/
|
|
19
21
|
|
|
20
22
|
import chalk from 'chalk';
|
|
@@ -22,27 +24,9 @@ import inquirer from 'inquirer';
|
|
|
22
24
|
import ora from 'ora';
|
|
23
25
|
import { dbGet, dbSet } from '../../core/db.js';
|
|
24
26
|
import { loadConfig } from '../../core/config.js';
|
|
25
|
-
import { getDashboardStatus, startDashboard, stopDashboard } from '
|
|
26
|
-
import { run } from '../../core/shell.js';
|
|
27
|
+
import { getDashboardStatus, startDashboard, stopDashboard } from '../../core/dashboardProcess.js';
|
|
27
28
|
|
|
28
29
|
|
|
29
|
-
// ─── Version helpers ──────────────────────────────────────────────────────────
|
|
30
|
-
|
|
31
|
-
async function fetchLatestVersion() {
|
|
32
|
-
const result = await run('npm view easy-devops version', { timeout: 20000 });
|
|
33
|
-
if (result.success && result.stdout.trim()) return result.stdout.trim();
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function isNewer(latest, current) {
|
|
38
|
-
const parse = v => v.replace(/^v/, '').split('.').map(Number);
|
|
39
|
-
const [la, lb, lc] = parse(latest);
|
|
40
|
-
const [ca, cb, cc] = parse(current);
|
|
41
|
-
if (la !== ca) return la > ca;
|
|
42
|
-
if (lb !== cb) return lb > cb;
|
|
43
|
-
return lc > cc;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
30
|
// ─── Recover interrupted update ───────────────────────────────────────────────
|
|
47
31
|
// If a previous update crashed after stopping the dashboard but before restarting
|
|
48
32
|
// it, the key 'update-pre-dashboard' is still set. Offer to restart it.
|
|
@@ -79,36 +63,18 @@ async function recoverIfNeeded() {
|
|
|
79
63
|
dbSet('update-pre-dashboard', null);
|
|
80
64
|
}
|
|
81
65
|
|
|
82
|
-
// ───
|
|
66
|
+
// ─── Detached dashboard ───────────────────────────────────────────────────────
|
|
83
67
|
|
|
84
68
|
/**
|
|
85
|
-
*
|
|
69
|
+
* Persists the dashboard state, stops it, runs `fn`, and starts it again.
|
|
86
70
|
*
|
|
87
|
-
* The
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* What stays here is the detached dashboard, which is a CLI concept, and the
|
|
94
|
-
* recovery key that survives a crash mid-update.
|
|
71
|
+
* The state is written *before* the stop, so a crash in between leaves the
|
|
72
|
+
* `update-pre-dashboard` key behind and `recoverIfNeeded()` finishes the job on
|
|
73
|
+
* the next launch. Both entry points go through here — `ezz update`, and the
|
|
74
|
+
* menu, which now simply calls it — so neither can stop the dashboard and
|
|
75
|
+
* forget to bring it back.
|
|
95
76
|
*/
|
|
96
|
-
async function
|
|
97
|
-
const updater = await import('../../core/updater.js');
|
|
98
|
-
const { detectInstallSource, describeUnmanaged } = await import('../../core/installSource.js');
|
|
99
|
-
|
|
100
|
-
const source = detectInstallSource();
|
|
101
|
-
if (!source.npmUpdatable) {
|
|
102
|
-
console.log();
|
|
103
|
-
for (const line of describeUnmanaged(source, 'update')) console.log(' ' + chalk.gray(line));
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
for (const line of updater.whyCliOnly()) console.log(' ' + chalk.gray(line));
|
|
108
|
-
console.log();
|
|
109
|
-
|
|
110
|
-
// Step 1 — the dashboard's state, persisted so a crash mid-update can still
|
|
111
|
-
// bring it back on the next launch (recoverIfNeeded above).
|
|
77
|
+
async function withDashboardStopped(fn) {
|
|
112
78
|
const status = await getDashboardStatus();
|
|
113
79
|
dbSet('update-pre-dashboard', {
|
|
114
80
|
wasRunning: status.running,
|
|
@@ -118,44 +84,58 @@ async function performUpdate(latestVersion) {
|
|
|
118
84
|
});
|
|
119
85
|
|
|
120
86
|
if (status.running) {
|
|
121
|
-
const sp = ora('Stopping dashboard...').start();
|
|
87
|
+
const sp = ora('Stopping the dashboard...').start();
|
|
122
88
|
await stopDashboard(status.pid);
|
|
123
89
|
sp.succeed('Dashboard stopped');
|
|
124
90
|
}
|
|
125
91
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const saved = dbGet('update-pre-dashboard');
|
|
134
|
-
dbSet('update-pre-dashboard', null);
|
|
135
|
-
|
|
136
|
-
if (saved?.wasRunning) {
|
|
137
|
-
const port = saved.port || loadConfig().dashboardPort;
|
|
138
|
-
const sp = ora(`Restarting dashboard on port ${port}...`).start();
|
|
139
|
-
const back = await startDashboard(port);
|
|
140
|
-
back.success
|
|
141
|
-
? sp.succeed(`Dashboard restarted on port ${port}`)
|
|
142
|
-
: sp.fail('Could not restart dashboard — use the Dashboard menu');
|
|
143
|
-
}
|
|
92
|
+
try {
|
|
93
|
+
return await fn();
|
|
94
|
+
} finally {
|
|
95
|
+
// Cleared before the restart: if the restart itself crashes, the next
|
|
96
|
+
// launch must not start a second dashboard on the same port.
|
|
97
|
+
const saved = dbGet('update-pre-dashboard');
|
|
98
|
+
dbSet('update-pre-dashboard', null);
|
|
144
99
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
100
|
+
if (saved?.wasRunning) {
|
|
101
|
+
const port = saved.port || loadConfig().dashboardPort;
|
|
102
|
+
const sp = ora(`Starting the dashboard on port ${port}...`).start();
|
|
103
|
+
const back = await startDashboard(port);
|
|
104
|
+
back.success
|
|
105
|
+
? sp.succeed(`Dashboard running on port ${port}`)
|
|
106
|
+
: sp.fail('Could not start the dashboard - use the Dashboard menu');
|
|
149
107
|
}
|
|
150
|
-
return true;
|
|
151
108
|
}
|
|
109
|
+
}
|
|
152
110
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
111
|
+
// ─── Post-update check ────────────────────────────────────────────────────────
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Says so when a daemon this command did not start is still on the old code.
|
|
115
|
+
*
|
|
116
|
+
* Replacing the files does not replace a running process: a daemon started
|
|
117
|
+
* from another terminal keeps the code it loaded until it is restarted. Telling
|
|
118
|
+
* the user is the whole fix — killing a process another terminal owns is not
|
|
119
|
+
* this command's call, and that pid may be an interactive session.
|
|
120
|
+
*
|
|
121
|
+
* @param {string} targetVersion The version the files on disk now carry
|
|
122
|
+
*/
|
|
123
|
+
async function warnStaleDaemon(targetVersion) {
|
|
124
|
+
const updater = await import('../../core/updater.js');
|
|
125
|
+
const { inspect } = await import('../../core/daemon/lock.js');
|
|
126
|
+
|
|
127
|
+
const state = inspect();
|
|
128
|
+
if (!state.running || !state.lock) return;
|
|
129
|
+
|
|
130
|
+
const running = state.lock.version;
|
|
131
|
+
if (running && updater.compareVersions(running, targetVersion) === 0) return;
|
|
132
|
+
|
|
133
|
+
console.log();
|
|
134
|
+
console.log(' ' + chalk.yellow(
|
|
135
|
+
`A daemon this command did not start is still running${running ? ` v${running}` : ''} (pid ${state.lock.pid}).`
|
|
136
|
+
));
|
|
137
|
+
console.log(' ' + chalk.gray('The files on disk are now the new version, but a running process keeps the code it loaded.'));
|
|
138
|
+
console.log(' ' + chalk.gray('Restart it from the terminal that started it (stop it there, then run `ezz daemon`).'));
|
|
159
139
|
}
|
|
160
140
|
|
|
161
141
|
// ─── `ezz update` ─────────────────────────────────────────────────────────────
|
|
@@ -240,31 +220,17 @@ export async function updateCommand({ yes = false } = {}) {
|
|
|
240
220
|
}
|
|
241
221
|
|
|
242
222
|
// A detached dashboard runs the jobs while no service does, and it is
|
|
243
|
-
// running the code npm is about to replace. Stopped
|
|
244
|
-
//
|
|
245
|
-
const dash = await getDashboardStatus();
|
|
246
|
-
if (dash.running) {
|
|
247
|
-
const sp = ora('Stopping the dashboard...').start();
|
|
248
|
-
await stopDashboard(dash.pid);
|
|
249
|
-
sp.succeed('Dashboard stopped');
|
|
250
|
-
}
|
|
251
|
-
|
|
223
|
+
// running the code npm is about to replace. Stopped and started again around
|
|
224
|
+
// the update, with the recovery key that covers a crash in between.
|
|
252
225
|
console.log();
|
|
253
|
-
const result = await
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
226
|
+
const result = await withDashboardStopped(() =>
|
|
227
|
+
updater.performUpdate({
|
|
228
|
+
version: check.latest,
|
|
229
|
+
log: (line) => console.log(' ' + chalk.gray(line)),
|
|
230
|
+
})
|
|
231
|
+
);
|
|
257
232
|
console.log();
|
|
258
233
|
|
|
259
|
-
if (dash.running) {
|
|
260
|
-
const port = dash.port || loadConfig().dashboardPort;
|
|
261
|
-
const sp = ora(`Starting the dashboard on port ${port}...`).start();
|
|
262
|
-
const back = await startDashboard(port);
|
|
263
|
-
back.success
|
|
264
|
-
? sp.succeed(`Dashboard running on port ${port}`)
|
|
265
|
-
: sp.fail('Could not start the dashboard - use the Dashboard menu');
|
|
266
|
-
}
|
|
267
|
-
|
|
268
234
|
if (result.ok) {
|
|
269
235
|
console.log(' ' + chalk.green(`Updated v${result.from} -> v${result.to}.`));
|
|
270
236
|
if (result.serviceInstalled) {
|
|
@@ -277,6 +243,7 @@ export async function updateCommand({ yes = false } = {}) {
|
|
|
277
243
|
console.log(' ' + chalk.gray('The ProgramData runtime copy was refreshed, so the service runs the new code.'));
|
|
278
244
|
}
|
|
279
245
|
}
|
|
246
|
+
await warnStaleDaemon(result.to);
|
|
280
247
|
console.log();
|
|
281
248
|
return 0;
|
|
282
249
|
}
|
|
@@ -304,56 +271,29 @@ export async function updateCommand({ yes = false } = {}) {
|
|
|
304
271
|
|
|
305
272
|
// ─── Menu ─────────────────────────────────────────────────────────────────────
|
|
306
273
|
|
|
274
|
+
/**
|
|
275
|
+
* The menu's "Check for Updates".
|
|
276
|
+
*
|
|
277
|
+
* Deliberately a front for `updateCommand` and not a second implementation:
|
|
278
|
+
* the old version here kept calling helpers that no longer existed and threw a
|
|
279
|
+
* ReferenceError the moment the item was chosen. One flow, one place to fix.
|
|
280
|
+
*/
|
|
307
281
|
export default async function updateMenu() {
|
|
308
|
-
//
|
|
282
|
+
// A crashed previous update is finished before another one is offered.
|
|
309
283
|
await recoverIfNeeded();
|
|
310
284
|
|
|
311
|
-
|
|
312
|
-
const latestVersion = await fetchLatestVersion();
|
|
313
|
-
spinner.stop();
|
|
314
|
-
|
|
315
|
-
console.log(chalk.bold('\n Check for Updates'));
|
|
316
|
-
console.log(chalk.gray(' ' + '─'.repeat(40)));
|
|
317
|
-
console.log(` Current version : ${chalk.cyan('v' + currentVersion)}`);
|
|
318
|
-
|
|
319
|
-
if (!latestVersion) {
|
|
320
|
-
console.log(chalk.yellow(' Could not reach npm registry. Check your internet connection.\n'));
|
|
321
|
-
await inquirer.prompt([{ type: 'input', name: '_', message: 'Press Enter to go back...' }]);
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
const updateAvailable = check.updateAvailable;
|
|
326
|
-
|
|
327
|
-
if (updateAvailable) {
|
|
328
|
-
console.log(` Latest version : ${chalk.green('v' + latestVersion)} ${chalk.yellow('← update available')}\n`);
|
|
329
|
-
} else {
|
|
330
|
-
console.log(` Latest version : ${chalk.green('v' + latestVersion)} ${chalk.gray('✓ up to date')}\n`);
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
const choices = updateAvailable
|
|
334
|
-
? [`Update to v${latestVersion}`, new inquirer.Separator(), '← Back']
|
|
335
|
-
: ['← Back'];
|
|
336
|
-
|
|
337
|
-
let choice;
|
|
285
|
+
let code;
|
|
338
286
|
try {
|
|
339
|
-
|
|
340
|
-
type: 'list',
|
|
341
|
-
name: 'choice',
|
|
342
|
-
message: 'Select an option:',
|
|
343
|
-
choices,
|
|
344
|
-
}]));
|
|
287
|
+
code = await updateCommand();
|
|
345
288
|
} catch (err) {
|
|
346
289
|
if (err.name === 'ExitPromptError') return;
|
|
347
290
|
throw err;
|
|
348
291
|
}
|
|
349
292
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
await inquirer.prompt([{ type: 'input', name: '_', message: 'Press Enter to continue...' }]);
|
|
357
|
-
} catch { /* ExitPromptError */ }
|
|
358
|
-
}
|
|
293
|
+
// Dismissed at the confirmation prompt: nothing ran, nothing to read.
|
|
294
|
+
if (code === 2) return;
|
|
295
|
+
|
|
296
|
+
try {
|
|
297
|
+
await inquirer.prompt([{ type: 'input', name: '_', message: 'Press Enter to continue...' }]);
|
|
298
|
+
} catch { /* ExitPromptError on the pause */ }
|
|
359
299
|
}
|
package/src/core/daemon/run.js
CHANGED
|
@@ -136,7 +136,13 @@ export async function startDaemon({
|
|
|
136
136
|
const handle = {
|
|
137
137
|
ok: true,
|
|
138
138
|
ipcPath: ipc?.path ?? null,
|
|
139
|
-
state: () => ({
|
|
139
|
+
state: () => ({
|
|
140
|
+
...jobs.state(),
|
|
141
|
+
version,
|
|
142
|
+
pid: process.pid,
|
|
143
|
+
ipcPath: ipc?.path ?? null,
|
|
144
|
+
hub: getHubAgentStatus(),
|
|
145
|
+
}),
|
|
140
146
|
|
|
141
147
|
/** Idempotent: a second signal while shutting down must not run it twice. */
|
|
142
148
|
stop() {
|