Source code of saltstack-start 1

Source: Internet
Author: User
Tags saltstack

I decided to look at the source code of salt. Simply look at it from the basic perspective, first look at its startup process.
Step 1 start with/etc/init. d/salt-master start
Find the file and find that there are three startup Methods: Suse, Debian, and centos. My testing machine and online environment are centos, so you can directly look at centos's

......PYTHON=/usr/bin/pythonSALTMASTER=/usr/bin/salt-masterMASTER_ARGS=""......stat() {    ......    elif $PYTHON $SALTMASTER -d $MASTER_ARGS >& /dev/null; then            echo -n "OK"            RETVAL=0    ......}.......

From this script, the file/usr/bin/salt-master is actually executed.
Continue to view the file/usr/bin/salt-Master
Only a few lines are supported for all classes of the file.

#!/usr/bin/python‘‘‘Start the salt-master‘‘‘from salt.scripts import salt_master if __name__ == ‘__main__‘:    salt_master()

The salt_master function in salt. scripts is called.
Find the target file and function/usr/lib/python2.6/Site-packages/salt/script. py

#! /Usr/bin/pythonimport osimport sys # import salt libsimport salt # contains its own module path:/usr/lib/python2.6/Site-packages/salt/_ init __. pyimport salt. CLI # I don't know what to do for the moment. I will analyze the included path later:/usr/lib/python2.6/Site-packages/salt/CLI/_ init __. PY def salt_master (): '''start the salt-master. '''master = salt. master () master. start ()

The start method of the master class of the salt module is called. I found no files related to the master file name in the salt directory, it must be _ init _ in the salt directory __. in The py file
Target file, target class, and target class methods are:/usr/lib/python2.6/Site-packages/salt/_ init _. py

Class master (parsers. masteroptionparser): ''' # the inheritance of this class is inherited from/usr/lib/python2.6/Site-packages/salt/utils/parser. # This parsers in Py. the py module overrides the built-in standard library optoarse. several methods of Py creates a master server ''' def prepare (Self): ''' run the preparation sequence required to start a salt master server. if sub-classed, don't ** ever ** forget to run: Super (yoursubclass, self ). prepare () ''' self. parse_args () Try: If self. config ['verify _ env']: verify_env ([self. config ['pki _ dir'], OS. path. join (self. config ['pki _ dir'], 'minions'), OS. path. join (self. config ['pki _ dir'], 'minions _ pre'), OS. path. join (self. config ['pki _ dir'], 'minions _ rejected'), self. config ['cachedir'], OS. path. join (self. config ['cachedir'], 'job'), OS. path. join (self. config ['cachedir'], 'proc'), self. config ['sock _ dir'], self. config ['token _ dir'],], self. config ['user'], permissive = self. config ['permissive _ pki_access '], pki_dir = self. config ['pki _ dir'],) logfile = self. config ['Log _ file'] If logfile is not none and not logfile. startswith ('tcp: // ', 'udp: //', 'file: // '): # logfile is not using syslog, verify verify_files ([logfile], self. config ['user']) Doesn't oserror as ERR: SYS. exit (err. errno) self. setup_logfile_logger () logger.info ('setting up the salt master') if not verify_socket (self. config ['interface'], self. config ['Publish _ port'], self. config ['ret _ port']): Self. exit (4, 'ports are not available to bind \ n') self. config ['interface'] = ip_bracket (self. config ['interface']) migrations. migrate_paths (self. config) # Late import so logging works correctly import salt. master self. master = salt. master. master (self. config) self. daemonize_if_required () self. set_pidfile () def start (Self): ''' start the actual master. if sub-classed, don't ** ever ** forget to run: Super (yoursubclass, self ). start () Note: run any required code before calling 'super ()'. '''self. prepare () # Call your own prepare method here if check_user (self. config ['user']): Try: Self. master. start () tables t masterexit: Self. shutdown () Finally: SYS. exit () def Shutdown (Self): ''' if sub-classed, run any shutdown operations on this method. '''

After tracing, I found that my two 24-inch monitors were not enough and there were too many file modules involved.
I began to doubt whether I could use python. I feel that I have never touched python .....
I have supplemented my knowledge about Python and the optparse standard library.
Okay. Take a rest and take a walk to relax your messy head.

Source code of saltstack-start 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.