Offer unmanaged host sites on Services

When this server's nginx serves sites no service accounts for,
Services shows an Adopt button with the count; the dialog lists
each site with what was detected and adopts it in one click. The
button is absent on a host with nothing to adopt, so the top bar
stays quiet. Host-managed rows drop the start/stop controls and
the detail page names how they are run.

Part of #269.
This commit is contained in:
Juan Denis committed 2026-11-22 02:10:36 -05:00
1 parent 933216e911
commit 7bc25e54c3
7 files changed
+292 -4

No files matched your search

@@ -0,0 +1,131 @@
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
import api from '@/services/api';
import Modal from '@/components/Modal';
import { Button } from '@/components/ui/button';
import { Pill } from '@/components/ds';
import { useToast } from '@/contexts/useToast.js';
import { toastError } from '@/utils/errorMessage';
// Sites host nginx is serving that no service accounts for. Each row shows
// what discovery found; adopting records the site as it is. Nothing on the
// server is rewritten, which the dialog says in so many words because that is
// the question anyone with a live site asks first.
export default function AdoptSitesDialog({ open, onClose, sites, onAdopted }) {
const { t } = useTranslation();
const toast = useToast();
const [adopting, setAdopting] = useState(null);
const kindLabel = (site) => ({
wordpress: t('app.services.adopt.kindWordpress', 'WordPress'),
php: t('app.services.adopt.kindPhp', 'PHP'),
static: t('app.services.adopt.kindStatic', 'Static'),
}[site.app_type] || (site.kind === 'proxy'
? t('app.services.adopt.kindProxy', 'Proxied app')
: t('app.services.adopt.kindRedirect', 'Redirect')));
async function handleAdopt(site) {
setAdopting(site.id);
try {
const result = await api.adoptHostSite(site.id, { apply: true });
toast.success(t('app.services.adopt.adopted', {
name: result?.app?.name || site.primary_domain,
defaultValue: '{{name}} is now managed. Nothing on the server was changed.',
}));
await onAdopted?.(result?.app);
} catch (err) {
toastError(toast, t('app.services.adopt.failed', "Couldn't adopt this site."), err);
} finally {
setAdopting(null);
}
}
return (
<Modal
open={open}
onClose={onClose}
size="lg"
title={t('app.services.adopt.title', 'Adopt existing sites')}
footer={(
<Button type="button" variant="outline" onClick={onClose}>
{t('common.actions.close', 'Close')}
</Button>
)}
>
<p className="sk-modal__subtitle">
{t('app.services.adopt.intro', 'These sites are served by this server but are not managed here yet, so they have no monitoring, backups or SSL status. Adopting one records it as it is: the nginx config, PHP-FPM pool, database and certificate are left exactly as they are.')}
</p>
<ul className="adopt-sites">
{sites.map((site) => (
<li key={site.id} className="adopt-sites__row">
<div className="adopt-sites__main">
<div className="adopt-sites__head">
<span className="adopt-sites__domain">{site.primary_domain}</span>
<Pill kind={site.adoptable ? 'cyan' : 'gray'} dot={false}>{kindLabel(site)}</Pill>
</div>
<dl className="adopt-sites__facts">
{site.domains.length > 1 && (
<>
<dt>{t('app.services.adopt.alsoServes', 'Also serves')}</dt>
<dd>{site.domains.slice(1).join(', ')}</dd>
</>
)}
{site.root && (
<>
<dt>{t('app.services.adopt.root', 'Document root')}</dt>
<dd>{site.root}</dd>
</>
)}
{site.php && (
<>
<dt>{t('app.services.adopt.php', 'PHP-FPM')}</dt>
<dd>
{site.php.version || t('app.services.adopt.unknownVersion', 'Unknown version')}
{site.php.pool ? ` · ${site.php.pool}` : ''}
</dd>
</>
)}
{site.upstream && (
<>
<dt>{t('app.services.adopt.upstream', 'Proxies to')}</dt>
<dd>{site.upstream}</dd>
</>
)}
{site.database && (
<>
<dt>{t('app.services.adopt.database', 'Database')}</dt>
<dd>{site.database.name}</dd>
</>
)}
<dt>{t('app.services.adopt.certificate', 'Certificate')}</dt>
<dd>
{site.ssl.enabled
? site.ssl.certificate
: t('app.services.adopt.noCertificate', 'None')}
</dd>
<dt>{t('app.services.adopt.vhost', 'nginx config')}</dt>
<dd>{site.vhost_file}</dd>
</dl>
{!site.adoptable && site.reason && (
<p className="adopt-sites__reason">{site.reason}</p>
)}
</div>
{site.adoptable && (
<Button
type="button"
size="sm"
onClick={() => handleAdopt(site)}
disabled={adopting !== null}
>
{adopting === site.id
? t('app.services.adopt.adopting', 'Adopting…')
: t('app.services.adopt.action', 'Adopt')}
</Button>
)}
</li>
))}
</ul>
</Modal>
);
}
+25
View File
@@ -6005,6 +6005,7 @@
"failedToLoadVersions": "Couldn't load versions.",
"failedToRollback": "Couldn't roll back.",
"failedToUploadNewVersion": "Couldn't upload the new version.",
"hostManaged": "Host nginx",
"loadingService": "Loading service",
"loadingVersions": "Loading versions…",
"localService": "Local service",
@@ -6051,6 +6052,30 @@
"wordpress": "WordPress"
},
"services": {
"adopt": {
"action": "Adopt",
"adopted": "{{name}} is now managed. Nothing on the server was changed.",
"adopting": "Adopting…",
"alsoServes": "Also serves",
"button": "Adopt ({{count}})",
"buttonTitle": "Sites running on this server that are not managed here yet",
"certificate": "Certificate",
"database": "Database",
"failed": "Couldn't adopt this site.",
"intro": "These sites are served by this server but are not managed here yet, so they have no monitoring, backups or SSL status. Adopting one records it as it is: the nginx config, PHP-FPM pool, database and certificate are left exactly as they are.",
"kindPhp": "PHP",
"kindProxy": "Proxied app",
"kindRedirect": "Redirect",
"kindStatic": "Static",
"kindWordpress": "WordPress",
"noCertificate": "None",
"php": "PHP-FPM",
"root": "Document root",
"title": "Adopt existing sites",
"unknownVersion": "Unknown version",
"upstream": "Proxies to",
"vhost": "nginx config"
},
"assignSelected_one": "Assign 1 selected service to a project and environment, or leave it unassigned.",
"assignSelected_other": "Assign {{count}} selected services to a project and environment, or leave them unassigned.",
"bulkRestartSent_one": "Restart sent to 1 service",
+9 -1
View File
@@ -476,7 +476,7 @@ const ServiceDetail = () => {
{service.managed_by && (
<>
<span className="svc-detail__repo-arrow">&rarr;</span>
<span className="svc-detail__repo-branch">{service.managed_by === 'docker_compose' ? t('app.serviceDetail.dockerCompose', 'Docker Compose') : 'systemd'}</span>
<span className="svc-detail__repo-branch">{managedByLabel(service.managed_by, t)}</span>
</>
)}
</span>
@@ -585,6 +585,14 @@ const ServiceDetail = () => {
);
};
// How a locally registered service is run. `host` is a site that was already
// being served by this server's nginx when it was adopted.
function managedByLabel(managedBy, t) {
if (managedBy === 'docker_compose') return t('app.serviceDetail.dockerCompose', 'Docker Compose');
if (managedBy === 'host') return t('app.serviceDetail.hostManaged', 'Host nginx');
return 'systemd';
}
function extractRepoDisplay(url) {
if (!url) return '';
try {
+47 -3
View File
@@ -1,6 +1,6 @@
import { useCallback, useState, useEffect, useMemo } from 'react';
import { useNavigate, Link } from 'react-router-dom';
import { Layers, Plus, Square, Play, RotateCw, GitBranch, FolderOpen, FileArchive, FolderKanban, ArrowDownToLine } from 'lucide-react';
import { Layers, Plus, Square, Play, RotateCw, GitBranch, FolderOpen, FileArchive, FolderKanban, ArrowDownToLine, ScanSearch } from 'lucide-react';
import { SiGithub as Github } from 'react-icons/si';
import api from '../services/api';
import { useToast } from '../contexts/useToast.js';
@@ -23,6 +23,8 @@ import {
} from '@/components/ui/select';
import Modal from '@/components/Modal';
import RequiresDocker from '../components/RequiresDocker';
import AdoptSitesDialog from '@/components/apps/AdoptSitesDialog';
import { useAuth } from '@/contexts/useAuth.js';
import { useTranslation } from 'react-i18next';
import { toastError } from '@/utils/errorMessage';
import { translateLabel } from '@/i18n/labels';
@@ -120,6 +122,22 @@ const Services = () => {
const [bulkLoading, setBulkLoading] = useState(false);
const [showMoveDialog, setShowMoveDialog] = useState(false);
const [bandwidth, setBandwidth] = useState({});
const { isAdmin } = useAuth();
// Sites this server's nginx is serving that no service accounts for.
const [unmanagedSites, setUnmanagedSites] = useState([]);
const [showAdoptDialog, setShowAdoptDialog] = useState(false);
// Best-effort and admin-only (the endpoint reads host config): a failure
// just means the Adopt button does not appear.
const loadUnmanagedSites = useCallback(async () => {
if (!isAdmin) return;
try {
const data = await api.getHostSites();
setUnmanagedSites((data?.sites || []).filter((site) => !site.linked_app && site.kind !== 'redirect'));
} catch {
setUnmanagedSites([]);
}
}, [isAdmin]);
const loadApps = useCallback(async () => {
try {
@@ -141,6 +159,10 @@ const Services = () => {
.catch(() => {});
}, [loadApps]);
useEffect(() => {
loadUnmanagedSites();
}, [loadUnmanagedSites]);
async function handleAction(e, appId, action) {
e.stopPropagation();
@@ -203,6 +225,17 @@ const Services = () => {
useTopbarActions(() =>
<>
{unmanagedSites.length > 0 && (
<Button
variant="outline"
size="sm"
onClick={() => setShowAdoptDialog(true)}
title={t('app.services.adopt.buttonTitle', 'Sites running on this server that are not managed here yet')}
>
<ScanSearch size={16} />
{t('app.services.adopt.button', { count: unmanagedSites.length, defaultValue: 'Adopt ({{count}})' })}
</Button>
)}
<Button variant="outline" size="sm" asChild title={t('app.services.importASite', 'Import a site')}>
<Link to="/imports" aria-label={t('app.services.importASite', 'Import a site')}>
<ArrowDownToLine size={16} />
@@ -221,7 +254,7 @@ const Services = () => {
placeholder={t('app.services.searchServices', 'Search services…')}
/>
</>,
[searchTerm]
[searchTerm, unmanagedSites.length]
);
const toggleOne = (id, checked) => {
@@ -374,6 +407,9 @@ const Services = () => {
sortable: false,
hideable: false,
render: (app) => {
// A host-managed site is served by the server's own nginx and
// PHP-FPM: there is nothing per-site to start or stop.
if (app.managed_by === 'host') return null;
const isRunning = app.status === 'running';
return (
<div className="services-page__actions" onClick={(e) => e.stopPropagation()}>
@@ -414,7 +450,7 @@ const Services = () => {
items={filteredApps}
columns={columns}
keyField="id"
onRowClick={(app) => navigate(app.app_type === 'wordpress' ? `/wordpress/${app.id}` : `/services/${app.id}`)}
onRowClick={(app) => navigate(app.app_type === 'wordpress' && app.managed_by !== 'host' ? `/wordpress/${app.id}` : `/services/${app.id}`)}
selectable
selectedIds={selectedIds}
onToggleSelect={toggleOne}
@@ -447,6 +483,14 @@ const Services = () => {
filteredEmptyTitle={t('app.services.noServicesFound', 'No services found')}
filteredEmptyDescription={t('app.services.tryAdjustingFilter', 'Try adjusting your search or filter')}
>
<AdoptSitesDialog
open={showAdoptDialog && unmanagedSites.length > 0}
onClose={() => setShowAdoptDialog(false)}
sites={unmanagedSites}
onAdopted={async () => {
await Promise.all([loadApps(), loadUnmanagedSites()]);
}}
/>
<MoveToProjectDialog
open={showMoveDialog}
onOpenChange={setShowMoveDialog}
+2
View File
@@ -36,6 +36,7 @@ import * as speedTestMethods from './speedtest.js';
import * as dbProcessMethods from './dbProcesses.js';
import * as dbTunerMethods from './dbTuner.js';
import * as importMethods from './imports.js';
import * as siteAdoptionMethods from './siteAdoption.js';
import * as doctorMethods from './doctor.js';
import * as bandwidthMethods from './bandwidth.js';
import * as htaccessToolMethods from './htaccessTools.js';
@@ -97,6 +98,7 @@ class ApiService extends ApiClient {
dbProcessMethods,
dbTunerMethods,
importMethods,
siteAdoptionMethods,
doctorMethods,
bandwidthMethods,
htaccessToolMethods,
+15
View File
@@ -0,0 +1,15 @@
// Site adoption (/api/v1/site-adoption) — register sites that already run on
// this host. Discovery is read-only; adopting records rows and never rewrites
// the running nginx / PHP-FPM config. Admin-only on the server.
export async function getHostSites() {
return this.request('/site-adoption/sites');
}
// A dry run unless `apply` is true: the server's default answer is the plan.
export async function adoptHostSite(site, { name, apply = false } = {}) {
return this.request('/site-adoption/adopt', {
method: 'POST',
body: { site, name: name || undefined, dry_run: !apply },
});
}
+63
View File
@@ -92,6 +92,69 @@
}
}
// "Adopt existing sites" dialog: one row per site nginx serves that no
// service accounts for, with what discovery found about it.
.adopt-sites {
display: flex;
flex-direction: column;
gap: $space-3;
margin: 0;
padding: 0;
list-style: none;
&__row {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: $space-4;
padding: $space-3;
border: 1px solid var(--border-soft);
border-radius: $radius-card;
background: var(--surface-2);
}
&__main {
min-width: 0;
flex: 1;
}
&__head {
display: flex;
align-items: center;
gap: $space-2;
flex-wrap: wrap;
}
&__domain {
font-size: $text-sm;
font-weight: $font-weight-medium;
color: $text-primary;
overflow-wrap: anywhere;
}
&__facts {
display: grid;
grid-template-columns: max-content minmax(0, 1fr);
gap: $space-1 $space-3;
margin: $space-2 0 0;
font-size: $text-xs;
dt { color: $text-secondary; }
dd {
margin: 0;
color: $text-primary;
overflow-wrap: anywhere;
}
}
&__reason {
margin: $space-2 0 0;
font-size: $text-xs;
color: $text-secondary;
}
}
@keyframes pulse-dot {
0%, 100% { opacity: 1; }
50% { opacity: 0.4; }