mirror of https://github.com/shunfei/cronsun
Merge branch 'master' of github.com:shunfei/cronsun into develop
commit
f52cc9d1bd
12
README.md
12
README.md
|
@ -53,7 +53,7 @@ We encourage you to try it, it's easy to use, see how it works for you. We belie
|
||||||
"users": [
|
"users": [
|
||||||
"www", "db"
|
"www", "db"
|
||||||
],
|
],
|
||||||
"#ext": "allowed execution file extension",
|
"#ext": "allowed execution file extensions",
|
||||||
"ext": [
|
"ext": [
|
||||||
".cron.sh", ".cron.py"
|
".cron.sh", ".cron.py"
|
||||||
]
|
]
|
||||||
|
@ -66,11 +66,13 @@ We encourage you to try it, it's easy to use, see how it works for you. We belie
|
||||||
|
|
||||||
Install from binary [latest release](https://github.com/shunfei/cronsun/releases/latest)
|
Install from binary [latest release](https://github.com/shunfei/cronsun/releases/latest)
|
||||||
|
|
||||||
Or build from source, require `go >= 1.9+`
|
Or build from source ([feature/glide](https://github.com/shunfei/cronsun/tree/feature/glide)), require `go >= 1.9+`, [glide](https://glide.sh/)
|
||||||
|
|
||||||
```
|
```
|
||||||
go get -u github.com/shunfei/cronsun
|
go get -u github.com/shunfei/cronsun
|
||||||
cd $GOPATH/src/github.com/shunfei/cronsun
|
cd $GOPATH/src/github.com/shunfei/cronsun
|
||||||
|
git checkout feature/glide
|
||||||
|
glide update
|
||||||
sh build.sh
|
sh build.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -78,9 +80,9 @@ sh build.sh
|
||||||
|
|
||||||
1. Install [MongoDB](http://docs.mongodb.org/manual/installation/)
|
1. Install [MongoDB](http://docs.mongodb.org/manual/installation/)
|
||||||
2. Install [etcd3](https://github.com/coreos/etcd)
|
2. Install [etcd3](https://github.com/coreos/etcd)
|
||||||
3. Modify config in `conf` dir
|
3. Open and update Etcd(`conf/etcd.json`) and MongoDB(`conf/db.json`) configurations
|
||||||
4. Start Node: `./cronnode -conf conf/base.json`, start Web: `./cronweb -conf conf/base.json`
|
4. Start cronnode: `./cronnode -conf conf/base.json`, start cronweb: `./cronweb -conf conf/base.json`
|
||||||
5. Opne `http://127.0.0.1:7079/ui/` with the browser
|
5. Open `http://127.0.0.1:7079` in browser
|
||||||
|
|
||||||
## Screenshot
|
## Screenshot
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ func main() {
|
||||||
if len(conf.Config.Mail.HttpAPI) > 0 {
|
if len(conf.Config.Mail.HttpAPI) > 0 {
|
||||||
noticer = &cronsun.HttpAPI{}
|
noticer = &cronsun.HttpAPI{}
|
||||||
} else {
|
} else {
|
||||||
mailer, err := cronsun.NewMail(10 * time.Second)
|
mailer, err := cronsun.NewMail(30 * time.Second)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf(err.Error())
|
log.Errorf(err.Error())
|
||||||
return
|
return
|
||||||
|
|
|
@ -22,7 +22,7 @@ type Client struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(cfg *conf.Conf) (c *Client, err error) {
|
func NewClient(cfg *conf.Conf) (c *Client, err error) {
|
||||||
cli, err := client.New(cfg.Etcd)
|
cli, err := client.New(cfg.Etcd.Copy())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -86,6 +86,12 @@ func (c *Client) Grant(ttl int64) (*client.LeaseGrantResponse, error) {
|
||||||
return c.Client.Grant(ctx, ttl)
|
return c.Client.Grant(ctx, ttl)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) Revoke(id client.LeaseID) (*client.LeaseRevokeResponse, error) {
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), c.reqTimeout)
|
||||||
|
defer cancel()
|
||||||
|
return c.Client.Revoke(ctx, id)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) KeepAliveOnce(id client.LeaseID) (*client.LeaseKeepAliveResponse, error) {
|
func (c *Client) KeepAliveOnce(id client.LeaseID) (*client.LeaseKeepAliveResponse, error) {
|
||||||
ctx, cancel := NewEtcdTimeoutContext(c)
|
ctx, cancel := NewEtcdTimeoutContext(c)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
21
conf/conf.go
21
conf/conf.go
|
@ -62,7 +62,7 @@ type Conf struct {
|
||||||
// 默认 300
|
// 默认 300
|
||||||
LockTtl int64
|
LockTtl int64
|
||||||
|
|
||||||
Etcd client.Config
|
Etcd *etcdConfig
|
||||||
Mgo *db.Config
|
Mgo *db.Config
|
||||||
Web *webConfig
|
Web *webConfig
|
||||||
Mail *MailConf
|
Mail *MailConf
|
||||||
|
@ -70,6 +70,19 @@ type Conf struct {
|
||||||
Security *Security
|
Security *Security
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type etcdConfig struct {
|
||||||
|
Endpoints []string
|
||||||
|
Username string
|
||||||
|
Password string
|
||||||
|
DialTimeout int64 // 单位秒
|
||||||
|
|
||||||
|
conf client.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *etcdConfig) Copy() client.Config {
|
||||||
|
return e.conf
|
||||||
|
}
|
||||||
|
|
||||||
type webConfig struct {
|
type webConfig struct {
|
||||||
BindAddr string
|
BindAddr string
|
||||||
Auth struct {
|
Auth struct {
|
||||||
|
@ -130,8 +143,12 @@ func (c *Conf) parse(confFile string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.Etcd.DialTimeout > 0 {
|
if c.Etcd.DialTimeout > 0 {
|
||||||
c.Etcd.DialTimeout *= time.Second
|
c.Etcd.conf.DialTimeout = time.Duration(c.Etcd.DialTimeout) * time.Second
|
||||||
}
|
}
|
||||||
|
c.Etcd.conf.Username = c.Etcd.Username
|
||||||
|
c.Etcd.conf.Password = c.Etcd.Password
|
||||||
|
c.Etcd.conf.Endpoints = c.Etcd.Endpoints
|
||||||
|
|
||||||
if c.Ttl <= 0 {
|
if c.Ttl <= 0 {
|
||||||
c.Ttl = 10
|
c.Ttl = 10
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,14 @@
|
||||||
"To": ["na@nb.com"],
|
"To": ["na@nb.com"],
|
||||||
"#HttpAPI": "如有此字段,则按 http api 方式发送",
|
"#HttpAPI": "如有此字段,则按 http api 方式发送",
|
||||||
"#Keepalive": "如果此时间段内没有邮件发送,则关闭 SMTP 连接,单位/秒",
|
"#Keepalive": "如果此时间段内没有邮件发送,则关闭 SMTP 连接,单位/秒",
|
||||||
"Keepalive": 30,
|
"Keepalive": 60,
|
||||||
"#doc": "https://godoc.org/github.com/go-gomail/gomail#Dialer",
|
"#doc": "https://godoc.org/github.com/go-gomail/gomail#Dialer",
|
||||||
"Host": "smtp.exmail.qq.com",
|
"Host": "smtp.exmail.qq.com",
|
||||||
"Port": 25,
|
"Port": 25,
|
||||||
"Username": "sendmail@nb.com",
|
"Username": "sendmail@nb.com",
|
||||||
"Password": "nbhh",
|
"Password": "nbhh",
|
||||||
"SSL": false,
|
"SSL": false,
|
||||||
"LocalName": "sendmail@nb.com"
|
"#LocalName": "LocalName is the hostname sent to the SMTP server with the HELO command.",
|
||||||
|
"#LocalName": "By default, "localhost" is sent.",
|
||||||
|
"LocalName": "localhost"
|
||||||
}
|
}
|
||||||
|
|
5
job.go
5
job.go
|
@ -119,8 +119,8 @@ func (l *locker) unlock() {
|
||||||
|
|
||||||
close(l.done)
|
close(l.done)
|
||||||
l.timer.Stop()
|
l.timer.Stop()
|
||||||
if _, err := DefalutClient.KeepAliveOnce(l.lID); err != nil {
|
if _, err := DefalutClient.Revoke(l.lID); err != nil {
|
||||||
log.Warnf("unlock keep alive err: %s", err.Error())
|
log.Warnf("unlock revoke err: %s", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,6 +307,7 @@ func (rule *JobRule) Valid() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note: this function did't check the job.
|
||||||
func GetJob(group, id string) (job *Job, err error) {
|
func GetJob(group, id string) (job *Job, err error) {
|
||||||
job, _, err = GetJobAndRev(group, id)
|
job, _, err = GetJobAndRev(group, id)
|
||||||
return
|
return
|
||||||
|
|
|
@ -332,6 +332,13 @@ func (n *Node) groupAddNode(g *cronsun.Group) {
|
||||||
n.link.delGroupJob(g.ID, jid)
|
n.link.delGroupJob(g.ID, jid)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err = job.Valid(); err != nil {
|
||||||
|
log.Warnf("invalid job[%s][%s]: %s", jl.gname, jid, err.Error())
|
||||||
|
n.link.delGroupJob(g.ID, jid)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
job.Init(n.ID, n.Hostname)
|
job.Init(n.ID, n.Hostname)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,9 +94,8 @@ func (m *Mail) Serve() {
|
||||||
if m.open {
|
if m.open {
|
||||||
if err = m.sc.Close(); err != nil {
|
if err = m.sc.Close(); err != nil {
|
||||||
log.Warnf("close smtp server err: %s", err.Error())
|
log.Warnf("close smtp server err: %s", err.Error())
|
||||||
} else {
|
|
||||||
m.open = false
|
|
||||||
}
|
}
|
||||||
|
m.open = false
|
||||||
}
|
}
|
||||||
m.timer.Reset(time.Duration(m.cf.Keepalive) * time.Second)
|
m.timer.Reset(time.Duration(m.cf.Keepalive) * time.Second)
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -53,14 +53,14 @@ export default {
|
||||||
data: function(){
|
data: function(){
|
||||||
return {
|
return {
|
||||||
log: {
|
log: {
|
||||||
id: 'sdfas',
|
id: '',
|
||||||
jobId: 'wewe',
|
jobId: '',
|
||||||
jobGroup: 'test',
|
jobGroup: '',
|
||||||
name: 'run run run',
|
name: '',
|
||||||
node: '192.168.1.2',
|
node: '',
|
||||||
user: '',
|
user: '',
|
||||||
command: 'echo hello;',
|
command: '',
|
||||||
output: 'hello',
|
output: '',
|
||||||
exitCode: 0,
|
exitCode: 0,
|
||||||
beginTime: new Date(),
|
beginTime: new Date(),
|
||||||
endTime: new Date()
|
endTime: new Date()
|
||||||
|
@ -72,7 +72,7 @@ export default {
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
printResult(){
|
printResult(){
|
||||||
return this.log.output.replace("\r\n", "^M\r\n");
|
return this.log.output ? this.log.output.replace("\r\n", "^M\r\n") : '';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue