diff --git a/deploy.go b/deploy.go index 5c61f49..a4d211f 100644 --- a/deploy.go +++ b/deploy.go @@ -25,6 +25,7 @@ const ( remoteWindowSize = 10 remoteIndent = " " remoteLineColor = "\033[96m" + localTimeColor = "\033[92m" remoteColorReset = "\033[0m" ) @@ -194,16 +195,17 @@ func runDeploy() error { } } - if err := syncLocalDirectories(ctx.serverIP, ctx.serviceDir, []string{"pb_migrations", "pb_hooks", "pb_public"}); err != nil { - return fmt.Errorf("asset sync failed: %w", err) + dirs := []string{"pb_public", "pb_migrations", "pb_hooks"} + if err := syncLocalDirectories(ctx.serverIP, ctx.serviceDir, dirs); err != nil { + return fmt.Errorf("failed to sync local directories: %w", err) } - if err := runSSHCommand(ctx.serverIP, systemdScript(ctx.unitServiceDir, ctx.unitEnvFile, ctx.serviceName)); err != nil { + if err := runSSHCommand(ctx.serverIP, systemdRestartScript(ctx.serviceName)); err != nil { return fmt.Errorf("systemd restart failed: %w", err) } fmt.Printf("\nDeployment complete; PocketBase should be reachable at https://%s\n", ctx.domain) - fmt.Printf("Total deployment time: %s\n", time.Since(start).Round(time.Millisecond)) + fmt.Printf("Total deployment time: %s%s%s\n", localTimeColor, time.Since(start).Round(time.Millisecond), remoteColorReset) return nil } @@ -387,6 +389,12 @@ EOF `, serviceDir, serviceDir, serviceDir, envFile, serviceDir, serviceName, serviceName) } +func systemdRestartScript(serviceName string) string { + return fmt.Sprintf(`set -euo pipefail +systemctl --no-block restart pb@%s +`, serviceName) +} + func runSSHCommand(server, script string) error { remoteCmd := fmt.Sprintf("bash --noprofile --norc -c %s", shellQuote(script)) cmd := exec.Command("ssh", append(sshArgs(server), remoteCmd)...)