#!/usr/bin/env python
'''
This script is used to kick off a salt minion daemon
'''

import salt.ext.six as six
import salt.utils.platform
from salt.scripts import salt_minion
from multiprocessing import freeze_support


if __name__ == '__main__':
    if salt.utils.platform.is_windows():
        # Since this file does not have a '.py' extension, when running on
        # Windows, spawning any addional processes will fail due to Python
        # not being able to load this 'module' in the new process.
        # Work around this by creating a '.pyc' file which will enable the
        # spawned process to load this 'module' and proceed.
        import os.path
        import py_compile
        cfile = os.path.splitext(__file__)[0] + '.pyc'
        if not os.path.exists(cfile):
            py_compile.compile(__file__, cfile)
# REMOVEME after Python 2.7 support is dropped (also the six import)
    elif six.PY2:
        from salt.utils.versions import warn_until
        # Message borrowed from pip's deprecation warning
        warn_until('Sodium',
                   'Python 2.7 will reach the end of its life on January 1st,'
                   ' 2020. Please upgrade your Python as Python 2.7 won\'t be'
                   ' maintained after that date.  Salt will drop support for'
                   ' Python 2.7 in the Sodium release or later.')
# END REMOVEME
    # This handles the bootstrapping code that is included with frozen
    # scripts. It is a no-op on unfrozen code.
    freeze_support()
    salt_minion()
