-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add daemon; hooks before/after xref-building; bugs;
- Loading branch information
Showing
18 changed files
with
646 additions
and
110 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
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 |
---|---|---|
|
@@ -36,7 +36,7 @@ var ( | |
}, | ||
SubCommands: []*cmdr.Command{ | ||
// generatorCommands, | ||
serverCommands, | ||
// serverCommands, | ||
msCommands, | ||
}, | ||
}, | ||
|
@@ -48,65 +48,6 @@ var ( | |
Author: "Hedzr Yeh <[email protected]>", | ||
} | ||
|
||
serverCommands = &cmdr.Command{ | ||
BaseOpt: cmdr.BaseOpt{ | ||
// Name: "server", | ||
Short: "s", | ||
Full: "server", | ||
Aliases: []string{"serve", "svr"}, | ||
Description: "server ops: for linux service/daemon.", | ||
}, | ||
SubCommands: []*cmdr.Command{ | ||
{ | ||
BaseOpt: cmdr.BaseOpt{ | ||
Short: "s", | ||
Full: "start", | ||
Aliases: []string{"run", "startup"}, | ||
Description: "startup this system service/daemon.", | ||
}, | ||
}, | ||
{ | ||
BaseOpt: cmdr.BaseOpt{ | ||
Short: "t", | ||
Full: "stop", | ||
Aliases: []string{"stp", "halt", "pause"}, | ||
Description: "stop this system service/daemon.", | ||
}, | ||
}, | ||
{ | ||
BaseOpt: cmdr.BaseOpt{ | ||
Short: "r", | ||
Full: "restart", | ||
Aliases: []string{"reload"}, | ||
Description: "restart this system service/daemon.", | ||
}, | ||
}, | ||
{ | ||
BaseOpt: cmdr.BaseOpt{ | ||
Full: "status", | ||
Aliases: []string{"st"}, | ||
Description: "display its running status as a system service/daemon.", | ||
}, | ||
}, | ||
{ | ||
BaseOpt: cmdr.BaseOpt{ | ||
Short: "i", | ||
Full: "install", | ||
Aliases: []string{"setup"}, | ||
Description: "install as a system service/daemon.", | ||
}, | ||
}, | ||
{ | ||
BaseOpt: cmdr.BaseOpt{ | ||
Short: "u", | ||
Full: "uninstall", | ||
Aliases: []string{"remove"}, | ||
Description: "remove from a system service/daemon.", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
msCommands = &cmdr.Command{ | ||
BaseOpt: cmdr.BaseOpt{ | ||
Name: "microservices", | ||
|
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,65 @@ | ||
/* | ||
* Copyright © 2019 Hedzr Yeh. | ||
*/ | ||
|
||
package svr | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hedzr/cmdr" | ||
"github.com/hedzr/cmdr/plugin/daemon" | ||
"github.com/sirupsen/logrus" | ||
"os" | ||
"time" | ||
) | ||
|
||
func NewDaemon() daemon.Daemon { | ||
return &DaemonImpl{} | ||
} | ||
|
||
type DaemonImpl struct { | ||
} | ||
|
||
func (*DaemonImpl) OnRun(cmd *cmdr.Command, args []string, stopCh, doneCh chan struct{}) (err error) { | ||
logrus.Debugf("demo daemon OnRun, pid = %v, ppid = %v", os.Getpid(), os.Getppid()) | ||
go worker(stopCh, doneCh) | ||
return | ||
} | ||
|
||
func worker(stopCh, doneCh chan struct{}) { | ||
LOOP: | ||
for { | ||
time.Sleep(time.Second) // this is work to be done by worker. | ||
select { | ||
case <-stopCh: | ||
break LOOP | ||
default: | ||
} | ||
} | ||
doneCh <- struct{}{} | ||
} | ||
|
||
func (*DaemonImpl) OnStop(cmd *cmdr.Command, args []string) (err error) { | ||
logrus.Debugf("demo daemon OnStop") | ||
return | ||
} | ||
|
||
func (*DaemonImpl) OnReload() { | ||
logrus.Debugf("demo daemon OnReload") | ||
} | ||
|
||
func (*DaemonImpl) OnStatus(cxt *daemon.Context, cmd *cmdr.Command, p *os.Process) (err error) { | ||
fmt.Printf("%v v%v\n", cmd.GetRoot().AppName, cmd.GetRoot().Version) | ||
fmt.Printf("PID=%v\nLOG=%v\n", cxt.PidFileName, cxt.LogFileName) | ||
return | ||
} | ||
|
||
func (*DaemonImpl) OnInstall(cxt *daemon.Context, cmd *cmdr.Command, args []string) (err error) { | ||
logrus.Debugf("demo daemon OnInstall") | ||
panic("implement me") | ||
} | ||
|
||
func (*DaemonImpl) OnUninstall(cxt *daemon.Context, cmd *cmdr.Command, args []string) (err error) { | ||
logrus.Debugf("demo daemon OnUninstall") | ||
panic("implement me") | ||
} |
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
Oops, something went wrong.