Changeset View
Changeset View
Standalone View
Standalone View
pykolab/setup/setup_mta.py
Show All 12 Lines | |||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
# GNU General Public License for more details. | # GNU General Public License for more details. | ||||
# You should have received a copy of the GNU General Public License | # You should have received a copy of the GNU General Public License | ||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
# | # | ||||
from augeas import Augeas | from augeas import Augeas | ||||
from Cheetah.Template import Template | from jinja2 import Template | ||||
import os | import os | ||||
import shutil | import shutil | ||||
import subprocess | import subprocess | ||||
import components | import components | ||||
import pykolab | import pykolab | ||||
from pykolab import utils | from pykolab import utils | ||||
from pykolab.constants import * | from pykolab.constants import * | ||||
from pykolab.translate import _ | from pykolab.translate import _ | ||||
log = pykolab.getLogger('pykolab.setup') | log = pykolab.getLogger('pykolab.setup') | ||||
conf = pykolab.getConf() | conf = pykolab.getConf() | ||||
def __init__(): | def __init__(): | ||||
components.register('mta', execute, description=description(), after=['ldap']) | components.register('mta', execute, description=description(), after=['ldap']) | ||||
def description(): | def description(): | ||||
return _("Setup MTA.") | return _("Setup MTA.") | ||||
def execute(*args, **kw): | def execute(*args, **kw): | ||||
group_filter = conf.get('ldap','kolab_group_filter') | postfix_ldap_dir = '/etc/postfix/ldap' | ||||
if group_filter == None: | if not os.path.isdir(postfix_ldap_dir): | ||||
group_filter = conf.get('ldap','group_filter') | os.mkdir(postfix_ldap_dir, 0770) | ||||
user_filter = conf.get('ldap','kolab_user_filter') | # Get ldap config section into dictionary with interpolation | ||||
if user_filter == None: | config_ldap_dict = { | ||||
user_filter = conf.get('ldap','user_filter') | 'ldap': dict(conf.cfg_parser.items('ldap', raw=False)) | ||||
resource_filter = conf.get('ldap', 'resource_filter') | |||||
sharedfolder_filter = conf.get('ldap', 'sharedfolder_filter') | |||||
server_host = utils.parse_ldap_uri(conf.get('ldap', 'ldap_uri'))[1] | |||||
files = { | |||||
"/etc/postfix/ldap/local_recipient_maps.cf": """ | |||||
server_host = %(server_host)s | |||||
server_port = 389 | |||||
version = 3 | |||||
search_base = %(base_dn)s | |||||
scope = sub | |||||
domain = ldap:/etc/postfix/ldap/mydestination.cf | |||||
bind_dn = %(service_bind_dn)s | |||||
bind_pw = %(service_bind_pw)s | |||||
query_filter = (&(|(mail=%%s)(alias=%%s))(|%(kolab_user_filter)s%(kolab_group_filter)s%(resource_filter)s%(sharedfolder_filter)s)) | |||||
result_attribute = mail | |||||
""" % { | |||||
"base_dn": conf.get('ldap', 'base_dn'), | |||||
"server_host": server_host, | |||||
"service_bind_dn": conf.get('ldap', 'service_bind_dn'), | |||||
"service_bind_pw": conf.get('ldap', 'service_bind_pw'), | |||||
"kolab_user_filter": user_filter, | |||||
"kolab_group_filter": group_filter, | |||||
"resource_filter": resource_filter, | |||||
"sharedfolder_filter": sharedfolder_filter, | |||||
}, | |||||
"/etc/postfix/ldap/mydestination.cf": """ | |||||
server_host = %(server_host)s | |||||
server_port = 389 | |||||
version = 3 | |||||
search_base = %(domain_base_dn)s | |||||
scope = sub | |||||
bind_dn = %(service_bind_dn)s | |||||
bind_pw = %(service_bind_pw)s | |||||
query_filter = %(domain_filter)s | |||||
result_attribute = %(domain_name_attribute)s | |||||
""" % { | |||||
"server_host": server_host, | |||||
"domain_base_dn": conf.get('ldap', 'domain_base_dn'), | |||||
"domain_filter": conf.get('ldap', 'domain_filter').replace('*', '%s'), | |||||
"domain_name_attribute": conf.get('ldap', 'domain_name_attribute'), | |||||
"service_bind_dn": conf.get('ldap', 'service_bind_dn'), | |||||
"service_bind_pw": conf.get('ldap', 'service_bind_pw'), | |||||
}, | |||||
"/etc/postfix/ldap/mailenabled_distgroups.cf": """ | |||||
server_host = %(server_host)s | |||||
server_port = 389 | |||||
version = 3 | |||||
search_base = %(group_base_dn)s | |||||
scope = sub | |||||
domain = ldap:/etc/postfix/ldap/mydestination.cf | |||||
bind_dn = %(service_bind_dn)s | |||||
bind_pw = %(service_bind_pw)s | |||||
# This finds the mail enabled distribution group LDAP entry | |||||
query_filter = (&(|(mail=%%s)(alias=%%s))(objectClass=kolabgroupofuniquenames)(objectclass=groupofuniquenames)(!(objectclass=groupofurls))) | |||||
# From this type of group, get all uniqueMember DNs | |||||
special_result_attribute = uniqueMember | |||||
# Only from those DNs, get the mail | |||||
result_attribute = | |||||
leaf_result_attribute = mail | |||||
""" % { | |||||
"server_host": server_host, | |||||
"group_base_dn": conf.get('ldap', 'group_base_dn'), | |||||
"service_bind_dn": conf.get('ldap', 'service_bind_dn'), | |||||
"service_bind_pw": conf.get('ldap', 'service_bind_pw'), | |||||
}, | |||||
"/etc/postfix/ldap/mailenabled_dynamic_distgroups.cf": """ | |||||
server_host = %(server_host)s | |||||
server_port = 389 | |||||
version = 3 | |||||
search_base = %(group_base_dn)s | |||||
scope = sub | |||||
domain = ldap:/etc/postfix/ldap/mydestination.cf | |||||
bind_dn = %(service_bind_dn)s | |||||
bind_pw = %(service_bind_pw)s | |||||
# This finds the mail enabled dynamic distribution group LDAP entry | |||||
query_filter = (&(|(mail=%%s)(alias=%%s))(objectClass=kolabgroupofuniquenames)(objectClass=groupOfURLs)) | |||||
# From this type of group, get all memberURL searches/references | |||||
special_result_attribute = memberURL | |||||
# Only from those DNs, get the mail | |||||
result_attribute = | |||||
leaf_result_attribute = mail | |||||
""" % { | |||||
"server_host": server_host, | |||||
"group_base_dn": conf.get('ldap', 'group_base_dn'), | |||||
"service_bind_dn": conf.get('ldap', 'service_bind_dn'), | |||||
"service_bind_pw": conf.get('ldap', 'service_bind_pw'), | |||||
}, | |||||
"/etc/postfix/ldap/transport_maps.cf": """ | |||||
server_host = %(server_host)s | |||||
server_port = 389 | |||||
version = 3 | |||||
search_base = %(base_dn)s | |||||
scope = sub | |||||
domain = ldap:/etc/postfix/ldap/mydestination.cf | |||||
bind_dn = %(service_bind_dn)s | |||||
bind_pw = %(service_bind_pw)s | |||||
query_filter = (&(|(mailAlternateAddress=%%s)(alias=%%s)(mail=%%s))(objectclass=kolabinetorgperson)) | |||||
result_attribute = mail | |||||
result_format = lmtp:unix:/var/lib/imap/socket/lmtp | |||||
""" % { | |||||
"base_dn": conf.get('ldap', 'base_dn'), | |||||
"server_host": server_host, | |||||
"service_bind_dn": conf.get('ldap', 'service_bind_dn'), | |||||
"service_bind_pw": conf.get('ldap', 'service_bind_pw'), | |||||
}, | |||||
"/etc/postfix/ldap/virtual_alias_maps.cf": """ | |||||
server_host = %(server_host)s | |||||
server_port = 389 | |||||
version = 3 | |||||
search_base = %(base_dn)s | |||||
scope = sub | |||||
domain = ldap:/etc/postfix/ldap/mydestination.cf | |||||
bind_dn = %(service_bind_dn)s | |||||
bind_pw = %(service_bind_pw)s | |||||
query_filter = (&(|(mail=%%s)(alias=%%s))(objectclass=kolabinetorgperson)) | |||||
result_attribute = mail | |||||
""" % { | |||||
"base_dn": conf.get('ldap', 'base_dn'), | |||||
"server_host": server_host, | |||||
"service_bind_dn": conf.get('ldap', 'service_bind_dn'), | |||||
"service_bind_pw": conf.get('ldap', 'service_bind_pw'), | |||||
}, | |||||
"/etc/postfix/ldap/virtual_alias_maps_mailforwarding.cf": """ | |||||
server_host = %(server_host)s | |||||
server_port = 389 | |||||
version = 3 | |||||
search_base = %(base_dn)s | |||||
scope = sub | |||||
domain = ldap:/etc/postfix/ldap/mydestination.cf | |||||
bind_dn = %(service_bind_dn)s | |||||
bind_pw = %(service_bind_pw)s | |||||
query_filter = (&(|(mail=%%s)(alias=%%s))(objectclass=mailrecipient)(objectclass=inetorgperson)(mailforwardingaddress=*)) | |||||
result_attribute = mailForwardingAddress | |||||
""" % { | |||||
"base_dn": conf.get('ldap', 'base_dn'), | |||||
"server_host": server_host, | |||||
"service_bind_dn": conf.get('ldap', 'service_bind_dn'), | |||||
"service_bind_pw": conf.get('ldap', 'service_bind_pw'), | |||||
}, | |||||
"/etc/postfix/ldap/virtual_alias_maps_sharedfolders.cf": """ | |||||
server_host = %(server_host)s | |||||
server_port = 389 | |||||
version = 3 | |||||
search_base = %(base_dn)s | |||||
scope = sub | |||||
domain = ldap:/etc/postfix/ldap/mydestination.cf | |||||
bind_dn = %(service_bind_dn)s | |||||
bind_pw = %(service_bind_pw)s | |||||
query_filter = (&(|(mail=%%s)(alias=%%s))(objectclass=kolabsharedfolder)(kolabFolderType=mail)) | |||||
result_attribute = kolabtargetfolder | |||||
result_format = "shared+%%s" | |||||
""" % { | |||||
"base_dn": conf.get('ldap', 'base_dn'), | |||||
"server_host": server_host, | |||||
"service_bind_dn": conf.get('ldap', 'service_bind_dn'), | |||||
"service_bind_pw": conf.get('ldap', 'service_bind_pw'), | |||||
}, | |||||
} | } | ||||
if not os.path.isdir('/etc/postfix/ldap'): | postfix_lookup_tables = ( | ||||
os.mkdir('/etc/postfix/ldap/', 0770) | 'local_recipient_maps.cf', | ||||
'mydestination.cf', | |||||
'mailenabled_distgroups.cf', | |||||
'mailenabled_dynamic_distgroups.cf', | |||||
'transport_maps.cf', | |||||
'virtual_alias_maps.cf', | |||||
'virtual_alias_maps_mailforwarding.cf', | |||||
'virtual_alias_maps_sharedfolders.cf' | |||||
) | |||||
for filename in files.keys(): | for lookup_table in postfix_lookup_tables: | ||||
fp = open(filename, 'w') | try: | ||||
fp.write(files[filename]) | with open(utils.find_template("%s.j2" % lookup_table)) as _template_def: | ||||
fp.close() | compiled_template = Template(_template_def.read()) | ||||
with open(os.path.join(postfix_ldap_dir, lookup_table), 'w') as _template_dest: | |||||
_template_dest.write(compiled_template.render(**config_ldap_dict)) | |||||
log.debug(_("Saved Postfix LDAP lookup table: %s") % _template_dest.name, level=8) | |||||
except Exception, errmsg: | |||||
log.error(_("Failed to save Postfix LDAP lookup table: %s") % errmsg) | |||||
continue | |||||
fp = open('/etc/postfix/transport', 'a') | fp = open('/etc/postfix/transport', 'a') | ||||
fp.write("\n# Shared Folder Delivery for %(domain)s:\nshared@%(domain)s\t\tlmtp:unix:/var/lib/imap/socket/lmtp\n" % {'domain': conf.get('kolab', 'primary_domain')}) | fp.write("\n# Shared Folder Delivery for %(domain)s:\nshared@%(domain)s\t\tlmtp:unix:/var/lib/imap/socket/lmtp\n" % {'domain': conf.get('kolab', 'primary_domain')}) | ||||
fp.close() | fp.close() | ||||
subprocess.call(["postmap", "/etc/postfix/transport"]) | subprocess.call(["postmap", "/etc/postfix/transport"]) | ||||
postfix_main_settings = { | postfix_main_settings = { | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | def execute(*args, **kw): | ||||
postfix_master_settings = { | postfix_master_settings = { | ||||
} | } | ||||
if os.path.exists('/usr/lib/postfix/kolab_smtp_access_policy'): | if os.path.exists('/usr/lib/postfix/kolab_smtp_access_policy'): | ||||
postfix_master_settings['kolab_sap_executable_path'] = '/usr/lib/postfix/kolab_smtp_access_policy' | postfix_master_settings['kolab_sap_executable_path'] = '/usr/lib/postfix/kolab_smtp_access_policy' | ||||
else: | else: | ||||
postfix_master_settings['kolab_sap_executable_path'] = '/usr/libexec/postfix/kolab_smtp_access_policy' | postfix_master_settings['kolab_sap_executable_path'] = '/usr/libexec/postfix/kolab_smtp_access_policy' | ||||
template_file = None | try: | ||||
with open(utils.find_template('master.cf.j2')) as postfix_master_template: | |||||
if os.path.isfile('/etc/kolab/templates/master.cf.tpl'): | compiled_template = Template(postfix_master_template.read()) | ||||
template_file = '/etc/kolab/templates/master.cf.tpl' | |||||
elif os.path.isfile('/usr/share/kolab/templates/master.cf.tpl'): | |||||
template_file = '/usr/share/kolab/templates/master.cf.tpl' | |||||
elif os.path.isfile(os.path.abspath(os.path.join(__file__, '..', '..', '..', 'share', 'templates', 'master.cf.tpl'))): | |||||
template_file = os.path.abspath(os.path.join(__file__, '..', '..', '..', 'share', 'templates', 'master.cf.tpl')) | |||||
if not template_file == None: | |||||
fp = open(template_file, 'r') | |||||
template_definition = fp.read() | |||||
fp.close() | |||||
t = Template(template_definition, searchList=[postfix_master_settings]) | with open('/etc/postfix/master.cf', 'w') as postfix_master_file: | ||||
fp = open('/etc/postfix/master.cf', 'w') | postfix_master_file.write(compiled_template.render(**postfix_master_settings)) | ||||
fp.write(t.__str__()) | |||||
fp.close() | |||||
else: | log.debug(_("Saved Postfix /etc/postfix/master.cf file"), level=8) | ||||
log.error(_("Could not write out Postfix configuration file /etc/postfix/master.cf")) | except Exception, errmsg: | ||||
log.error( | |||||
_("Could not write out Postfix configuration file /etc/postfix/master.cf: %s") % | |||||
errmsg | |||||
) | |||||
return | return | ||||
if os.path.isdir('/etc/postfix/sasl/'): | if os.path.isdir('/etc/postfix/sasl/'): | ||||
fp = open('/etc/postfix/sasl/smtpd.conf', 'w') | fp = open('/etc/postfix/sasl/smtpd.conf', 'w') | ||||
fp.write("pwcheck_method: saslauthd\n") | fp.write("pwcheck_method: saslauthd\n") | ||||
fp.write("mech_list: plain login\n") | fp.write("mech_list: plain login\n") | ||||
fp.close() | fp.close() | ||||
# Get raw config values for kolab section. Don't need to interpolate | |||||
config_kolab_dict = { | |||||
'kolab': dict(conf.cfg_parser.items('kolab', raw=True)) | |||||
} | |||||
# Merge ldap and kolab sections into one dictionalry | |||||
amavisd_settings = { | amavisd_settings = { | ||||
'ldap_server': '%(server_host)s', | |||||
'ldap_bind_dn': conf.get('ldap', 'service_bind_dn'), | |||||
'ldap_bind_pw': conf.get('ldap', 'service_bind_pw'), | |||||
'primary_domain': conf.get('kolab', 'primary_domain'), | |||||
'ldap_filter': "(|(mail=%m)(alias=%m))", | |||||
'ldap_base_dn': conf.get('ldap', 'base_dn'), | |||||
'clamdsock': '/var/spool/amavisd/clamd.sock', | 'clamdsock': '/var/spool/amavisd/clamd.sock', | ||||
'kolab': config_kolab_dict['kolab'], | |||||
'ldap': config_ldap_dict['ldap'] | |||||
} | } | ||||
template_file = None | |||||
# On RPM installations, Amavis configuration is contained within a single file. | # On RPM installations, Amavis configuration is contained within a single file. | ||||
amavisconf_paths = [ | amavisconf_paths = [ | ||||
"/etc/amavisd.conf", | "/etc/amavisd.conf", | ||||
"/etc/amavis/amavisd.conf", | "/etc/amavis/amavisd.conf", | ||||
"/etc/amavisd/amavisd.conf" | "/etc/amavisd/amavisd.conf" | ||||
] | ] | ||||
amavis_conf = '' | amavis_conf = '' | ||||
for amavisconf_path in amavisconf_paths: | for amavisconf_path in amavisconf_paths: | ||||
if os.path.isfile(amavisconf_path): | if os.path.isfile(amavisconf_path): | ||||
amavis_conf = amavisconf_path | amavis_conf = amavisconf_path | ||||
break | |||||
if os.path.isfile(amavis_conf): | |||||
if os.path.isfile('/etc/kolab/templates/amavisd.conf.tpl'): | |||||
template_file = '/etc/kolab/templates/amavisd.conf.tpl' | |||||
elif os.path.isfile('/usr/share/kolab/templates/amavisd.conf.tpl'): | |||||
template_file = '/usr/share/kolab/templates/amavisd.conf.tpl' | |||||
elif os.path.isfile(os.path.abspath(os.path.join(__file__, '..', '..', '..', 'share', 'templates', 'amavisd.conf.tpl'))): | |||||
template_file = os.path.abspath(os.path.join(__file__, '..', '..', '..', 'share', 'templates', 'amavisd.conf.tpl')) | |||||
if not template_file == None: | |||||
fp = open(template_file, 'r') | |||||
template_definition = fp.read() | |||||
fp.close() | |||||
if os.path.isfile('/etc/clamd.d/amavisd.conf'): | if os.path.isfile('/etc/clamd.d/amavisd.conf'): | ||||
amavisdconf_content = file('/etc/clamd.d/amavisd.conf') | amavisdconf_content = file('/etc/clamd.d/amavisd.conf') | ||||
for line in amavisdconf_content: | for line in amavisdconf_content: | ||||
if line.startswith('LocalSocket'): | if line.startswith('LocalSocket'): | ||||
amavisd_settings['clamdsock'] = line[len('LocalSocket '):].strip() | amavisd_settings['clamdsock'] = line[len('LocalSocket '):].strip() | ||||
break | |||||
t = Template(template_definition, searchList=[amavisd_settings]) | if os.path.isfile(amavis_conf): | ||||
try: | |||||
fp = None | with open(utils.find_template("%s.j2" % os.path.basename(amavis_conf))) as amavis_conf_template: | ||||
fp = open(amavis_conf, 'w') | compiled_template = Template(amavis_conf_template.read()) | ||||
if not fp == None: | with open(amavis_conf, 'w') as amavis_conf_file: | ||||
fp.write(t.__str__()) | amavis_conf_file.write(compiled_template.render(**amavisd_settings)) | ||||
fp.close() | |||||
else: | log.debug(_("Saved Amavisd configuration file %s") % (amavis_conf), level=8) | ||||
log.error(_("Could not write out Amavis configuration file amavisd.conf")) | except Exception, errmsg: | ||||
log.error(_("Could not write out Amavisd configuration file %s: %s") % (amavis_conf, errmsg)) | |||||
return | return | ||||
# On APT installations, /etc/amavis/conf.d/ is a directory with many more files. | # On APT installations, /etc/amavis/conf.d/ is a directory with many more files. | ||||
# | # | ||||
# Somebody could work on enhancement request #1080 to configure LDAP lookups, | # Somebody could work on enhancement request #1080 to configure LDAP lookups, | ||||
# while really it isn't required. | # while really it isn't required. | ||||
else: | else: | ||||
log.info(_("Not writing out any configuration for Amavis.")) | log.info(_("Not writing out any configuration for Amavis.")) | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | elif os.path.isfile('/usr/share/kolab/templates/freshclam.conf.tpl'): | ||||
) | ) | ||||
else: | else: | ||||
log.error(_("Could not find a ClamAV update configuration file")) | log.error(_("Could not find a ClamAV update configuration file")) | ||||
if os.path.isfile('/etc/freshclam.conf'): | if os.path.isfile('/etc/freshclam.conf'): | ||||
subprocess.call([ | subprocess.call([ | ||||
'/usr/bin/freshclam', | '/usr/bin/freshclam', | ||||
'--quiet', | '--quiet', | ||||
'--datadir="/var/lib/clamav"' | '--datadir=/var/lib/clamav' | ||||
]) | ]) | ||||
amavisservice = 'amavisd.service' | amavisservice = 'amavisd.service' | ||||
clamavservice = 'clamd@amavisd.service' | clamavservice = 'clamd@amavisd.service' | ||||
if os.path.isfile('/usr/lib/systemd/system/amavis.service'): | if os.path.isfile('/usr/lib/systemd/system/amavis.service'): | ||||
amavisservice = 'amavis.service' | amavisservice = 'amavis.service' | ||||
if os.path.isfile('/lib/systemd/system/amavis.service'): | if os.path.isfile('/lib/systemd/system/amavis.service'): | ||||
amavisservice = 'amavis.service' | amavisservice = 'amavis.service' | ||||
if os.path.isfile('/etc/init.d/amavis'): | |||||
amavisservice = 'amavis.service' | |||||
if os.path.isfile('/usr/lib/systemd/system/clamd.service'): | if os.path.isfile('/usr/lib/systemd/system/clamd.service'): | ||||
clamavservice = 'clamd.service' | clamavservice = 'clamd.service' | ||||
if os.path.isfile('/lib/systemd/system/clamd.service'): | if os.path.isfile('/lib/systemd/system/clamd.service'): | ||||
clamavservice = 'clamd.service' | clamavservice = 'clamd.service' | ||||
if os.path.isfile('/lib/systemd/system/clamav-daemon.service'): | if os.path.isfile('/lib/systemd/system/clamav-daemon.service'): | ||||
clamavservice = 'clamav-daemon.service' | clamavservice = 'clamav-daemon.service' | ||||
if os.path.isfile('/bin/systemctl'): | if os.path.isfile('/bin/systemctl'): | ||||
subprocess.call(['systemctl', 'restart', 'postfix.service']) | # Reload systemctl daemon in case any service file changed | ||||
subprocess.call(['systemctl', 'restart', amavisservice]) | subprocess.call(['systemctl', 'daemon-reload']) | ||||
subprocess.call(['systemctl', 'restart', clamavservice]) | for _srv in ('postfix.service', amavisservice, clamavservice, 'wallace.service'): | ||||
subprocess.call(['systemctl', 'restart', 'wallace.service']) | log.debug(_("Restarting %s systemd service ... ") % _srv, level=8) | ||||
subprocess.call(['systemctl', 'restart', _srv]) | |||||
subprocess.call(['systemctl', 'enable', _srv]) | |||||
elif os.path.isfile('/sbin/service'): | elif os.path.isfile('/sbin/service'): | ||||
subprocess.call(['service', 'postfix', 'restart']) | for _srv in ('postfix', 'amavisd', 'clamd.amavisd', 'wallace'): | ||||
subprocess.call(['service', 'amavisd', 'restart']) | log.debug(_("Restarting %s service ... ") % _srv, level=8) | ||||
subprocess.call(['service', 'clamd.amavisd', 'restart']) | subprocess.call(['service', _srv, 'restart']) | ||||
subprocess.call(['service', 'wallace', 'restart']) | subprocess.call(['chkconfig', _srv, 'on']) | ||||
elif os.path.isfile('/usr/sbin/service'): | elif os.path.isfile('/usr/sbin/service'): | ||||
subprocess.call(['/usr/sbin/service','postfix','restart']) | for _srv in ('postfix', 'amavis', 'clamav-daemon', 'wallace'): | ||||
subprocess.call(['/usr/sbin/service','amavis','restart']) | log.debug(_("Restarting %s service ... ") % _srv, level=8) | ||||
subprocess.call(['/usr/sbin/service','clamav-daemon','restart']) | subprocess.call(['/usr/sbin/service', _srv, 'restart']) | ||||
subprocess.call(['/usr/sbin/service','wallace','restart']) | |||||
else: | else: | ||||
log.error(_("Could not start the postfix, clamav and amavisd services services.")) | log.error(_("Could not start the postfix, clamav and amavisd services services.")) | ||||
if os.path.isfile('/bin/systemctl'): | if os.path.isfile('/bin/systemctl'): | ||||
subprocess.call(['systemctl', 'enable', 'postfix.service']) | for _srv in ('postfix.service', amavisservice, clamavservice, 'wallace.service'): | ||||
subprocess.call(['systemctl', 'enable', amavisservice]) | log.debug(_("Enabling %s systemd service to start on boot") % _srv, level=8) | ||||
subprocess.call(['systemctl', 'enable', clamavservice]) | subprocess.call(['systemctl', 'enable', _srv]) | ||||
subprocess.call(['systemctl', 'enable', 'wallace.service']) | |||||
elif os.path.isfile('/sbin/chkconfig'): | elif os.path.isfile('/sbin/chkconfig'): | ||||
subprocess.call(['chkconfig', 'postfix', 'on']) | for _srv in ('postfix', 'amavisd', 'clamd.amavisd', 'wallace'): | ||||
subprocess.call(['chkconfig', 'amavisd', 'on']) | log.debug(_("Enabling %s service to start on boot") % _srv, level=8) | ||||
subprocess.call(['chkconfig', 'clamd.amavisd', 'on']) | subprocess.call(['chkconfig', _srv, 'on']) | ||||
subprocess.call(['chkconfig', 'wallace', 'on']) | |||||
elif os.path.isfile('/usr/sbin/update-rc.d'): | elif os.path.isfile('/usr/sbin/update-rc.d'): | ||||
subprocess.call(['/usr/sbin/update-rc.d', 'postfix', 'defaults']) | for _srv in ('postfix', 'amavis', 'clamav-daemon', 'wallace'): | ||||
subprocess.call(['/usr/sbin/update-rc.d', 'amavis', 'defaults']) | log.debug(_("Enabling %s service to start on boot ") % _srv, level=8) | ||||
subprocess.call(['/usr/sbin/update-rc.d', 'clamav-daemon', 'defaults']) | subprocess.call(['/usr/sbin/update-rc.d', _srv, 'defaults']) | ||||
subprocess.call(['/usr/sbin/update-rc.d', 'wallace', 'defaults']) | |||||
else: | else: | ||||
log.error(_("Could not configure to start on boot, the " + \ | log.error(_("Could not configure to start on boot, the " + \ | ||||
"postfix, clamav and amavisd services.")) | "postfix, clamav and amavisd services.")) |