标签:style blog color io os ar for 文件 div
决定看salt的源码了.干脆就从最基本的看起来,先看它的启动过程开始
第一步用/etc/init.d/salt-master start 启动
找到那个文件,发现有3种启动方式,suse,debian,centos的启动方式各不一样,我测试机和线上环境都是centos的,所以直接就看Centos的
...... PYTHON=/usr/bin/python SALTMASTER=/usr/bin/salt-master MASTER_ARGS="" ...... stat() { ...... elif $PYTHON $SALTMASTER -d $MASTER_ARGS >& /dev/null; then echo -n "OK" RETVAL=0 ...... } .......
从这个脚本看到其实就是执行了/usr/bin/salt-master 这个文件
继续往下查看文件 /usr/bin/salt-master
文件的全部类容就几行
#!/usr/bin/python ‘‘‘ Start the salt-master ‘‘‘ from salt.scripts import salt_master if __name__ == ‘__main__‘: salt_master()
调用了salt.scripts下的salt_master 函数
找到目标文件和目标函数/usr/lib/python2.6/site-packages/salt/script.py
#!/usr/bin/python import os import sys # Import salt libs import salt #包含本身的模块 路径:/usr/lib/python2.6/site-packages/salt/__init__.py import salt.cli #这个暂时不知道干嘛的,以后再来分析 这个包含的路径是/usr/lib/python2.6/site-packages/salt/cli/__init__.py def salt_master(): ‘‘‘ Start the salt-master. ‘‘‘ master = salt.Master() master.start()
这里是调用了salt模块的Master类的start方法,我在salt目录下找了下没发现Master文件名相关的文件,那么一定就是在salt目录下的__init__.py文件里面
目标文件,目标类,目标类方法是在:/usr/lib/python2.6/site-packages/salt/__init__.py
class Master(parsers.MasterOptionParser): ‘‘‘ #这个类的继承是继承自/usr/lib/python2.6/site-packages/salt/utils/parser.py里面的 #这个parsers.py模块重写了自带的标准库optoarse.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‘], ‘jobs‘), 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‘]) except 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, ‘The 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() #这里调用自己的prepare的方法 if check_user(self.config[‘user‘]): try: self.master.start() except MasterExit: self.shutdown() finally: sys.exit() def shutdown(self): ‘‘‘ If sub-classed, run any shutdown operations on this method. ‘‘‘
一路追查下去,发现我2个24寸的显示器根本不够用,涉及的文件模块太多了
我都开始怀疑我到底是不是会python,我感觉我根本就没接触过python.....
我又恶补了一下关于python类的知识和optparse标准库
好吧,先休息一会出去走一下,放松自己凌乱的脑袋
标签:style blog color io os ar for 文件 div
原文地址:http://www.cnblogs.com/pping/p/3989699.html