Skip to content

Lightweight and no-nonsense POSIX daemon library for Python (2.x.x/3.x.x)

License

Notifications You must be signed in to change notification settings

boyombo/daemon-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#Daemon-Python (0.2) Lightweight and no-nonsense POSIX daemon library. Extensible, complete with process forking and PID management.

Inspired by Sander Marechal.

##License MIT/X11 - See LICENSE

##Getting Started

Installation

	# git clone https://github.com/stackd/daemon-py.git
	# cd seat-py/
	# python setup.py install

Note: Daemon-Python, as of version 0.2, has only been tested on Linux. The setup.py script will automatically detect if the underlying platform is compatible, as well as determine the appropriate version of Python.

  1. Instantiation

     import daemon
     class MyDaemon(daemon.Daemon):
     """Subclass Daemon-Python."""
     ...
     	def run(self):
     	"""Define what to daemonize by implementing the run() method."""
     	...
    
  2. Implementing control

    Finally, we want to be able to control our daemon.

     ...
     if __name__ == "__main__":
         daemon = MyDaemon('/tmp/mydaemon.pid') #Define a pidfile location (typically located in /tmp or /var/run)
         if len(sys.argv) == 2:
             if 'start' == sys.argv[1]:
                 daemon.start()
             elif 'stop' == sys.argv[1]:
                 daemon.stop()
             elif 'restart' == sys.argv[1]:
                 daemon.restart()
             elif 'status' == sys.argv[1]:
                 daemon.status()
             else:
                 sys.stdout.write("Unknown command\n")
                 sys.exit(2)
             sys.exit(0)
         else:
             sys.stdout.write("Usage: %s start|stop|restart|status\n" % sys.argv[0])
             sys.exit(2)
    

For a complete basic implementation, see src/test.py

About

Lightweight and no-nonsense POSIX daemon library for Python (2.x.x/3.x.x)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages