Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
81ac4d4db5 | |||
![]() |
398a932bcb | ||
![]() |
9f262c4a55 | ||
eb4fae52ab | |||
![]() |
e188813adf | ||
![]() |
e1ba6e49a8 | ||
![]() |
20912ba17c | ||
![]() |
dd5ebb60fd | ||
![]() |
0e8864d4da | ||
![]() |
490fae7d5b | ||
![]() |
ca9d8af13f | ||
![]() |
2537d5f1c8 | ||
![]() |
79ad631494 |
@@ -30,6 +30,7 @@ jobs:
|
|||||||
ext: ""
|
ext: ""
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
|
||||||
- name: Checkout repo
|
- name: Checkout repo
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
@@ -43,8 +44,8 @@ jobs:
|
|||||||
|
|
||||||
if [ ! -x "$GOROOT/bin/go" ]; then
|
if [ ! -x "$GOROOT/bin/go" ]; then
|
||||||
echo "Go not found in $GOROOT, downloading latest stable..."
|
echo "Go not found in $GOROOT, downloading latest stable..."
|
||||||
|
|
||||||
GO_VERSION=$(curl -s https://go.dev/VERSION?m=text)
|
GO_VERSION=$(curl -s https://go.dev/VERSION?m=text | head -n1)
|
||||||
echo "Latest version is $GO_VERSION"
|
echo "Latest version is $GO_VERSION"
|
||||||
|
|
||||||
mkdir -p /data/go
|
mkdir -p /data/go
|
||||||
@@ -56,16 +57,6 @@ jobs:
|
|||||||
|
|
||||||
go version
|
go version
|
||||||
|
|
||||||
- name: Cache Go build and module cache in /data
|
|
||||||
uses: actions/cache@v4
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
/data/gocache
|
|
||||||
/data/gomodcache
|
|
||||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-go-
|
|
||||||
|
|
||||||
- name: Download Go dependencies
|
- name: Download Go dependencies
|
||||||
run: |
|
run: |
|
||||||
export GOROOT=/data/go/go
|
export GOROOT=/data/go/go
|
||||||
@@ -92,13 +83,9 @@ jobs:
|
|||||||
echo "Building $OUTPUT"
|
echo "Building $OUTPUT"
|
||||||
GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -ldflags="-s -w" -trimpath -o "$OUTPUT"
|
GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -ldflags="-s -w" -trimpath -o "$OUTPUT"
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
- name: Zip artifact
|
- name: Upload artifact
|
||||||
run: |
|
|
||||||
zip bin/${{ env.APP_NAME }}-${{ matrix.os }}-${{ matrix.arch }}.zip bin/${{ env.APP_NAME }}-*
|
|
||||||
|
|
||||||
- name: Upload zipped artifact
|
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: ${{ env.APP_NAME }}-${{ matrix.os }}-${{ matrix.arch }}
|
name: ${{ env.APP_NAME }}-${{ matrix.os }}-${{ matrix.arch }}
|
||||||
path: bin/${{ env.APP_NAME }}-${{ matrix.os }}-${{ matrix.arch }}.zip
|
path: bin/
|
||||||
|
20
dist/supervisorTemplate.json
vendored
Normal file
20
dist/supervisorTemplate.json
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"processes":[{
|
||||||
|
"name":"Database DBM",
|
||||||
|
"description":"data description",
|
||||||
|
"executePath":"dist/test-windows-amd64.exe",
|
||||||
|
"workingDirectory":".",
|
||||||
|
"startDelay":1000,
|
||||||
|
"priority":0,
|
||||||
|
"arguments":["-sleep 5"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name":"Pau",
|
||||||
|
"description":"my lovely wife",
|
||||||
|
"executePath":"explorer.exe",
|
||||||
|
"workingDirectory":".",
|
||||||
|
"startDelay":1000,
|
||||||
|
"priority":2
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
BIN
dist/test-windows-amd64.exe
vendored
Normal file
BIN
dist/test-windows-amd64.exe
vendored
Normal file
Binary file not shown.
@@ -1,17 +0,0 @@
|
|||||||
package handlers
|
|
||||||
|
|
||||||
import (
|
|
||||||
"html/template"
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
type MainPage struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateMainPage(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
|
||||||
tmpl := template.Must(
|
|
||||||
template.New("index.html").ParseFiles("templates/index.html"),
|
|
||||||
)
|
|
||||||
tmpl.Execute(w, nil)
|
|
||||||
}
|
|
@@ -1,18 +1,21 @@
|
|||||||
package handlers
|
package htop
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
"processSupervisor/models"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed templates
|
||||||
|
var templatesFS embed.FS
|
||||||
|
|
||||||
type HTopHandler struct {
|
type HTopHandler struct {
|
||||||
Table *models.HtopTable
|
Table *HtopTable
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHTopHandler() (*HTopHandler, error) {
|
func NewHTopHandler() (*HTopHandler, error) {
|
||||||
table, err := models.NewTable()
|
table, err := NewTable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -38,16 +41,20 @@ func (h *HTopHandler) UpdateHTop(w http.ResponseWriter, r *http.Request) {
|
|||||||
// Detect HTMX request via the HX-Request header
|
// Detect HTMX request via the HX-Request header
|
||||||
if r.Header.Get("HX-Request") == "true" {
|
if r.Header.Get("HX-Request") == "true" {
|
||||||
tmpl := template.Must(
|
tmpl := template.Must(
|
||||||
template.New("table.html").Funcs(funcMap).ParseFiles("templates/htop/table.html"),
|
template.New("table.html").Funcs(funcMap).ParseFS(
|
||||||
|
templatesFS,
|
||||||
|
"templates/table.html",
|
||||||
|
),
|
||||||
)
|
)
|
||||||
tmpl.Execute(w, h.Table)
|
tmpl.Execute(w, h.Table)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpl := template.Must(
|
tmpl := template.Must(
|
||||||
template.New("htop.html").Funcs(funcMap).ParseFiles(
|
template.New("htop.html").Funcs(funcMap).ParseFS(
|
||||||
"templates/htop/htop.html",
|
templatesFS,
|
||||||
"templates/htop/table.html",
|
"templates/htop.html",
|
||||||
|
"templates/table.html",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
tmpl.Execute(w, h.Table)
|
tmpl.Execute(w, h.Table)
|
||||||
@@ -83,7 +90,7 @@ func toFloat64(v any) float64 {
|
|||||||
|
|
||||||
// GET /taskmanager/usage
|
// GET /taskmanager/usage
|
||||||
func UsageHandler(w http.ResponseWriter, r *http.Request) {
|
func UsageHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
cpu, mem, err := models.GetSystemUsage()
|
cpu, mem, err := GetSystemUsage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Failed to get usage", 500)
|
http.Error(w, "Failed to get usage", 500)
|
||||||
return
|
return
|
@@ -1,8 +1,9 @@
|
|||||||
package models
|
package htop
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"processSupervisor/htop/models"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@@ -11,13 +12,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type HtopTable struct {
|
type HtopTable struct {
|
||||||
Processes []Process
|
Processes []models.Process
|
||||||
CurrentSort string
|
CurrentSort string
|
||||||
CurrentOrder string
|
CurrentOrder string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTable() (*HtopTable, error) {
|
func NewTable() (*HtopTable, error) {
|
||||||
processes, err := GetProcesses()
|
processes, err := models.GetProcesses()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &HtopTable{}, err
|
return &HtopTable{}, err
|
||||||
}
|
}
|
||||||
@@ -28,7 +29,7 @@ func NewTable() (*HtopTable, error) {
|
|||||||
|
|
||||||
func (t *HtopTable) UpdateTable() error {
|
func (t *HtopTable) UpdateTable() error {
|
||||||
var err error
|
var err error
|
||||||
t.Processes, err = GetProcesses()
|
t.Processes, err = models.GetProcesses()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
@@ -1,10 +1,10 @@
|
|||||||
package handlers
|
package htop
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"processSupervisor/models"
|
"processSupervisor/htop/models"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -35,6 +35,6 @@ func KillHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpl := template.Must(template.ParseFiles("templates/htop/table.html"))
|
tmpl := template.Must(template.ParseFiles("templates/table.html"))
|
||||||
tmpl.Execute(w, processes)
|
tmpl.Execute(w, processes)
|
||||||
}
|
}
|
@@ -63,7 +63,7 @@
|
|||||||
hx-get="/taskmanager/kill?pid={{.PID}}"
|
hx-get="/taskmanager/kill?pid={{.PID}}"
|
||||||
hx-target="#process-table"
|
hx-target="#process-table"
|
||||||
hx-swap="outerHTML"
|
hx-swap="outerHTML"
|
||||||
hx-confirm="Are you sure you want to kill this process?">
|
hx-confirm="Are you sure you want to kill {{.Cmd}} process?">
|
||||||
Kill
|
Kill
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
42
main.go
42
main.go
@@ -1,31 +1,49 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"embed"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"processSupervisor/handlers"
|
"processSupervisor/htop"
|
||||||
|
"processSupervisor/mainPage"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed static
|
||||||
|
var staticFS embed.FS
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
port := flag.Uint("port", 9400, "listenig port")
|
port := flag.Uint("port", 9400, "listening port")
|
||||||
flag.Parse()
|
cfgDir := flag.String("cfg", "./dist", "configuration directory")
|
||||||
|
htopHandler, err := htop.NewHTopHandler()
|
||||||
htop, err := handlers.NewHTopHandler()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fs := http.FileServer(http.Dir("static"))
|
mP, err := mainPage.NewMainPage(*cfgDir)
|
||||||
http.Handle("/static/", http.StripPrefix("/static/", fs))
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
http.HandleFunc("/taskmanager/htop", htop.UpdateHTop)
|
staticSub, err := fs.Sub(staticFS, "static")
|
||||||
http.HandleFunc("/", handlers.UpdateMainPage)
|
if err != nil {
|
||||||
http.HandleFunc("/taskmanager/kill", handlers.KillHandler)
|
log.Fatal(err)
|
||||||
http.HandleFunc("/taskmanager/usage", handlers.UsageHandler)
|
}
|
||||||
|
|
||||||
log.Printf("Listening on http://localhost:%d/taskmanager/htop\n", *port)
|
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.FS(staticSub))))
|
||||||
|
|
||||||
|
http.HandleFunc("/taskmanager/htop", htopHandler.UpdateHTop)
|
||||||
|
http.HandleFunc("/", mP.LoadMainPage)
|
||||||
|
http.HandleFunc("/start-process", mP.StartProcess)
|
||||||
|
http.HandleFunc("/stop-process", mP.StopProcess)
|
||||||
|
http.HandleFunc("/restart-process", mP.RestartProcess)
|
||||||
|
http.HandleFunc("/processes", mP.UpdateMainPage)
|
||||||
|
http.HandleFunc("/taskmanager/kill", htop.KillHandler)
|
||||||
|
http.HandleFunc("/taskmanager/usage", htop.UsageHandler)
|
||||||
|
|
||||||
|
log.Printf("Listening on http://localhost:%d\n", *port)
|
||||||
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), nil))
|
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), nil))
|
||||||
}
|
}
|
||||||
|
96
mainPage/mainPage.go
Normal file
96
mainPage/mainPage.go
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
package mainPage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"embed"
|
||||||
|
"html/template"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"processSupervisor/supervisor"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed templates
|
||||||
|
var templatesFS embed.FS
|
||||||
|
|
||||||
|
type MainPage struct {
|
||||||
|
Supervisor *supervisor.Supervisor
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMainPage(cfgDir string) (*MainPage, error) {
|
||||||
|
var sv supervisor.Supervisor
|
||||||
|
file := filepath.Join(cfgDir, "supervisorTemplate.json")
|
||||||
|
if _, err := os.Stat(file); err == nil {
|
||||||
|
sv, err = supervisor.ReadTemplate(file)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := sv.StartProcesses(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
m := MainPage{
|
||||||
|
Supervisor: &sv,
|
||||||
|
}
|
||||||
|
|
||||||
|
return &m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MainPage) LoadMainPage(w http.ResponseWriter, r *http.Request) {
|
||||||
|
tmpl := template.Must(
|
||||||
|
template.New("index.html").ParseFS(
|
||||||
|
templatesFS,
|
||||||
|
"templates/index.html",
|
||||||
|
"templates/processes.html",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
tmpl.Execute(w, m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MainPage) UpdateMainPage(w http.ResponseWriter, r *http.Request) {
|
||||||
|
tmpl := template.Must(
|
||||||
|
template.New("processes.html").ParseFS(
|
||||||
|
templatesFS,
|
||||||
|
"templates/processes.html",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
tmpl.Execute(w, m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MainPage) StartProcess(w http.ResponseWriter, r *http.Request) {
|
||||||
|
name := r.PostFormValue("name")
|
||||||
|
|
||||||
|
// This is where you trigger the .Start method
|
||||||
|
err := m.Supervisor.StartProcessByName(name)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Failed to start process", err)
|
||||||
|
}
|
||||||
|
m.UpdateMainPage(w, r)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MainPage) StopProcess(w http.ResponseWriter, r *http.Request) {
|
||||||
|
name := r.PostFormValue("name")
|
||||||
|
|
||||||
|
err := m.Supervisor.StopProcessByName(name)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Failed to stop process", err)
|
||||||
|
}
|
||||||
|
m.UpdateMainPage(w, r)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MainPage) RestartProcess(w http.ResponseWriter, r *http.Request) {
|
||||||
|
name := r.PostFormValue("name")
|
||||||
|
|
||||||
|
err := m.Supervisor.StopProcessByName(name)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
err = m.Supervisor.StartProcessByName(name)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
m.UpdateMainPage(w, r)
|
||||||
|
}
|
56
mainPage/templates/index.html
Normal file
56
mainPage/templates/index.html
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Process Dashboard</title>
|
||||||
|
<script src="https://unpkg.com/htmx.org@1.9.5"></script>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<ul id="process-page">
|
||||||
|
<div class="top-link-container">
|
||||||
|
<a href="/taskmanager/htop" class="top-link" target="_blank" rel="noopener noreferrer">
|
||||||
|
📈 Task Manager
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Header -->
|
||||||
|
<h2>Processes</h2>
|
||||||
|
<ul id="process-list"
|
||||||
|
hx-get="/processes"
|
||||||
|
hx-trigger="every 5s"
|
||||||
|
hx-swap="innerHTML">
|
||||||
|
{{ template "processes.html" . }}
|
||||||
|
</ul>
|
||||||
|
</body>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: "Segoe UI", Roboto, sans-serif;
|
||||||
|
margin: 2rem;
|
||||||
|
background-color: #f7f9fb;
|
||||||
|
color: #222;
|
||||||
|
}
|
||||||
|
|
||||||
|
.top-link-container {
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.top-link {
|
||||||
|
font-size: 1.2rem;
|
||||||
|
text-decoration: none;
|
||||||
|
color: #4a90e2;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.top-link:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
h2 {
|
||||||
|
text-align: center;
|
||||||
|
color: #444;
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
</html>
|
135
mainPage/templates/processes.html
Normal file
135
mainPage/templates/processes.html
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
{{ range .Supervisor.GetProcesses }}
|
||||||
|
<li>
|
||||||
|
<span class="process-name">📦
|
||||||
|
{{ if .Running }}
|
||||||
|
🟢 {{ .Name }}{{if ne .Description ""}} <span class="process-description">{{.Description}}</span>{{end}}
|
||||||
|
{{ else }}
|
||||||
|
🔴 {{ .Name }}{{if ne .Description ""}} <span class="process-description">{{.Description}}</span>{{end}}
|
||||||
|
{{ end }}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<div class="dropdown">
|
||||||
|
<button class="dot-button">⋮</button>
|
||||||
|
<div class="dropdown-content">
|
||||||
|
{{ if not .Running }}
|
||||||
|
<button
|
||||||
|
hx-post="/start-process"
|
||||||
|
hx-vals='{"name": "{{ .Name }}"}'
|
||||||
|
hx-trigger="click"
|
||||||
|
hx-target="#process-list"
|
||||||
|
hx-swap="innerHTML">
|
||||||
|
▶️ Start
|
||||||
|
</button>
|
||||||
|
{{else}}
|
||||||
|
<button
|
||||||
|
hx-post="/stop-process"
|
||||||
|
hx-vals='{"name": "{{ .Name }}"}'
|
||||||
|
hx-trigger="click"
|
||||||
|
hx-target="#process-list"
|
||||||
|
hx-swap="innerHTML">
|
||||||
|
⏹️ Stop
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
hx-post="/restart-process"
|
||||||
|
hx-vals='{"name": "{{ .Name }}"}'
|
||||||
|
hx-trigger="click"
|
||||||
|
hx-target="#process-list"
|
||||||
|
hx-swap="innerHTML">
|
||||||
|
🔁 Restart
|
||||||
|
</button>
|
||||||
|
{{ end }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
ul#process-list {
|
||||||
|
list-style: none;
|
||||||
|
padding: 0;
|
||||||
|
max-width: 600px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul#process-list li {
|
||||||
|
background: #fff;
|
||||||
|
margin: 0.75rem 0;
|
||||||
|
padding: 1rem 1.25rem;
|
||||||
|
border-radius: 10px;
|
||||||
|
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
transition: box-shadow 0.25s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul#process-list li:hover {
|
||||||
|
box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.process-name {
|
||||||
|
font-weight: 600;
|
||||||
|
font-size: 1rem;
|
||||||
|
color: #2c3e50;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.process-description {
|
||||||
|
font-weight: 400; /* normal or lighter */
|
||||||
|
color: #2c3e50; /* optional: same color or adjust if needed */
|
||||||
|
}
|
||||||
|
|
||||||
|
.dot-button {
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
cursor: pointer;
|
||||||
|
color: #777;
|
||||||
|
padding: 0 4px;
|
||||||
|
transition: color 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dot-button:hover {
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown {
|
||||||
|
position: relative;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-content {
|
||||||
|
display: none;
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
top: 1.8rem;
|
||||||
|
background-color: #fff;
|
||||||
|
min-width: 130px;
|
||||||
|
box-shadow: 0 6px 12px rgba(0,0,0,0.1);
|
||||||
|
border-radius: 6px;
|
||||||
|
overflow: hidden;
|
||||||
|
z-index: 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown:hover .dropdown-content {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-content button {
|
||||||
|
width: 100%;
|
||||||
|
padding: 10px 12px;
|
||||||
|
text-align: left;
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
color: #333;
|
||||||
|
transition: background 0.2s, color 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-content button:hover {
|
||||||
|
background-color: #f0f0f0;
|
||||||
|
color: #000;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</html>
|
93
supervisor/process.go
Normal file
93
supervisor/process.go
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
package supervisor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Process struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Description string `json:"description,omitempty"`
|
||||||
|
ExecutePath string `json:"executePath"`
|
||||||
|
WorkingDirectory string `json:"workingDirectory,omitempty"`
|
||||||
|
StartDelay int `json:"startDelay,omitempty"`
|
||||||
|
Priority int `json:"priority,omitempty"`
|
||||||
|
Arguments []string `json:"arguments,omitempty"`
|
||||||
|
process *exec.Cmd `json:"-"`
|
||||||
|
cancel context.CancelFunc `json:"-"`
|
||||||
|
Running bool `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var Init bool
|
||||||
|
|
||||||
|
func (p *Process) Start() error {
|
||||||
|
if p.Running {
|
||||||
|
return fmt.Errorf("process %s already running", p.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
p.cancel = cancel
|
||||||
|
|
||||||
|
var args []string
|
||||||
|
for _, arg := range p.Arguments {
|
||||||
|
fields := strings.Fields(arg)
|
||||||
|
args = append(args, fields...)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := exec.CommandContext(ctx, p.ExecutePath, args...)
|
||||||
|
cmd.Dir = p.WorkingDirectory
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
|
p.process = cmd
|
||||||
|
|
||||||
|
p.Running = true
|
||||||
|
|
||||||
|
if !Init {
|
||||||
|
time.Sleep(time.Duration(p.StartDelay) * time.Millisecond)
|
||||||
|
Init = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := cmd.Start(); err != nil {
|
||||||
|
p.Running = false
|
||||||
|
p.process = nil
|
||||||
|
p.cancel = nil
|
||||||
|
return fmt.Errorf("failed to start process %s: %w", p.Name, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
err := cmd.Wait()
|
||||||
|
if err != nil {
|
||||||
|
} else {
|
||||||
|
p.Running = false
|
||||||
|
p.process = nil
|
||||||
|
p.cancel = nil
|
||||||
|
}
|
||||||
|
p.Running = false
|
||||||
|
}()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) Stop() error {
|
||||||
|
if !p.Running {
|
||||||
|
return fmt.Errorf("process %s is not running", p.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cancel the context
|
||||||
|
p.cancel()
|
||||||
|
|
||||||
|
err := p.process.Process.Kill()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to kill process %s: %w", p.Name, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
p.Running = false
|
||||||
|
p.process = nil
|
||||||
|
p.cancel = nil
|
||||||
|
return nil
|
||||||
|
}
|
58
supervisor/supervisor.go
Normal file
58
supervisor/supervisor.go
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
package supervisor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"sort"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Supervisor struct {
|
||||||
|
Processes []*Process `json:"processes"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func ReadTemplate(path string) (supervisor Supervisor, err error) {
|
||||||
|
content, err := os.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(content, &supervisor)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Supervisor) StartProcesses() error {
|
||||||
|
sort.Slice(s.Processes, func(i, j int) bool {
|
||||||
|
return s.Processes[i].Priority < s.Processes[j].Priority
|
||||||
|
})
|
||||||
|
|
||||||
|
for _, p := range s.Processes {
|
||||||
|
p.Start()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Supervisor) GetProcesses() (processes []Process) {
|
||||||
|
for _, p := range s.Processes {
|
||||||
|
processes = append(processes, *p)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Supervisor) StartProcessByName(name string) error {
|
||||||
|
for _, p := range s.Processes {
|
||||||
|
if p.Name == name {
|
||||||
|
return p.Start()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fmt.Errorf("process %s not found", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Supervisor) StopProcessByName(name string) error {
|
||||||
|
for _, p := range s.Processes {
|
||||||
|
if p.Name == name {
|
||||||
|
return p.Stop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fmt.Errorf("process %s not found", name)
|
||||||
|
}
|
@@ -1,62 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>Process Dashboard</title>
|
|
||||||
<script src="https://unpkg.com/htmx.org@1.9.5"></script>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
font-family: sans-serif;
|
|
||||||
margin: 2rem;
|
|
||||||
}
|
|
||||||
.top-link {
|
|
||||||
display: block;
|
|
||||||
margin-bottom: 1rem;
|
|
||||||
font-size: 1.2rem;
|
|
||||||
}
|
|
||||||
ul#process-list {
|
|
||||||
list-style: none;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
ul#process-list li {
|
|
||||||
background: #f4f4f4;
|
|
||||||
margin: 0.5rem 0;
|
|
||||||
padding: 0.75rem;
|
|
||||||
border-radius: 5px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<div class="top-link-container">
|
|
||||||
<a href="/taskmanager/htop" class="top-link" target="_blank" rel="noopener noreferrer">
|
|
||||||
📈 Task Manager
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Header -->
|
|
||||||
<h2>Future Processes</h2>
|
|
||||||
|
|
||||||
<!-- Placeholder List for Future Processes -->
|
|
||||||
<ul id="process-list">
|
|
||||||
<li>📌 Process A (placeholder)</li>
|
|
||||||
<li>📌 Process B (placeholder)</li>
|
|
||||||
<li>📌 Process C (placeholder)</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<!-- Example Button for Future HTMX Action -->
|
|
||||||
<button
|
|
||||||
hx-get="/get-latest-processes"
|
|
||||||
hx-target="#process-list"
|
|
||||||
hx-swap="innerHTML">
|
|
||||||
🔄 Load Latest Processes
|
|
||||||
</button>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
<style>
|
|
||||||
.top-link-container {
|
|
||||||
text-align: center;
|
|
||||||
margin-bottom: 1rem;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</html>
|
|
Reference in New Issue
Block a user