Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuring ha_propagate default per-service #13607

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/middlewared/middlewared/plugins/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ def result(task):
async def service_extend(self, svc, ctx):
return svc | ctx.get(svc['service'], {'state': 'UNKNOWN', 'pids': []})

async def __normalize_service_options(self, svc_obj, options):
if options.get('ha_propagate') != None:
return options

return options | {'ha_propagate': svc_obj.default_ha_propagate}

@filterable
async def query(self, filters, options):
"""
Expand Down Expand Up @@ -149,7 +155,7 @@ async def do_update(self, app, id_or_name, data):
Str('service'),
Dict(
'service-control',
Bool('ha_propagate', default=True),
Bool('ha_propagate'),
Bool('silent', default=True),
register=True,
),
Expand All @@ -166,6 +172,8 @@ async def start(self, app, service, options):
"""
service_object = await self.middleware.call('service.object', service)

options = await self.__normalize_service_options(service_object, options)

if not app_has_write_privilege_for_service(app, service):
raise CallError(f'{service}: authenticated session lacks privilege to start service', errno.EPERM)

Expand Down Expand Up @@ -249,6 +257,8 @@ async def stop(self, app, service, options):
"""
service_object = await self.middleware.call('service.object', service)

options = await self.__normalize_service_options(service_object, options)

if not app_has_write_privilege_for_service(app, service):
raise CallError(f'{service}: authenticated session lacks privilege to stop service')

Expand Down Expand Up @@ -285,6 +295,8 @@ async def restart(self, app, service, options):
"""
service_object = await self.middleware.call('service.object', service)

options = await self.__normalize_service_options(service_object, options)

if not app_has_write_privilege_for_service(app, service):
raise CallError(f'{service}: authenticated session lacks privilege to restart service', errno.EPERM)

Expand Down Expand Up @@ -347,6 +359,8 @@ async def reload(self, app, service, options):
"""
service_object = await self.middleware.call('service.object', service)

options = await self.__normalize_service_options(service_object, options)

if not app_has_write_privilege_for_service(app, service):
raise CallError(f'{service}: authenticated session lacks privilege to restart service', errno.EPERM)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class ServiceInterface:
restartable = False # Implements `restart` method instead of `stop` + `start`
reloadable = False # Implements `reload` method
deprecated = False # Alert if service is running
default_ha_propagate = True # If HA propagate service changes to other node

def __init__(self, middleware):
self.middleware = middleware
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class CIFSService(SimpleService):
name = "cifs"
reloadable = True
default_ha_propagate = False

etc = ["smb"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class IdmapService(SimpleService):
name = "idmap"
reloadable = True
restartable = True
default_ha_propagate = False

systemd_unit = "winbind"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
class MDNSService(SimpleService):
name = "mdns"
reloadable = True
default_ha_propagate = False

etc = ["mdns"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
class NFSService(SimpleService):
name = "nfs"
reloadable = True
default_ha_propagate = False

etc = ["nfsd"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@

class NSSPamLdapdService(SimpleService):
name = "nslcd"
default_ha_propagate = False

systemd_unit = "nslcd"
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ async def reload(self):

class DSCacheService(PseudoServiceBase):
name = "dscache"
default_ha_propagate = False

async def start(self):
await self.middleware.call('dscache.refresh')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

class WSDService(SimpleService):
name = "wsdd"
default_ha_propagate = False

etc = ["wsd"]

Expand Down
Loading