tis-cwrsync

3.1.1-3
install of a cwRsync daemon manages by nssm. rsyncd.conf must be customized to suit your needs. meant to be used with tisbackup for example.
3322 downloads
Download
default icon

  Description 

  • package : tis-cwrsync
  • version : 3.1.1-3
  • architecture : all
  • categories :
  • maintainer : Hubert TOUVET
  • description : install of a cwRsync daemon manages by nssm. rsyncd.conf must be customized to suit your needs. meant to be used with tisbackup for example.
  • locale :
  • target_os :
  • min_wapt_version :
  • sources : https://srvdev/sources/tis-cwrsync-wapt/trunk
  • installed_size :
  • impacted_process :
  • description_fr :
  • description_pl :
  • description_de :
  • description_es :
  • description_pt :
  • description_it :
  • description_nl :
  • description_ru :
  • editor :
  • licence :
  • signature_date : 2020-02-27T15:02:45.629600

  Setup.py 

# -*- coding: utf-8 -*-
from setuphelpers import *
from iniparse import RawConfigParser
import string,random


uninstallkey = []

service_name = 'cwRsync'
portnumber = 873

install_path = makepath(programfiles32,service_name)
nssm_path = makepath(install_path,'nssm.exe')
rsync_conf = makepath(install_path,'rsyncd.conf')
rsync_secrets = makepath(install_path,'rsyncd.secrets')
rsync_log = makepath(install_path,'rsyncd.log')

def install():
    print('installing tis-cwrsync')

    if service_installed(service_name) and  not service_is_stopped(service_name):
        print('Stopping rsync service')
        service_stop(service_name)

    print('Copy of cwRsync binaries')
    copytree2('cwRsync',install_path)
    if not isfile(nssm_path):
        print('Copy of nssm binary')
        if iswin64():
            filecopyto(makepath('win64','nssm.exe'),nssm_path)
        else:
            filecopyto(makepath('win32','nssm.exe'),nssm_path)


    if not isfile(rsync_conf):
        print('Adding a rsyncd.conf file')
        filecopyto('rsyncd.conf',rsync_conf)
    else:
        print('Keeping existing rsyncd.conf file')


    if not isfile(rsync_secrets):
        print('Create a secrets file')
        password = ''.join(random.choice(string.ascii_letters + string.digits) for x in range(20))
        open(rsync_secrets,'w').write('root:%s'%password)
        print('root password is %s'% password)
    else:
        print('Keep existing secrets file')

    print('Open firewall')
    check_open_port()

    print('Install service with nssm manager')
    install_service()

    print('Start rsync service')
    service_start(service_name)


def check_open_port():
    """Configure local firewall to accept incoming request to specified tcp port
    >>> check_open_port(8088)
    """
    import win32serviceutil
    import platform
    import win32service
    win_major_version = int(platform.win32_ver()[1].split('.')[0])
    try:
        if win_major_version<6:
            #check if firewall is running
            if win32serviceutil.QueryServiceStatus( 'SharedAccess', None)[1]==win32service.SERVICE_RUNNING:
                print(u"Firewall started, checking for port openning...")
                #WinXP 2003
                if service_name not in run_notfatal('netsh firewall show portopening'):
                    print(u"Adding a firewall rule to open port %s"%portnumber)
                    print run_notfatal("""netsh.exe firewall add portopening name="%s %s" port=%s protocol=TCP profile=ALL"""%(service_name,portnumber,portnumber))
                else:
                    print(u"port %s already opened, skipping firewall configuration"%(portnumber,))
        else:
            if win32serviceutil.QueryServiceStatus('MpsSvc', None)[1]==win32service.SERVICE_RUNNING:
                print(u"Firewall started, checking for port openning...")
                if service_name not in run_notfatal('netsh advfirewall firewall show rule name="%s %s"'%(service_name,portnumber,)):
                    print(u"No port opened for %s, opening port %s"%(service_name,portnumber))
                    #win Vista and higher
                    print run_notfatal("""netsh advfirewall firewall add rule name="%s %s" dir=in action=allow protocol=TCP localport=%s """%(service_name,portnumber,portnumber))
                else:
                    print(u"port %s already opened, skipping firewall configuration"%(portnumber,))
    except Exception as e:
        print('Unable to check if port %s is opened : %s' % (portnumber,e))


def install_service(nssm_path=nssm_path,exe_path=None,exe_params=None):
    """Setup cwRsync as a windows Service managed by nssm
    >>> install_service()
    """
    datatypes = {
        'dword':REG_DWORD,
        'sz':REG_SZ,
        'expand_sz':REG_EXPAND_SZ,
        'multi_sz':REG_MULTI_SZ,
    }

    if service_installed(service_name):
        if not service_is_stopped(service_name):
            print(u'Stop running "%s"' % service_name)
            run('net stop "%s"' % service_name)
            while not service_is_stopped(service_name):
                print(u'Waiting for "%s" to terminate' % service_name)
                time.sleep(2)
        print(u'Unregister existing "%s"' % service_name)
        run('sc delete "%s"' % service_name)

    if not exe_path:
        exe_path = makepath(install_path,'rsync.exe')

    if not exe_params:
        exe_params = '--daemon --no-detach --config rsyncd.conf'

    print(u'Register new %s with nssm' % service_name)
    run('"{nssm_path}" install {service_name} "{exe_path}" "{exe_params}"'.format(
        service_name = service_name,
        exe_path = exe_path,
        nssm_path = nssm_path,
        exe_params = exe_params,
     ))

    # fix some parameters (quotes for path with spaces...
    params = {
        "Description": "sz:%s" % service_name,
        "DisplayName" : "sz:%s" % service_name,
        "AppStdout" : r"expand_sz:{}".format(rsync_log),
        "Parameters\\AppStderr" : r"expand_sz:{}".format(rsync_log),
        "Parameters\\AppParameters" : r'expand_sz:{}'.format(exe_params),
        }

    print('Set service parameters...')
    root = HKEY_LOCAL_MACHINE
    base = r'SYSTEM\CurrentControlSet\services\%s' % service_name
    for key in params:
        if isinstance(params[key],int):
            (valuetype,value) = ('dword',params[key])
        elif ':' in params[key]:
            (valuetype,value) = params[key].split(':',1)
            if valuetype == 'dword':
                value = int(value)
        else:
            (valuetype,value) = ('sz',params[key])
        fullpath = base+'\\'+key
        (path,keyname) = fullpath.rsplit('\\',1)
        if keyname == '@' or keyname =='':
            keyname = None
        registry_set(root,path,keyname,value,type = datatypes[valuetype])
        print(r'HKLM\%s : %s = %s' % (path,keyname,value))

def uninstall():
    if service_installed(service_name):
        if not service_is_stopped(service_name):
            print(u'Stop running "%s"' % service_name)
            run('net stop "%s"' % service_name)
            while not service_is_stopped(service_name):
                print(u'Waiting for "%s" to terminate' % service_name)
                time.sleep(2)
        print(u'Unregister service "%s"' % service_name)
        run('sc delete "%s"' % service_name)
    print('Remove service files')
    remove_tree(install_path)

    print('Remove firewall exception')
    # winxp
    run_notfatal("""netsh.exe firewall add portopening name="%s %s" port=%s protocol=TCP profile=ALL"""%(service_name,portnumber,portnumber))
    # win 7
    run_notfatal("""netsh advfirewall firewall add rule name="%s %s" dir=in action=allow protocol=TCP localport=%s"""%(service_name,portnumber,portnumber,))

										

  Changelog 



No changelog.txt.
									
  manifest.sha256