precaching changes

Added precache_agent and code to run it at the end of a Munki updatecheck. Updated make_munki_mpkg* scripts to include
the new precache_agent in the core package.
This commit is contained in:
Greg Neagle
2018-07-18 14:21:33 -07:00
parent 0716732a6f
commit 0c03c28b05
5 changed files with 63 additions and 4 deletions

View File

@@ -30,6 +30,7 @@ from . import catalogs
from . import download
from . import licensing
from . import manifestutils
from . import precaching
from .. import display
from .. import info
@@ -480,6 +481,9 @@ def check(client_id='', localmanifestpath=None):
installcount = len(installinfo.get('managed_installs', []))
removalcount = len(installinfo.get('removals', []))
# start our precaching agent
precaching.run_agent()
if installcount or removalcount:
return 1
else:

29
code/client/munkilib/updatecheck/precaching.py Normal file → Executable file
View File

@@ -15,19 +15,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""
precached
precaching
Created by Greg Neagle on 2018-05-06.
Module for precacheing optional installs with installed=False and precache=True.
Module for precaching optional installs with installed=False and precache=True.
"""
import os
import sys
from . import download
from .. import FoundationPlist
from .. import display
from .. import fetch
from .. import launchd
from .. import prefs
@@ -62,5 +64,28 @@ def cache():
item['name'], unicode(err))
def run_agent():
'''Kick off a run of our precaching agent, which allows the precaching to
run in the background after a normal Munki run'''
parent_dir = (
os.path.dirname(
os.path.dirname(
os.path.dirname(
os.path.abspath(__file__)))))
precache_agent_path = os.path.join(parent_dir, 'precache_agent')
if not os.path.exists(precache_agent_path):
# try absolute path in Munki's normal install dir
precache_agent_path = '/usr/local/munki/precache_agent'
if os.path.exists(precache_agent_path):
try:
job = launchd.Job([precache_agent_path] , cleanup_at_exit=False)
job.start()
except launchd.LaunchdJobException as err:
display.display_error(
'Error with launchd job (%s): %s', precache_agent_path, err)
else:
display.display_error("Could not find precache_agent")
if __name__ == '__main__':
print 'This is a library of support tools for the Munki Suite.'

30
code/client/precache_agent Executable file
View File

@@ -0,0 +1,30 @@
#!/usr/bin/python
# encoding: utf-8
#
# Copyright 2018 Greg Neagle.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
precache_agent
Created by Greg Neagle on 2018-07-18.
A privileged agent that downloads optional installs items marked for precaching.
"""
import time
from munkilib.updatecheck import precaching
if __name__ == '__main__':
precaching.cache()
time.sleep(10)