mirror of
https://github.com/EnumeratedDev/enit.git
synced 2026-09-25 15:06:11 +00:00
Compare commits
4
Commits
0.3.0
...
70ef610ce6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
70ef610ce6
|
||
|
|
5ed1128e43
|
||
|
|
87412f20f8
|
||
|
|
2be3e0c947
|
@@ -5,3 +5,4 @@ start_cmd: /usr/bin/setsid /sbin/agetty --noclear tty1
|
|||||||
exit_method: kill
|
exit_method: kill
|
||||||
crash_on_safe_exit: false
|
crash_on_safe_exit: false
|
||||||
restart: always
|
restart: always
|
||||||
|
setpgid: false
|
||||||
|
|||||||
@@ -5,3 +5,4 @@ start_cmd: /usr/bin/setsid /sbin/agetty tty2
|
|||||||
exit_method: kill
|
exit_method: kill
|
||||||
crash_on_safe_exit: false
|
crash_on_safe_exit: false
|
||||||
restart: always
|
restart: always
|
||||||
|
setpgid: false
|
||||||
|
|||||||
@@ -5,3 +5,4 @@ start_cmd: /usr/bin/setsid /sbin/agetty tty3
|
|||||||
exit_method: kill
|
exit_method: kill
|
||||||
crash_on_safe_exit: false
|
crash_on_safe_exit: false
|
||||||
restart: always
|
restart: always
|
||||||
|
setpgid: false
|
||||||
|
|||||||
@@ -5,3 +5,4 @@ start_cmd: /usr/bin/setsid /sbin/agetty tty4
|
|||||||
exit_method: kill
|
exit_method: kill
|
||||||
crash_on_safe_exit: false
|
crash_on_safe_exit: false
|
||||||
restart: always
|
restart: always
|
||||||
|
setpgid: false
|
||||||
|
|||||||
@@ -5,3 +5,4 @@ start_cmd: /usr/bin/setsid /sbin/agetty tty5
|
|||||||
exit_method: kill
|
exit_method: kill
|
||||||
crash_on_safe_exit: false
|
crash_on_safe_exit: false
|
||||||
restart: always
|
restart: always
|
||||||
|
setpgid: false
|
||||||
|
|||||||
@@ -5,3 +5,4 @@ start_cmd: /usr/bin/setsid /sbin/agetty tty6
|
|||||||
exit_method: kill
|
exit_method: kill
|
||||||
crash_on_safe_exit: false
|
crash_on_safe_exit: false
|
||||||
restart: always
|
restart: always
|
||||||
|
setpgid: false
|
||||||
|
|||||||
+53
-1
@@ -57,7 +57,59 @@ func main() {
|
|||||||
return
|
return
|
||||||
} else if flag.Args()[0] == "service" || flag.Args()[0] == "sv" {
|
} else if flag.Args()[0] == "service" || flag.Args()[0] == "sv" {
|
||||||
if len(flag.Args()) <= 1 {
|
if len(flag.Args()) <= 1 {
|
||||||
fmt.Println("Usage: ectl service <start/stop/enable/disable/status/list> [service]")
|
fmt.Println("Usage: ectl service <reload/start/stop/enable/disable/status/list> [service]")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if flag.Arg(1) == "reload" {
|
||||||
|
type ServiceCommandJsonStruct struct {
|
||||||
|
Command string `json:"command"`
|
||||||
|
Service string `json:"service"`
|
||||||
|
}
|
||||||
|
serviceCommandJson := ServiceCommandJsonStruct{
|
||||||
|
Command: flag.Arg(1),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Encode struct to json string
|
||||||
|
jsonData, err := json.Marshal(serviceCommandJson)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not encode JSON data! Error: %s\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = conn.Write(jsonData)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not write JSON data to socket! Error: %s\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a buffer for incoming data.
|
||||||
|
buf := make([]byte, 4096)
|
||||||
|
|
||||||
|
// Read data from the connection.
|
||||||
|
n, err := conn.Read(buf)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print json data if flag is set
|
||||||
|
if *printJson {
|
||||||
|
fmt.Println(string(buf[:n]))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decoode JSON data
|
||||||
|
var returnedJsonData map[string]any
|
||||||
|
err = json.Unmarshal(buf[:n], &returnedJsonData)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not decode JSON data from connection!")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err, ok := returnedJsonData["error"]; ok {
|
||||||
|
log.Fatal(err)
|
||||||
|
} else if msg, ok := returnedJsonData["success"]; ok {
|
||||||
|
fmt.Println(msg)
|
||||||
|
} else {
|
||||||
|
log.Fatal("Connection returned empty string!")
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
} else if flag.Arg(1) == "start" || flag.Arg(1) == "stop" || flag.Arg(1) == "restart" {
|
} else if flag.Arg(1) == "start" || flag.Arg(1) == "stop" || flag.Arg(1) == "restart" {
|
||||||
// Ensure service name argument has been set
|
// Ensure service name argument has been set
|
||||||
|
|||||||
@@ -215,16 +215,12 @@ func waitZombieProcesses() {
|
|||||||
func catchSignals() {
|
func catchSignals() {
|
||||||
sigc := make(chan os.Signal, 1)
|
sigc := make(chan os.Signal, 1)
|
||||||
signal.Notify(sigc, syscall.SIGUSR1, syscall.SIGTERM, syscall.SIGINT, syscall.SIGCHLD)
|
signal.Notify(sigc, syscall.SIGUSR1, syscall.SIGTERM, syscall.SIGINT, syscall.SIGCHLD)
|
||||||
defer close(sigc)
|
|
||||||
defer signal.Stop(sigc)
|
|
||||||
for {
|
for {
|
||||||
switch <-sigc {
|
switch <-sigc {
|
||||||
case syscall.SIGUSR1:
|
case syscall.SIGUSR1:
|
||||||
close(sigc)
|
|
||||||
signal.Stop(sigc)
|
signal.Stop(sigc)
|
||||||
shutdownSystem()
|
shutdownSystem()
|
||||||
case syscall.SIGTERM, syscall.SIGINT:
|
case syscall.SIGTERM, syscall.SIGINT:
|
||||||
close(sigc)
|
|
||||||
signal.Stop(sigc)
|
signal.Stop(sigc)
|
||||||
rebootSystem()
|
rebootSystem()
|
||||||
case syscall.SIGCHLD:
|
case syscall.SIGCHLD:
|
||||||
|
|||||||
+27
-13
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@@ -143,19 +144,22 @@ func Init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
service := EnitService{
|
service := EnitService{
|
||||||
Name: "",
|
Name: "",
|
||||||
Description: "",
|
Description: "",
|
||||||
Dependencies: make([]string, 0),
|
Dependencies: make([]string, 0),
|
||||||
Type: "",
|
Type: "",
|
||||||
StartCmd: "",
|
StartCmd: "",
|
||||||
ExitMethod: "",
|
ExitMethod: "",
|
||||||
StopCmd: "",
|
StopCmd: "",
|
||||||
Restart: "",
|
Restart: "",
|
||||||
CrashOnSafeExit: true,
|
Setpgid: true,
|
||||||
restartCount: 0,
|
CrashOnSafeExit: true,
|
||||||
stopChannel: make(chan bool),
|
LogOutput: true,
|
||||||
LogOutput: true,
|
Filepath: path.Join(serviceConfigDir, "services", entry.Name()),
|
||||||
state: EnitServiceUnloaded,
|
filepathChecksum: sha256.Sum256(bytes),
|
||||||
|
restartCount: 0,
|
||||||
|
stopChannel: make(chan bool),
|
||||||
|
state: EnitServiceUnloaded,
|
||||||
}
|
}
|
||||||
if err := yaml.Unmarshal(bytes, &service); err != nil {
|
if err := yaml.Unmarshal(bytes, &service); err != nil {
|
||||||
logger.Printf("Error: could not read service file %s", path.Join(serviceConfigDir, "services", entry.Name()))
|
logger.Printf("Error: could not read service file %s", path.Join(serviceConfigDir, "services", entry.Name()))
|
||||||
@@ -227,6 +231,16 @@ func Init() {
|
|||||||
logger.Println("ESVM initialized successfully!")
|
logger.Println("ESVM initialized successfully!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Reload() {
|
||||||
|
logger.Println("Reloading all ESVM services...")
|
||||||
|
|
||||||
|
for _, service := range Services {
|
||||||
|
service.ReloadService()
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Println("All ESVM services have been reloaded!")
|
||||||
|
}
|
||||||
|
|
||||||
func Destroy() {
|
func Destroy() {
|
||||||
logger.Println("Stopping all ESVM services...")
|
logger.Println("Stopping all ESVM services...")
|
||||||
|
|
||||||
|
|||||||
+192
-16
@@ -1,7 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
@@ -18,6 +20,7 @@ type EnitServiceState uint8
|
|||||||
const (
|
const (
|
||||||
EnitServiceUnknown EnitServiceState = iota
|
EnitServiceUnknown EnitServiceState = iota
|
||||||
EnitServiceUnloaded
|
EnitServiceUnloaded
|
||||||
|
EnitServiceStarting
|
||||||
EnitServiceRunning
|
EnitServiceRunning
|
||||||
EnitServiceStopped
|
EnitServiceStopped
|
||||||
EnitServiceCrashed
|
EnitServiceCrashed
|
||||||
@@ -27,6 +30,7 @@ const (
|
|||||||
var EnitServiceStateNames map[EnitServiceState]string = map[EnitServiceState]string{
|
var EnitServiceStateNames map[EnitServiceState]string = map[EnitServiceState]string{
|
||||||
EnitServiceUnknown: "unknown",
|
EnitServiceUnknown: "unknown",
|
||||||
EnitServiceUnloaded: "unloaded",
|
EnitServiceUnloaded: "unloaded",
|
||||||
|
EnitServiceStarting: "starting",
|
||||||
EnitServiceRunning: "running",
|
EnitServiceRunning: "running",
|
||||||
EnitServiceStopped: "stopped",
|
EnitServiceStopped: "stopped",
|
||||||
EnitServiceCrashed: "crashed",
|
EnitServiceCrashed: "crashed",
|
||||||
@@ -34,20 +38,25 @@ var EnitServiceStateNames map[EnitServiceState]string = map[EnitServiceState]str
|
|||||||
}
|
}
|
||||||
|
|
||||||
type EnitService struct {
|
type EnitService struct {
|
||||||
Name string `yaml:"name"`
|
Name string `yaml:"name"`
|
||||||
Description string `yaml:"description,omitempty"`
|
Description string `yaml:"description,omitempty"`
|
||||||
Dependencies []string `yaml:"dependencies,omitempty"`
|
Dependencies []string `yaml:"dependencies,omitempty"`
|
||||||
Type string `yaml:"type"`
|
Type string `yaml:"type"`
|
||||||
StartCmd string `yaml:"start_cmd"`
|
StartCmd string `yaml:"start_cmd"`
|
||||||
ExitMethod string `yaml:"exit_method"`
|
ExitMethod string `yaml:"exit_method"`
|
||||||
CrashOnSafeExit bool `yaml:"crash_on_safe_exit"`
|
CrashOnSafeExit bool `yaml:"crash_on_safe_exit"`
|
||||||
StopCmd string `yaml:"stop_cmd,omitempty"`
|
StopCmd string `yaml:"stop_cmd,omitempty"`
|
||||||
Restart string `yaml:"restart,omitempty"`
|
Restart string `yaml:"restart,omitempty"`
|
||||||
LogOutput bool `yaml:"log_output,omitempty"`
|
ReadyFd int `yaml:"ready_fd"`
|
||||||
state EnitServiceState
|
Setpgid bool `yaml:"setpgid"`
|
||||||
processID int
|
LogOutput bool `yaml:"log_output,omitempty"`
|
||||||
restartCount int
|
Filepath string
|
||||||
stopChannel chan bool
|
filepathChecksum [32]byte
|
||||||
|
state EnitServiceState
|
||||||
|
processID int
|
||||||
|
restartCount int
|
||||||
|
stopChannel chan bool
|
||||||
|
shouldReload bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var Services = make([]*EnitService, 0)
|
var Services = make([]*EnitService, 0)
|
||||||
@@ -113,7 +122,92 @@ func (service *EnitService) GetLogFile() (file *os.File, err error) {
|
|||||||
return file, nil
|
return file, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (service *EnitService) StartService() error {
|
func (service *EnitService) ReloadService() {
|
||||||
|
bytes, err := os.ReadFile(service.Filepath)
|
||||||
|
checksum := sha256.Sum256(bytes)
|
||||||
|
if slices.Equal(checksum[:], service.filepathChecksum[:]) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if service.state == EnitServiceStarting || service.state == EnitServiceRunning {
|
||||||
|
service.shouldReload = true
|
||||||
|
logger.Printf("Warning: Service (%s) is currently running and will be reloaded when stopped\n", service.Name)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
service.shouldReload = false
|
||||||
|
|
||||||
|
logger.Printf("Reloading service (%s)...\n", service.Filepath)
|
||||||
|
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
Services = slices.DeleteFunc(Services, func(sv *EnitService) bool {
|
||||||
|
return sv == service
|
||||||
|
})
|
||||||
|
logger.Printf("Service (%s) has been removed\n", service.Name)
|
||||||
|
return
|
||||||
|
} else if err != nil {
|
||||||
|
logger.Printf("Error: Could not read service file (%s)", service.Filepath)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
newService := EnitService{
|
||||||
|
Name: "",
|
||||||
|
Description: "",
|
||||||
|
Dependencies: make([]string, 0),
|
||||||
|
Type: "",
|
||||||
|
StartCmd: "",
|
||||||
|
ExitMethod: "",
|
||||||
|
StopCmd: "",
|
||||||
|
Restart: "",
|
||||||
|
Setpgid: true,
|
||||||
|
CrashOnSafeExit: true,
|
||||||
|
LogOutput: true,
|
||||||
|
Filepath: service.Filepath,
|
||||||
|
filepathChecksum: checksum,
|
||||||
|
restartCount: service.restartCount,
|
||||||
|
stopChannel: service.stopChannel,
|
||||||
|
state: service.state,
|
||||||
|
}
|
||||||
|
if err := yaml.Unmarshal(bytes, &newService); err != nil {
|
||||||
|
logger.Printf("Error: could not read service file %s", service.Filepath)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, sv := range Services {
|
||||||
|
if sv.Name == newService.Name && sv != service {
|
||||||
|
logger.Printf("Error: service with name (%s) has already been initialized", service.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch newService.Type {
|
||||||
|
case "simple", "background":
|
||||||
|
default:
|
||||||
|
logger.Printf("Error: unknown service type (%s)", newService.Type)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch newService.ExitMethod {
|
||||||
|
case "stop_command", "kill":
|
||||||
|
default:
|
||||||
|
logger.Printf("Error: unknown exit method (%s)\n", newService.ExitMethod)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch newService.Restart {
|
||||||
|
case "true", "always":
|
||||||
|
default:
|
||||||
|
newService.Restart = "false"
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, sv := range Services {
|
||||||
|
if sv == service {
|
||||||
|
Services[i] = &newService
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Printf("Service (%s) has been reloaded!\n", newService.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (service *EnitService) StartService() (err error) {
|
||||||
if service == nil {
|
if service == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -126,7 +220,6 @@ func (service *EnitService) StartService() error {
|
|||||||
// Get log file if service logs output
|
// Get log file if service logs output
|
||||||
var logFile *os.File
|
var logFile *os.File
|
||||||
if service.LogOutput {
|
if service.LogOutput {
|
||||||
var err error
|
|
||||||
logFile, err = service.GetLogFile()
|
logFile, err = service.GetLogFile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -134,10 +227,38 @@ func (service *EnitService) StartService() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd := exec.Command("/bin/sh", "-c", "exec "+service.StartCmd)
|
cmd := exec.Command("/bin/sh", "-c", "exec "+service.StartCmd)
|
||||||
|
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: service.Setpgid, Pgid: 0}
|
||||||
if logFile != nil {
|
if logFile != nil {
|
||||||
cmd.Stdout = logFile
|
cmd.Stdout = logFile
|
||||||
cmd.Stderr = logFile
|
cmd.Stderr = logFile
|
||||||
}
|
}
|
||||||
|
var pipeReader, pipeWriter *os.File
|
||||||
|
if service.ReadyFd > 2 {
|
||||||
|
pipeReader, pipeWriter, err = os.Pipe()
|
||||||
|
if err != nil {
|
||||||
|
// Close log file if not nil
|
||||||
|
if logFile != nil {
|
||||||
|
logFile.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err := pipeReader.SetDeadline(time.Now().Add(10 * time.Second))
|
||||||
|
if err != nil {
|
||||||
|
// Close log file if not nil
|
||||||
|
if logFile != nil {
|
||||||
|
logFile.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 3; i < service.ReadyFd; i++ {
|
||||||
|
cmd.ExtraFiles = append(cmd.ExtraFiles, nil)
|
||||||
|
}
|
||||||
|
cmd.ExtraFiles = append(cmd.ExtraFiles, pipeWriter)
|
||||||
|
}
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
// Close log file if not nil
|
// Close log file if not nil
|
||||||
if logFile != nil {
|
if logFile != nil {
|
||||||
@@ -148,6 +269,28 @@ func (service *EnitService) StartService() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
service.processID = cmd.Process.Pid
|
service.processID = cmd.Process.Pid
|
||||||
|
service.state = EnitServiceStarting
|
||||||
|
|
||||||
|
// Wait for data from pipe
|
||||||
|
if pipeReader != nil {
|
||||||
|
buffer := make([]byte, 1)
|
||||||
|
_, err := io.ReadAtLeast(pipeReader, buffer, 1)
|
||||||
|
if err != nil {
|
||||||
|
// Close log file if not nil
|
||||||
|
if logFile != nil {
|
||||||
|
logFile.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Kill process and children
|
||||||
|
syscall.Kill(-service.processID, syscall.SIGKILL)
|
||||||
|
|
||||||
|
service.processID = 0
|
||||||
|
service.state = EnitServiceCrashed
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
service.state = EnitServiceRunning
|
service.state = EnitServiceRunning
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@@ -162,10 +305,21 @@ func (service *EnitService) StartService() error {
|
|||||||
case <-service.stopChannel:
|
case <-service.stopChannel:
|
||||||
service.restartCount = 0
|
service.restartCount = 0
|
||||||
default:
|
default:
|
||||||
|
// Kill remaining child processes
|
||||||
|
syscall.Kill(-service.processID, syscall.SIGKILL)
|
||||||
|
|
||||||
if service.Type == "simple" && err == nil {
|
if service.Type == "simple" && err == nil {
|
||||||
service.restartCount = 0
|
service.restartCount = 0
|
||||||
if service.ExitMethod != "stop_command" {
|
if service.ExitMethod != "stop_command" {
|
||||||
service.state = EnitServiceCompleted
|
service.state = EnitServiceCompleted
|
||||||
|
|
||||||
|
// Reload service if needed
|
||||||
|
if service.shouldReload {
|
||||||
|
service.ReloadService()
|
||||||
|
if GetServiceByName(service.Name) == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
service.state = EnitServiceRunning
|
service.state = EnitServiceRunning
|
||||||
}
|
}
|
||||||
@@ -179,6 +333,15 @@ func (service *EnitService) StartService() error {
|
|||||||
service.state = EnitServiceCrashed
|
service.state = EnitServiceCrashed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reload service if needed
|
||||||
|
if service.shouldReload {
|
||||||
|
service.ReloadService()
|
||||||
|
if GetServiceByName(service.Name) == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
service = GetServiceByName(service.Name)
|
||||||
|
}
|
||||||
|
|
||||||
if service.Restart == "always" {
|
if service.Restart == "always" {
|
||||||
_ = service.StartService()
|
_ = service.StartService()
|
||||||
} else if service.Restart == "true" && service.restartCount < 5 {
|
} else if service.Restart == "true" && service.restartCount < 5 {
|
||||||
@@ -206,11 +369,24 @@ func (service *EnitService) StopService() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logger.Printf("Stopping service (%s)...", service.Name)
|
logger.Printf("Stopping service (%s)...", service.Name)
|
||||||
|
pid := service.processID
|
||||||
|
|
||||||
newServiceStatus := EnitServiceCrashed
|
newServiceStatus := EnitServiceCrashed
|
||||||
defer func() {
|
defer func() {
|
||||||
|
// Kill remaining child processes
|
||||||
|
syscall.Kill(-pid, syscall.SIGKILL)
|
||||||
|
|
||||||
service.state = newServiceStatus
|
service.state = newServiceStatus
|
||||||
service.processID = 0
|
service.processID = 0
|
||||||
|
|
||||||
|
// Reload service if needed
|
||||||
|
if service.shouldReload {
|
||||||
|
service.ReloadService()
|
||||||
|
if GetServiceByName(service.Name) == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
service = GetServiceByName(service.Name)
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if service.ExitMethod == "kill" {
|
if service.ExitMethod == "kill" {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ func initSocket() (socket net.Listener, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Register command handlers
|
// Register command handlers
|
||||||
|
commandHandlers["reload"] = handleReloadServicesCommand
|
||||||
commandHandlers["start"] = handleStartServiceCommand
|
commandHandlers["start"] = handleStartServiceCommand
|
||||||
commandHandlers["stop"] = handleStopServiceCommand
|
commandHandlers["stop"] = handleStopServiceCommand
|
||||||
commandHandlers["restart"] = handleRestartServiceCommand
|
commandHandlers["restart"] = handleRestartServiceCommand
|
||||||
@@ -74,6 +75,13 @@ func listenToSocket() {
|
|||||||
}(conn)
|
}(conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleReloadServicesCommand(conn net.Conn, jsonData map[string]any) {
|
||||||
|
// Reload services
|
||||||
|
Reload()
|
||||||
|
|
||||||
|
conn.Write(wrapSuccessMsgInJson("Services reloaded successfully"))
|
||||||
|
}
|
||||||
|
|
||||||
func handleStartServiceCommand(conn net.Conn, jsonData map[string]any) {
|
func handleStartServiceCommand(conn net.Conn, jsonData map[string]any) {
|
||||||
// Get service name from json data
|
// Get service name from json data
|
||||||
serviceName, ok := jsonData["service"]
|
serviceName, ok := jsonData["service"]
|
||||||
|
|||||||
Reference in New Issue
Block a user