-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from launchrctl/start-stop-ui
Web - Start/stop UX, background option
- Loading branch information
Showing
10 changed files
with
624 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package web | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"syscall" | ||
|
||
"github.com/launchrctl/launchr/pkg/log" | ||
) | ||
|
||
func setSysProcAttr(cmd *exec.Cmd) { | ||
cmd.SysProcAttr = &syscall.SysProcAttr{ | ||
Setsid: true, | ||
} | ||
} | ||
|
||
func isProcessRunning(pid int) bool { | ||
process, err := os.FindProcess(pid) | ||
if err != nil { | ||
log.Debug("Failed to find process: %s\n", err) | ||
return false | ||
} | ||
|
||
err = process.Signal(syscall.Signal(0)) | ||
if err == nil { | ||
return true | ||
} | ||
|
||
if err.Error() == "os: process already finished" { | ||
return false | ||
} | ||
|
||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package web | ||
|
||
import ( | ||
"os/exec" | ||
|
||
"golang.org/x/sys/windows" | ||
) | ||
|
||
func setSysProcAttr(cmd *exec.Cmd) { | ||
cmd.SysProcAttr = &windows.SysProcAttr{ | ||
CreationFlags: windows.CREATE_NEW_PROCESS_GROUP, | ||
} | ||
} | ||
|
||
func isProcessRunning(pid uint32) bool { | ||
h, err := windows.OpenProcess(windows.PROCESS_QUERY_LIMITED_INFORMATION, false, pid) | ||
if err != nil { | ||
return false | ||
} | ||
defer windows.CloseHandle(h) | ||
|
||
var code uint32 | ||
err = windows.GetExitCodeProcess(h, &code) | ||
if err != nil { | ||
return false | ||
} | ||
if code == windows.STILL_ACTIVE { | ||
return true | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package web | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strconv" | ||
) | ||
|
||
func pidFileExists(path string) bool { | ||
_, err := os.Stat(path) | ||
return err == nil | ||
} | ||
|
||
func readPidFile(path string) (int, error) { | ||
data, err := os.ReadFile(filepath.Clean(path)) | ||
if err != nil { | ||
return 0, fmt.Errorf("error reading PID file: %w", err) | ||
} | ||
|
||
pid, err := strconv.Atoi(string(data)) | ||
if err != nil { | ||
return 0, fmt.Errorf("error converting PID from file: %w", err) | ||
} | ||
|
||
return pid, nil | ||
} | ||
|
||
func killProcess(pid int) error { | ||
process, err := os.FindProcess(pid) | ||
if err != nil { | ||
return fmt.Errorf("error finding process: %w", err) | ||
} | ||
|
||
if err = process.Kill(); err != nil { | ||
return fmt.Errorf("error killing process: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func interruptProcess(pid int) error { | ||
process, err := os.FindProcess(pid) | ||
if err != nil { | ||
return fmt.Errorf("error finding process: %w", err) | ||
} | ||
|
||
if err = process.Signal(os.Interrupt); err != nil { | ||
return fmt.Errorf("error interrupting process: %w", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.