diff --git a/app/main.go b/app/main.go index 55ddb811..6cfa2ab3 100644 --- a/app/main.go +++ b/app/main.go @@ -89,16 +89,21 @@ func main() { return } + if opts.DevPasswd != "" { + log.Printf("[WARN] running in dev mode") + } + dataService := store.Service{Interface: dataStore, EditDuration: 5 * time.Minute} sessionStore := func() sessions.Store { sess := sessions.NewFilesystemStore(opts.ServerCommand.SessionStore, []byte(opts.ServerCommand.StoreKey)) sess.Options.HttpOnly = true sess.Options.Secure = true sess.Options.MaxAge = 3600 * 24 * 365 + sess.Options.Path = "/" return sess }() - exporter := migrator.Remark{DataStore: dataStore} + exporter := &migrator.Remark{DataStore: dataStore} avatarProxy := &auth.AvatarProxy{ StorePath: opts.ServerCommand.AvatarStore, @@ -107,10 +112,12 @@ func main() { DefaultAvatar: opts.ServerCommand.DefaultAvatar, } + activateBackup(exporter) + srv := api.Rest{ Version: revision, DataService: dataService, - Exporter: &exporter, + Exporter: exporter, Authenticator: auth.Authenticator{ Admins: opts.Admins, SessionStore: sessionStore, @@ -122,22 +129,21 @@ func main() { Cache: rest.NewLoadingCache(4*time.Hour, 15*time.Minute, postFlushFn), Notifier: notifier.NewNoOperation(), } + srv.Run(opts.ServerCommand.Port) +} - if opts.DevPasswd != "" { - log.Printf("[WARN] running in dev mode") - } - +// activateBackup runs background backups for each site +func activateBackup(exporter migrator.Exporter) { for _, siteID := range opts.Sites { - go migrator.AutoBackup{ + backup := migrator.AutoBackup{ Exporter: &exporter, BackupLocation: opts.BackupLocation, SiteID: siteID, KeepMax: opts.MaxBackupFiles, Duration: 24 * time.Hour, - }.Do() + } + go backup.Do() } - - srv.Run(opts.ServerCommand.Port) } // makeBoltStore creates store for all sites diff --git a/app/store/bolt.go b/app/store/bolt.go index 81393e2f..4802cada 100644 --- a/app/store/bolt.go +++ b/app/store/bolt.go @@ -521,7 +521,7 @@ func (b *BoltDB) load(bkt *bolt.Bucket, key []byte) (comment Comment, err error) return comment, nil } -// count adds val to counts key postURL. val can be negative to substruct. if val 0 can be used as accessor +// count adds val to counts key postURL. val can be negative to subtract. if val 0 can be used as accessor // it uses separate counts bucket because boltdb Stat call is very slow func (b *BoltDB) count(tx *bolt.Tx, postURL string, val int) (int, error) {