inizio implementazione lock su user

This commit is contained in:
Miki 2015-10-16 11:43:18 +02:00
parent b2ae33be3b
commit 28521afda2
3 changed files with 21 additions and 2 deletions

9
dbs.go
View file

@ -22,6 +22,7 @@ type Dbs struct {
rdb *redis.Client
mdb *mgo.Session
ll *mgo.Collection
// us *mgo.Collection
}
type MongoLogin struct {
@ -29,7 +30,12 @@ type MongoLogin struct {
Protocol string `json:"protocol"`
Ip string `json:"ip"`
Date time.Time `json:"date"`
Read bool `json:"read"`
}
type UserLogin struct {
User string `json:"user"`
Date time.Time `json:"date"`
Lock bool `json:"lock"`
}
type Index struct {
@ -54,4 +60,5 @@ func (db *Dbs) connectMongo() {
os.Exit(-3)
}
db.ll = db.mdb.DB("dovecot").C("lastlogin")
// db.us = db.mdb.DB("dovecot").C("userlogin")
}

View file

@ -139,8 +139,12 @@ func main() {
Protocol: sval[0],
Ip: sval[2],
Date: time.Unix(date, 0),
Read: false,
}
// ul := UserLogin{
// User: user,
// Date: time.Unix(date, 0),
// Lock: false,
// }
ind := Index{
User: user,
Date: time.Unix(date, 0),
@ -155,6 +159,8 @@ func main() {
continue
}
}
// inserisce lo user nella collectione che gestira' il lock nella procedura di consolidamento
// _ err := dbs.us.Upsert(ind, ul)
// cancella da Redis la riga di login inserita
retval := dbs.rdb.Cmd("lrem", user, "-1", val)
log.Println("LREM retval: ", retval, user, val)

6
pid.go
View file

@ -20,6 +20,8 @@ type PID struct {
PIDFile string
}
// verifica se esiste il PIDFile;
// se esiste legge il PID e controlla se e' running il processo associato
func (p *PID) check() bool {
bpid, err := ioutil.ReadFile(p.PIDFile)
p.PID = strings.TrimRight(string(bpid), "\n")
@ -29,6 +31,8 @@ func (p *PID) check() bool {
return false
}
// controlla se esiste il processo associato al PID,
// se il cmd e' lo stesso e se e' in esecuzione.
func (p *PID) readCmd() bool {
bcmd, err := ioutil.ReadFile(path.Join("/proc", p.PID, "cmdline"))
// non esiste la dir relativa al PID su /proc
@ -46,6 +50,7 @@ func (p *PID) readCmd() bool {
return true
}
// scrive il PID nel PIDFile
func (p *PID) Write() {
if p.check() {
@ -62,6 +67,7 @@ func (p *PID) Write() {
fpid.Close()
}
// Cancella il PIDFile
func (p *PID) Remove() {
err := os.Remove(p.PIDFile)
if err != nil {