Skip to content
Merged
17 changes: 3 additions & 14 deletions cmd/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/prvious/pv/internal/automation"
"github.com/prvious/pv/internal/automation/steps"
"github.com/prvious/pv/internal/config"
"github.com/prvious/pv/internal/daemon"
"github.com/prvious/pv/internal/detection"
"github.com/prvious/pv/internal/laravel"
"github.com/prvious/pv/internal/phpenv"
Expand Down Expand Up @@ -140,20 +139,10 @@ pv link --name=myapp ~/Code/myapp`,
fmt.Fprintf(os.Stderr, " %s %s\n", ui.Muted.Render("PHP"), ui.Green.Render(ctx.PHPVersion))
fmt.Fprintln(os.Stderr)

// Reload/restart server if needed.
// Signal the daemon to reconcile FrankenPHP instances.
if server.IsRunning() {
needsRestart := phpVersion != "" && phpVersion != globalPHP
if needsRestart && daemon.IsLoaded() {
if err := daemon.Restart(); err != nil {
ui.Fail(fmt.Sprintf("Could not restart daemon: %v — run 'pv restart' manually", err))
}
} else {
if err := server.ReconfigureServer(); err != nil {
ui.Fail(fmt.Sprintf("Could not reconfigure server: %v", err))
}
if needsRestart {
ui.Subtle("Stop and restart the server to serve this project: pv stop && pv start")
}
if err := server.SignalDaemon(); err != nil {
ui.Subtle(fmt.Sprintf("Could not signal daemon: %v", err))
}
}

Expand Down
11 changes: 5 additions & 6 deletions cmd/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,20 @@ var restartCmd = &cobra.Command{
GroupID: "server",
Short: "Restart or reload the pv server",
RunE: func(cmd *cobra.Command, args []string) error {
// Daemon mode — delegate to daemon:restart.
if daemon.IsLoaded() {
return daemoncmds.RunRestart()
}

// Foreground mode — reload config via admin API.
if !server.IsRunning() {
return fmt.Errorf("pv is not running")
}

return ui.Step("Reloading server configuration...", func() (string, error) {
if err := server.ReconfigureServer(); err != nil {
return "", fmt.Errorf("reconfigure failed: %w", err)
// Foreground mode — signal reconcile via SIGHUP.
return ui.Step("Reconciling server...", func() (string, error) {
if err := server.SignalDaemon(); err != nil {
return "", fmt.Errorf("cannot signal server: %w", err)
}
return "Configuration reloaded", nil
return "Server reconciled", nil
})
},
}
Expand Down
26 changes: 3 additions & 23 deletions cmd/unlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/prvious/pv/internal/caddy"
"github.com/prvious/pv/internal/certs"
"github.com/prvious/pv/internal/config"
"github.com/prvious/pv/internal/daemon"
"github.com/prvious/pv/internal/registry"
"github.com/prvious/pv/internal/server"
"github.com/prvious/pv/internal/ui"
Expand Down Expand Up @@ -53,7 +52,6 @@ pv unlink`,
return fmt.Errorf("project %q is not linked", name)
}
projectPath := project.Path
projectPHP := project.PHP

if err := reg.Remove(name); err != nil {
return err
Expand Down Expand Up @@ -91,28 +89,10 @@ pv unlink`,
fmt.Fprintln(os.Stderr)
ui.Success(fmt.Sprintf("Unlinked %s", ui.Accent.Bold(true).Render(domain)))

// Signal the daemon to reconcile — it will stop orphaned secondaries.
if server.IsRunning() {
// Check if unlinking this project orphans a secondary FrankenPHP
// (no remaining projects use its PHP version).
globalPHP := ""
if settings != nil {
globalPHP = settings.Defaults.PHP
}
hadSecondary := projectPHP != "" && projectPHP != globalPHP
versionOrphaned := hadSecondary && !caddy.ActiveVersions(reg.List(), globalPHP)[projectPHP]

if versionOrphaned && daemon.IsLoaded() {
// Daemon mode: full process restart so the relaunched server no longer spawns the unneeded secondary.
if err := daemon.Restart(); err != nil {
ui.Fail(fmt.Sprintf("Could not restart daemon: %v — run 'pv restart' manually", err))
}
} else {
if err := server.ReconfigureServer(); err != nil {
ui.Fail(fmt.Sprintf("Could not reconfigure server: %v", err))
}
if versionOrphaned {
ui.Subtle("Stop and restart the server to clean up unused PHP processes: pv stop && pv start")
}
if err := server.SignalDaemon(); err != nil {
ui.Subtle(fmt.Sprintf("Could not signal daemon: %v", err))
}
}

Expand Down
Loading
Loading