Skip to main content

cross platform service or daemon framework

Project description

WhatAmIThinking-Services

Cross-platform service library for building platform services that integrate with platform tooling and can be installed/started/stopped/uninstalled from the command line.

Table of Contents

Code Usage

You should subclass PlatformService and override the following methods:

  • run: put your core blocking logic for running your service here
    • call self.started() just before you start blocking in this method to signal to the platform that your service has started
    • call self.stopped() just before this returns to signal to the platform your service has stopped
  • stop: send signal to stop your service and wait for it to be stopped.
import time
import threading

from whatamithinking.services import PlatformService


class MyService(PlatformService):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._event = threading.Event()
        self._exited = threading.Event()

    def run(self):
        self.started()
        self._event.wait()
        self._exited.set()
        self.stopped()

    def stop(self):
        self._event.set()
        self._exited.wait()


if __name__ == '__main__':
    # this will handle commandline params and run your service
    MyService.execute()

CLI

A CLI is included in the service class execute method, so you can perform operations such as install, uninstall, etc. The following is an example showing the CLI.

Main

usage: My Service [-h] {install,uninstall,start,stop} ...

Description of my service

options:
  -h, --help            show this help message and exit

subcommand:
  {install,uninstall,start,stop}

Install Subcommand

usage: My Service install [-h] [--username USERNAME] [--password PASSWORD]

install the service on this machine

options:
  -h, --help           show this help message and exit
  --username USERNAME  domain\username of the account to run the service under
  --password PASSWORD  password of the account to run the service under

Uninstall Subcommand

usage: My Service uninstall [-h]

uninstall the service from the machine

options:
  -h, --help  show this help message and exit

Start Subcommand

usage: My Service start [-h]

start the service if it is installed or throw error if not

options:
  -h, --help  show this help message and exit

Stop Subcommand

usage: My Service stop [-h]

stop the service if it is installed or throw error if not

options:
  -h, --help  show this help message and exit

Platforms

Windows

NOTE: obscure bug was found when trying to run installer to update and event viewer was open at same time. servicemanager.pyd file becomes locked up. turns out event viewer does this. closing event viewer removes this lock. see: https://mail.python.org/pipermail/python-win32/2004-December/002736.html

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

whatamithinking_services-1.1.2.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

whatamithinking_services-1.1.2-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file whatamithinking_services-1.1.2.tar.gz.

File metadata

File hashes

Hashes for whatamithinking_services-1.1.2.tar.gz
Algorithm Hash digest
SHA256 6b61f57718436a575f08676aa53c4fc523f3529c7942677fe29e26a9cacd3eea
MD5 530d2cc550de95f1450382514b87c2d1
BLAKE2b-256 722a45587860fecdcf685dea8e10ff2a35ecb573fd029141a66322e536af1318

See more details on using hashes here.

File details

Details for the file whatamithinking_services-1.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for whatamithinking_services-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ffcc20f03bf318e9623ebfac0a63a4b4467dfa3fa9ad2fbefbf0e77c532d7c9b
MD5 19e11c49c308151a1470cf45431a3342
BLAKE2b-256 6818950d916d8f1e9927fd363fb22d18a13f89550eacd3bab6f9e5cc35638430

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page