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

systemd notify: Fail to understand how to properly launch this service through systemd #42

Closed
j1nx opened this issue May 31, 2023 · 10 comments · Fixed by #43
Closed

systemd notify: Fail to understand how to properly launch this service through systemd #42

j1nx opened this issue May 31, 2023 · 10 comments · Fixed by #43

Comments

@j1nx
Copy link
Member

j1nx commented May 31, 2023

I fail to understand how to launch this with systemd as type=notify

Can someone point me to the right way? Or better explain me what, where, how, etc.

@j1nx
Copy link
Member Author

j1nx commented May 31, 2023

To elaborate, this is the systemd wrapper of the "old" voice service;

import sdnotify
from mycroft.client.speech.__main__ import main

n = sdnotify.SystemdNotifier()

def notify_ready():
    n.notify('READY=1')
    print('Startup of Mycroft Voice service complete')

def notify_stopping():
    n.notify('STOPPING=1')
    print('Stopping the Mycroft Voice service')

main(ready_hook=notify_ready, stopping_hook=notify_stopping)

So to convert this into;

import sdnotify
from ovos_dinkum_listener.ovos_dinkum_listener.__main__ import main

n = sdnotify.SystemdNotifier()

def notify_ready():
    n.notify('READY=1')
    print('Startup of Mycroft Voice service complete')

def notify_stopping():
    n.notify('STOPPING=1')
    print('Stopping the Mycroft Voice service')

main(ready_hook=notify_ready, stopping_hook=notify_stopping)

However I do not see which hooks need to be changed to what?

@emphasize
Copy link
Member

emphasize commented May 31, 2023

from ovos_dinkum_listener.ovos_dinkum_listener.__main__ import main

main()

sdnotify in dinkum listener will report to the service
yet i'm not clear atm if all notification types are satisfied (in dinkum)

@j1nx
Copy link
Member Author

j1nx commented May 31, 2023

import sdnotify
from ovos_dinkum_listener.ovos_dinkum_listener.__main__ import main

main()

sdnotify in dinkum listener will report to the service yet i'm not clear atm if all notification types are satisfied (in dinkum)

We need to let systemd know it was started, which is done with sending READY=1 with sdnotify package. I don't see it imported anywhere within Dinkum listener so we still need to do it with the wrapper.

Otherwise systemd keeps restarting the service when the timeout is reached. What you stated is just a type=simple not type=notify

@j1nx
Copy link
Member Author

j1nx commented May 31, 2023

Are you sure the voice service does not get restarted after the timeout of 1 minute?

If this work, I am even more confused. Then somewhere within the dinkum code, it talks to systemd without importing any sdnotify package. ???

@emphasize
Copy link
Member

emphasize commented May 31, 2023

@jinx you are right, i was somewhat hallucinating and under the impression those were there.

we can work with the default callback handler here and notify from there

n = sdnotify.SystemdNotifier()

def on_ready():
    n.notify('READY=1')
    LOG.info('DinkumVoiceService is ready.')

...

The mention in the dinkum code (watchdog) is a lambda function that is doing nothing

further check: ovos_utils.process_utils

@NeonDaniel
Copy link
Member

To elaborate, this is the systemd wrapper of the "old" voice service;

import sdnotify
from mycroft.client.speech.__main__ import main

n = sdnotify.SystemdNotifier()

def notify_ready():
    n.notify('READY=1')
    print('Startup of Mycroft Voice service complete')

def notify_stopping():
    n.notify('STOPPING=1')
    print('Stopping the Mycroft Voice service')

main(ready_hook=notify_ready, stopping_hook=notify_stopping)

So to convert this into;

import sdnotify
from ovos_dinkum_listener.ovos_dinkum_listener.__main__ import main

n = sdnotify.SystemdNotifier()

def notify_ready():
    n.notify('READY=1')
    print('Startup of Mycroft Voice service complete')

def notify_stopping():
    n.notify('STOPPING=1')
    print('Stopping the Mycroft Voice service')

main(ready_hook=notify_ready, stopping_hook=notify_stopping)

However I do not see which hooks need to be changed to what?

OH. I missed the signature change; ready_hook and stopping_hook aren't the kwargs here, they're on_ready and on_stopping.

@emphasize
Copy link
Member

emphasize commented May 31, 2023

@jinx you are right, i was somewhat hallucinating and under the impression those were there.

we can work with the default callback handler here and notify from there

n = sdnotify.SystemdNotifier()

def on_ready():
    n.notify('READY=1')
    LOG.info('DinkumVoiceService is ready.')

...

The mention in the dinkum code (watchdog) is a lambda function that is doing nothing

further check: ovos_utils.process_utils

to avoid confusion i was reffering to

ie the default on_ready

@builderjer
Copy link
Member

So what should the service file, and exec file be? Similar to listener?

@github-actions github-actions bot mentioned this issue Jun 5, 2023
@github-actions github-actions bot mentioned this issue Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants