mirror of
https://github.com/seriousm4x/UpSnap.git
synced 2026-11-29 05:06:09 +00:00
Compare commits
5 Commits
4.1.2-beta.2
...
4.1.2
| Author | SHA1 | Date | |
|---|---|---|---|
| 86ed3c1c08 | |||
| 92a142b5ee | |||
| f351df6b88 | |||
| d50245ebaf | |||
| 2f3ad2fdcb |
@@ -2,9 +2,8 @@
|
||||
name: "\U0001F577️ Bug report"
|
||||
about: Create a report to help the project improve
|
||||
title: "[BUG]"
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
labels: ""
|
||||
assignees: ""
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
@@ -12,6 +11,7 @@ A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
@@ -20,7 +20,15 @@ Steps to reproduce the behavior:
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**UpSnap version**
|
||||
|
||||
```bash
|
||||
$ upsnap --version
|
||||
upsnap version 4.1.1
|
||||
```
|
||||
|
||||
**Logs**
|
||||
|
||||
```
|
||||
formatted logs here
|
||||
```
|
||||
|
||||
@@ -165,13 +165,13 @@ func RunWakeShutdown(app *pocketbase.PocketBase) {
|
||||
|
||||
func StopAll() {
|
||||
if PingRunning {
|
||||
logger.Info.Println("stopping ping cronjob")
|
||||
logger.Info.Println("Stopping ping cronjob")
|
||||
ctx := CronPing.Stop()
|
||||
<-ctx.Done()
|
||||
|
||||
}
|
||||
if WakeShutdownRunning {
|
||||
logger.Info.Println("stopping wake/shutdown cronjob")
|
||||
logger.Info.Println("Stopping wake/shutdown cronjob")
|
||||
ctx := CronWakeShutdown.Stop()
|
||||
<-ctx.Done()
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func ShutdownDevice(device *models.Record) error {
|
||||
logger.Info.Println("shutdown triggered for", device.GetString("name"))
|
||||
logger.Info.Println("Shutdown triggered for", device.GetString("name"))
|
||||
shutdown_cmd := device.GetString("shutdown_cmd")
|
||||
if shutdown_cmd == "" {
|
||||
return fmt.Errorf("%s: no shutdown_cmd definded", device.GetString("name"))
|
||||
@@ -31,9 +31,10 @@ func ShutdownDevice(device *models.Record) error {
|
||||
|
||||
ctx := context.Background()
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
cmd := exec.CommandContext(ctx, shell, shell_arg, shutdown_cmd)
|
||||
SetProcessAttributes(cmd)
|
||||
logger.Debug.Println(cmd)
|
||||
|
||||
var stderr bytes.Buffer
|
||||
cmd.Stderr = &stderr
|
||||
@@ -56,7 +57,6 @@ func ShutdownDevice(device *models.Record) error {
|
||||
if err := KillProcess(cmd.Process); err != nil {
|
||||
logger.Error.Println(err)
|
||||
}
|
||||
cancel()
|
||||
return fmt.Errorf("%s not offline after 2 minutes", device.GetString("name"))
|
||||
}
|
||||
isOnline := PingDevice(device)
|
||||
@@ -64,7 +64,6 @@ func ShutdownDevice(device *models.Record) error {
|
||||
if err := KillProcess(cmd.Process); err != nil {
|
||||
logger.Error.Println(err)
|
||||
}
|
||||
cancel()
|
||||
return nil
|
||||
}
|
||||
case err := <-done:
|
||||
@@ -72,7 +71,6 @@ func ShutdownDevice(device *models.Record) error {
|
||||
if err := KillProcess(cmd.Process); err != nil {
|
||||
logger.Error.Println(err)
|
||||
}
|
||||
cancel()
|
||||
return fmt.Errorf("%s", stderr.String())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
package networking
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"github.com/seriousm4x/upsnap/logger"
|
||||
)
|
||||
|
||||
// Set platform specifiy custom process attributes
|
||||
func SetProcessAttributes(cmd *exec.Cmd) {
|
||||
cmd.SysProcAttr = &unix.SysProcAttr{Setpgid: true}
|
||||
}
|
||||
|
||||
// Kills child processes on Linux. Windows doesn't provide a direct way to kill child processes, so we kill just the main process.
|
||||
func KillProcess(process *os.Process) error {
|
||||
pgid, err := unix.Getpgid(process.Pid)
|
||||
logger.Debug.Println(pgid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return unix.Kill(-pgid, unix.SIGKILL)
|
||||
}
|
||||
@@ -1,19 +1,35 @@
|
||||
//go:build !linux
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package networking
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
"github.com/seriousm4x/upsnap/logger"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// Set platform specifiy custom process attributes
|
||||
func SetProcessAttributes(cmd *exec.Cmd) {}
|
||||
func SetProcessAttributes(cmd *exec.Cmd) {
|
||||
cmd.SysProcAttr = &unix.SysProcAttr{Setpgid: true}
|
||||
}
|
||||
|
||||
// Kills child processes on Linux. Windows doesn't provide a direct way to kill child processes, so we kill just the main process.
|
||||
func KillProcess(process *os.Process) error {
|
||||
if err := process.Kill(); err != nil {
|
||||
logger.Warning.Println("Your shutdown cmd didn't finish in 2 minutes. It will be killed.")
|
||||
pgid, err := unix.Getpgid(process.Pid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
err = unix.Kill(-pgid, unix.SIGTERM)
|
||||
if err != nil {
|
||||
return unix.Kill(-pgid, unix.SIGKILL)
|
||||
}
|
||||
|
||||
_, err = process.Wait()
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package networking
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
// Set platform specifiy custom process attributes
|
||||
func SetProcessAttributes(cmd *exec.Cmd) {}
|
||||
|
||||
// Kills child processes on Linux. Windows doesn't provide a direct way to kill child processes, so we kill just the main process.
|
||||
func KillProcess(process *os.Process) error {
|
||||
return windows.GenerateConsoleCtrlEvent(windows.CTRL_BREAK_EVENT, uint32(process.Pid))
|
||||
}
|
||||
@@ -16,7 +16,7 @@ type SolResponse struct {
|
||||
}
|
||||
|
||||
func SleepDevice(device *models.Record) (SolResponse, error) {
|
||||
logger.Info.Println("sleep triggered for", device.GetString("name"))
|
||||
logger.Info.Println("Sleep triggered for", device.GetString("name"))
|
||||
|
||||
var solResp SolResponse
|
||||
var url string
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func WakeDevice(device *models.Record) error {
|
||||
logger.Info.Println("wake triggered for", device.GetString("name"))
|
||||
logger.Info.Println("Wake triggered for", device.GetString("name"))
|
||||
err := SendMagicPacket(device)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user