Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 910809 Details for
Bug 1106457
Doesn't implement NOTIFY_SOCKET ERRNO
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
fake daemon for systemd
systemd.py (text/x-python), 3.47 KB, created by
Miguel Angel Ajo
on 2014-06-20 15:46:07 UTC
(
hide
)
Description:
fake daemon for systemd
Filename:
MIME Type:
Creator:
Miguel Angel Ajo
Created:
2014-06-20 15:46:07 UTC
Size:
3.47 KB
patch
obsolete
>#!/bin/python ># Copyright 2012-2014 Red Hat, Inc. ># ># Licensed under the Apache License, Version 2.0 (the "License"); you may ># not use this file except in compliance with the License. You may obtain ># a copy of the License at ># ># http://www.apache.org/licenses/LICENSE-2.0 ># ># Unless required by applicable law or agreed to in writing, software ># distributed under the License is distributed on an "AS IS" BASIS, WITHOUT ># WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the ># License for the specific language governing permissions and limitations ># under the License. > >""" >Helper module for systemd service readiness notification. >""" > >import os >import socket >import sys >import time > >def _abstractify(socket_name): > if socket_name.startswith('@'): > # abstract namespace socket > socket_name = '\0%s' % socket_name[1:] > return socket_name > > >def _sd_notify(msg): > print msg > notify_socket = os.getenv('NOTIFY_SOCKET') > notified = False > if notify_socket: > sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) > try: > sock.connect(_abstractify(notify_socket)) > sock.sendall(msg) > notified = True > except EnvironmentError: > LOG.debug("Systemd notification failed", exc_info=True) > finally: > sock.close() > return notified > >def notify_message(**kwargs): > """Send notification message to Systemd with the data > specified by kwargs > """ > lines = ["%s=%s" % (param,str(value)) > for param, value in kwargs.iteritems()] > > _sd_notify("\n".join(lines)) > >def notify(): > """Send notification to Systemd that service is ready. > For details see > http://www.freedesktop.org/software/systemd/man/sd_notify.html > """ > notify_message(READY=1) > > >_ready_already_notified = False > >def notify_once(): > """Send notification once to Systemd that service is ready. > Systemd sets NOTIFY_SOCKET environment variable with the name of the > socket listening for notifications from services. > This method removes the NOTIFY_SOCKET environment variable to ensure > notification is sent only once. > """ > if not _ready_already_notified: # TODO(majopela) mutex here / race condition > _ready_already_notified = True > notify_message(READY=1) > > >def onready(notify_socket, timeout): > """Wait for systemd style notification on the socket. > > :param notify_socket: local socket address > :type notify_socket: string > :param timeout: socket timeout > :type timeout: float > :returns: 0 service ready > 1 service not ready > 2 timeout occured > """ > sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) > sock.settimeout(timeout) > sock.bind(_abstractify(notify_socket)) > try: > msg = sock.recv(512) > except socket.timeout: > return 2 > finally: > sock.close() > if 'READY=1' in msg: > return 0 > else: > return 1 > > >if __name__ == '__main__': > # simple CLI for testing > if len(sys.argv) == 1: > notify() > for i in range(1,250): > notify_message(STATUS="I'm running, with status %d" % i, > ERRNO=i) > time.sleep(1) > elif len(sys.argv) >= 2: > timeout = float(sys.argv[1]) > notify_socket = os.getenv('NOTIFY_SOCKET') > if notify_socket: > retval = onready(notify_socket, timeout) > sys.exit(retval)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 1106457
:
910807
| 910809 |
910810
|
913408
|
914407