• saltstack 在window下 发布 service 服务


    saltstack 发布 service 服务

    如果是注册的服务发布:

      salt -L '172.16.3.39' state.sls service.deploy

    目录结构:

    /home/salt/servername
    ├── deploy.sls
    └── files
        └── servername

    server1.sls 配置示例:

    # cat server1.sls

    # 备份 声明变量
    {% set time = salt['cmd.run']('D:Scriptgetinfo.py gettime') %} {% set service_dirname = 'Service' %} {% set service_name = 'Server1' %}
    # 或者自设置批处理备份方式 backup_service: cmd.run: - name: D:ackup ar.bat
    # 窗口服务 除了 net stop service 还可以直接杀死进程 stop_service: cmd.run: - name: taskkill /im Server1.exe /f - require: - cmd: backup_service
    # 服务间歇 stop_sleep: cmd.run: - name: D:\Script\sleep.vbs - require: - cmd: stop_service # 服务发布 deploy_service: file.recurse: - name: D:\{{service_dirname}} - source: - salt://Service/Server1 - require: - cmd: stop_sleep # 服务启动 start_service: cmd.run: - name: net start {{service_name}} - require: - file: deploy_service

    同样的发布指令:

      salt -L '172.16.3.39' state.sls service.server1

    相关脚本参考:

    getinfo.py

    #coding=utf-8
    import os
    import time
    import sys
    
    def getTime(*vars):
        date = time.strftime("%Y%m%d", time.localtime(time.time()))
        return date
    
    def getLastBackup(*vars):
        if not os.path.exists(vars[0]):
            print '%r: 备份路径不存在' % vars[0]
            sys.exit(1)
        try:
            os.chdir(vars[0])
        except OSError, e:
            print e
            sys.exit(1)
        else:
            lastbackup = sorted(os.listdir(os.curdir)).pop()
            return lastbackup
    
    def usage():
        print 'Usage: python getinfo.py [ gettime | getbackup <service>]'
    
    funcdict = {'gettime': getTime, 'getbackup': getLastBackup}
    
    def main():
        if len(sys.argv) < 2:
            usage()
            sys.exit(1)
    
        option = sys.argv[1:]
        if option[0] in funcdict.keys():
            print funcdict[option[0]](*option[1:])
        else:
            usage()
    
    if __name__ == '__main__':
        main()

    压缩备份 rar.bat 

    set "today=%Date:~3,4%%Date:~8,2%%Date:~11,2%"
    md D:\backup\%today%
    "C:Program Files (x86)WinRARWinRAR.exe" a D:ackup\%today%DcApi_%today%.rar -x D:Serviceserver1Logs D:Serviceserver1

    sleep.vbs

    WScript.sleep 5000 
  • 相关阅读:
    手机获取ip地址
    CoreGraphics 自定义button
    抽奖及背景图片的透明度设置时连着转盘图片也跟着虚幻解决方法
    多个UIcollctionView,返回个数不对错误
    collectionview item 间距
    判断键盘的高度
    orcle 11g 的安装图解
    clone()详解
    isAssignableFrom ,isInstance , Instanceof() 区别
    三元表达式
  • 原文地址:https://www.cnblogs.com/sharesdk/p/10821738.html
Copyright © 2020-2023  润新知