hnctl prints line breaks after errors

This commit is contained in:
Sasha Koshka 2023-06-01 01:01:08 -04:00
parent 4e58df9c9b
commit e8349360cc

View File

@ -60,19 +60,19 @@ func execStart (service string) {
pid, err := spawn.PidOf(fullName) pid, err := spawn.PidOf(fullName)
if err == nil && spawn.Running(pid) { if err == nil && spawn.Running(pid) {
cli.Sayf("service is already running") cli.Sayf("service is already running\n")
return return
} }
uid, gid, err := spawn.LookupUID(fullName) uid, gid, err := spawn.LookupUID(fullName)
if err != nil { if err != nil {
cli.Sayf("cannot start service: %v", err) cli.Sayf("cannot start service: %v\n", err)
os.Exit(1) os.Exit(1)
} }
path, err := exec.LookPath(fullName) path, err := exec.LookPath(fullName)
if err != nil { if err != nil {
cli.Sayf("cannot start service: %v", err) cli.Sayf("cannot start service: %v\n", err)
os.Exit(1) os.Exit(1)
} }
@ -80,7 +80,7 @@ func execStart (service string) {
env := append(os.Environ(), "HNAKRA_LOG_DIR=" + logDir) env := append(os.Environ(), "HNAKRA_LOG_DIR=" + logDir)
err = ensureLogDir(logDir, int(uid), int(gid)) err = ensureLogDir(logDir, int(uid), int(gid))
if err != nil { if err != nil {
cli.Sayf("cannot start service: %v", err) cli.Sayf("cannot start service: %v\n", err)
os.Exit(1) os.Exit(1)
} }
@ -88,14 +88,14 @@ func execStart (service string) {
// to it // to it
err = ensurePidFile(spawn.PidFile(fullName), int(uid), int(gid)) err = ensurePidFile(spawn.PidFile(fullName), int(uid), int(gid))
if err != nil { if err != nil {
cli.Sayf("cannot start service: %v", err) cli.Sayf("cannot start service: %v\n", err)
os.Exit(1) os.Exit(1)
} }
// spawn the service // spawn the service
pid, err = spawn.Spawn(path, uid, gid, env) pid, err = spawn.Spawn(path, uid, gid, env)
if err != nil { if err != nil {
cli.Sayf("cannot start service: %v", err) cli.Sayf("cannot start service: %v\n", err)
os.Exit(1) os.Exit(1)
} }
@ -108,19 +108,19 @@ func execStop (service string) {
pid, err := spawn.PidOf(fullName) pid, err := spawn.PidOf(fullName)
if err != nil || !spawn.Running(pid) { if err != nil || !spawn.Running(pid) {
cli.Sayf("service is not running") cli.Sayf("service is not running\n")
return return
} }
process, err := os.FindProcess(pid) process, err := os.FindProcess(pid)
if err != nil { if err != nil {
cli.Sayf("service is not running") cli.Sayf("service is not running\n")
return return
} }
err = spawn.KillAndWait(process, 16 * time.Second) err = spawn.KillAndWait(process, 16 * time.Second)
if err != nil { if err != nil {
cli.Sayf("could not stop service: %v", err) cli.Sayf("could not stop service: %v\n", err)
os.Exit(1) os.Exit(1)
} }
} }