@@ -60,8 +60,7 @@ const (
6060 lastoreAutoUpdateToken UnitName = "lastoreAutoUpdateToken"
6161 watchOsVersion UnitName = "watchOsVersion"
6262 lastoreInitIdleDownload UnitName = "lastoreInitIdleDownload"
63- lastoreRegularlyUpdate UnitName = "lastoreRegularlyUpdate" // 到触发时间后开始检查更新->下载更新->安装更新
64- lastoreCronCheck UnitName = "lastoreCronCheck"
63+ lastoreRegularlyUpdate UnitName = "lastoreRegularlyUpdate"
6564 lastorePostUpgrade UnitName = "lastorePostUpgrade"
6665 lastoreRetryPostMsg UnitName = "lastoreRetryPostMsg"
6766)
@@ -79,8 +78,7 @@ func (m *Manager) getLastoreSystemUnitMap() lastoreUnitMap {
7978 unitMap := make (lastoreUnitMap )
8079 if (m .config .GetLastoreDaemonStatus ()& config .DisableUpdate ) == 0 && ! m .ImmutableAutoRecovery { // 更新禁用未开启且无忧还原未开启时
8180 unitMap [lastoreAutoCheck ] = genHandleEventCmdArgs ([]string {
82- // 随机数范围1800-21600,时间为0.5~6小时
83- fmt .Sprintf ("--on-active=%d" , int (m .getNextUpdateDelay ()/ time .Second )+ rand .New (rand .NewSource (time .Now ().UnixNano ())).Intn (m .config .StartCheckRange [1 ]- m .config .StartCheckRange [0 ])+ m .config .StartCheckRange [0 ])}, AutoCheck ) // 根据上次检查时间,设置下一次自动检查时间
81+ fmt .Sprintf ("--on-active=%d" , m .getNextAutoCheckDelay ())}, AutoCheck )
8482 }
8583 unitMap [lastoreAutoClean ] = genHandleEventCmdArgs ([]string {
8684 "--on-active=600" }, AutoClean ) // 10分钟后自动检查是否需要清理
@@ -260,31 +258,6 @@ func (m *Manager) updateTimerUnit(unitName UnitName) error {
260258 return nil
261259}
262260
263- func (m * Manager ) startCheckPolicyTask () {
264- if m .config .CheckPolicyInterval == 0 {
265- logger .Info ("config: not CheckPolicyInterval" )
266- return
267- }
268-
269- args := []string {
270- fmt .Sprintf ("--unit=%s" , lastoreCronCheck ),
271- fmt .Sprintf ("--on-active=%d" , m .config .CheckPolicyInterval ),
272- fmt .Sprintf (`--on-unit-active=%d` , m .config .CheckPolicyInterval ),
273- "--uid=root" ,
274- "/usr/bin/lastore-tools" ,
275- "checkpolicy" ,
276- }
277- cmd := exec .Command (run , args ... )
278- logger .Info (cmd .String ())
279- var errBuffer bytes.Buffer
280- cmd .Stderr = & errBuffer
281- err := cmd .Run ()
282- if err != nil {
283- logger .Warning (err )
284- logger .Warning (errBuffer .String ())
285- }
286- }
287-
288261func (m * Manager ) handleAutoDownload () {
289262 if m .ImmutableAutoRecovery {
290263 logger .Debug ("Immutable auto recovery is enabled, don't allow to auto download" )
@@ -332,6 +305,24 @@ func (m *Manager) getNextUpdateDelay() time.Duration {
332305 return remained + _minDelayTime
333306}
334307
308+ func (m * Manager ) getNextAutoCheckDelay () int {
309+ checkInterval := m .config .CheckInterval
310+ if checkInterval < 0 {
311+ checkInterval = 0
312+ }
313+
314+ elapsed := time .Since (m .config .LastCheckTime )
315+ remained := int ((checkInterval - elapsed ) / time .Second )
316+ if remained < 0 {
317+ remained = 0
318+ }
319+
320+ randomDelay := rand .New (rand .NewSource (time .Now ().UnixNano ())).Intn (m .config .StartCheckRange [1 ]- m .config .StartCheckRange [0 ]) + m .config .StartCheckRange [0 ]
321+ autoCheckDelay := remained + randomDelay
322+ logger .Infof ("get next auto check delay, StartCheckRange=%v, randomDelay=%d, autoCheckDelay=%d" , m .config .StartCheckRange , randomDelay , autoCheckDelay )
323+ return autoCheckDelay
324+ }
325+
335326// isAllowedToTriggerSystemEvent checks if the uid is allowed to trigger system events
336327func isAllowedToTriggerSystemEvent (uid uint32 , eventType systemdEventType ) bool {
337328 // Allow regular users to trigger OsVersionChanged event
@@ -384,7 +375,6 @@ func (m *Manager) delHandleSystemEvent(sender dbus.Sender, eventType string) err
384375 if err != nil {
385376 logger .Warning (err )
386377 }
387- m .startCheckPolicyTask () // 在第一次自动检查更新后再加任务
388378 }()
389379 case AutoClean :
390380 go func () {
0 commit comments