wip: feat(task): defined concrete type for user group

wip: feat(version): added placeholder file + update gitignore
wip: chore: removed unnecessary files
This commit is contained in:
Suyono 2024-01-11 13:13:33 +11:00
parent cdc66a2c22
commit 1926598c0f
10 changed files with 45 additions and 30 deletions

1
.gitignore vendored
View File

@ -1,4 +1,3 @@
/cmd/wingmate/wingmate
/cmd/wingmate/version.txt
/cmd/pidproxy/pidproxy
/cmd/exec/exec

View File

@ -3,7 +3,7 @@ all:
go build -v
clean:
rm version.txt
echo "dev" > version.txt
go clean -i -cache -testcache
install:

1
cmd/wingmate/version.txt Normal file
View File

@ -0,0 +1 @@
dev

View File

@ -1,6 +1,7 @@
package main
import (
_ "embed"
"os"
"gitea.suyono.dev/suyono/wingmate"
@ -8,6 +9,11 @@ import (
wminit "gitea.suyono.dev/suyono/wingmate/init"
)
var (
//go:embed version.txt
version string
)
func main() {
var (
err error

View File

@ -33,21 +33,23 @@ type Task struct {
Setsid bool `mapstructure:"setsid"`
User string `mapstructure:"user"`
Group string `mapstructure:"group"`
Background bool `mapstructure:"background"`
WorkingDir string `mapstructure:"working_dir"`
}
type ServiceTask struct {
Name string `mapstructure:"-"`
Task `mapstructure:",squash"`
AutoStart bool `mapstructure:"autostart"`
AutoRestart bool `mapstructure:"autorestart"`
Name string `mapstructure:"-"`
Background bool `mapstructure:"background"`
PidFile string `mapstructure:"pidfile"`
StartSecs uint `mapstructure:"startsecs"`
AutoStart bool `mapstructure:"autostart"`
AutoRestart bool `mapstructure:"autorestart"`
}
type CronTask struct {
Name string `mapstructure:"-"`
CronSchedule `mapstructure:"-"`
Task `mapstructure:",squash"`
Name string `mapstructure:"-"`
Schedule string `mapstructure:"schedule"`
}

View File

@ -1,9 +0,0 @@
package testconfig
var One = `service:
one:
command: "mycommand -o output"
two:
command: ["cmd", "now"]
workdir: /
`

View File

@ -1,6 +0,0 @@
service:
one:
command: "mycommand -o output"
two:
command: ["cmd", "now"]
workdir: /

View File

@ -14,6 +14,8 @@ type Tasks interface {
}
type UserGroup interface {
String() string
IsSet() bool
}
type TaskStatus interface {
@ -37,6 +39,7 @@ type CronTask interface {
type ServiceTask interface {
Task
Background() bool //NOTE: implies using wmpidproxy
PidFile() string //NOTE: implies using wmpidproxy
StartSecs() uint
AutoStart() bool
AutoRestart() bool

View File

@ -68,12 +68,11 @@ func (cms *CronMultiOccurrenceSpec) Match(u uint8) bool {
type CronTask struct {
CronSchedule
userGroup
name string
command []string
environ []string
setsid bool
user string
group string
workingDir string
lastRun time.Time
hasRun bool //NOTE: make sure initialised as false
@ -144,8 +143,7 @@ func (c *CronTask) Setsid() bool {
}
func (c *CronTask) UserGroup() wminit.UserGroup {
panic("not implemented")
return nil
return &(c.userGroup)
}
func (c *CronTask) WorkingDir() string {

View File

@ -1,6 +1,7 @@
package task
import (
"fmt"
wminit "gitea.suyono.dev/suyono/wingmate/init"
)
@ -63,11 +64,10 @@ type ServiceTask struct {
command []string
environ []string
setsid bool
user string
group string
background bool
workingDir string
startSecs uint
userGroup
}
func NewServiceTask(name string) *ServiceTask {
@ -139,8 +139,7 @@ func (t *ServiceTask) Setsid() bool {
}
func (t *ServiceTask) UserGroup() wminit.UserGroup {
panic("not implemented")
return nil
return &(t.userGroup)
}
func (t *ServiceTask) Background() bool {
@ -172,3 +171,25 @@ func (t *ServiceTask) StartSecs() uint {
panic("not implemented")
return 0
}
func (t *ServiceTask) PidFile() string {
panic("not implemented")
return ""
}
type userGroup struct {
user string
group string
}
func (ug *userGroup) IsSet() bool {
return len(ug.user) > 0 || len(ug.group) > 0
}
func (ug *userGroup) String() string {
if len(ug.group) > 0 {
return fmt.Sprintf("%s:%s", ug.user, ug.group)
}
return ug.user
}