{ "info": { "author": "Todd Francis DeLuca", "author_email": "todddeluca@yahoo.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7" ], "description": "## Introduction\n\nMy first introduction to running a command as a daemon looked like this:\n\n nohup mycommand --myoption myarg >/dev/null 2>/dev/null &\n\nWhile this is a good for doing some development work, a proper daemon requires\nquite a number of other things to happen. The wikipedia page\nhttp://en.wikipedia.org/wiki/Daemon\\_(computing) says the following needs to\nhappen:\n\n- Dissociating from the controlling tty\n- Becoming a session leader\n- Becoming a process group leader\n- Executing as a background task by forking and exiting (once or twice). This\n is required sometimes for the process to become a session leader. It also\n allows the parent process to continue its normal execution.\n- Setting the root directory (\"/\") as the current working directory so that the\n process does not keep any directory in use that may be on a mounted file\n system (allowing it to be unmounted).\n- Changing the umask to 0 to allow open(), creat(), et al. operating system\n calls to provide their own permission masks and not to depend on the umask of\n the caller\n- Closing all inherited files at the time of execution that are left open by\n the parent process, including file descriptors 0, 1 and 2 (stdin, stdout,\n stderr). Required files will be opened later.\n- Using a logfile, the console, or /dev/null as stdin, stdout, and stderr\n\nAdditionally, when running a process under monit or initd, it is typical for\nthe process id of the daemon to be stored in a file, so the daemon can be\nmonitored and killed easily.\n\nFinally, it is common to use `start`, `stop`, `restart`, and\n`status` commands to control the daemon.\n\nDaemoncmd takes care of creating a daemon the right way, putting its pid in\na file, and interacting with the daemon via `start`, `stop`, etc. commands.\nUsing it is as simple as:\n\n /path/to/daemoncmd start --pidfile /tmp/mydaemon.pid /path/to/mycommand\n\nSee the Usage section for more details.\n\nFor more information on daemons and daemons in python, see:\n\n- http://pypi.python.org/pypi/python-daemon\n- http://www.python.org/dev/peps/pep-3143/\n- http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66012\n- http://en.wikipedia.org/wiki/Daemon\\_(computing)\n\n\n## Alternatives\n\nHere are some projects that are similar in scope to daemoncmd:\n\n- http://pypi.python.org/pypi/zdaemon/2.0.4, and see\n http://ridingpython.blogspot.cz/2011/08/turning-your-python-script-into-linux.html\n for a description.\n- https://github.com/indexzero/forever\n\nWhile daemoncmd is a great way to start running a daemon, there are many\nprograms designed to run and monitor processes in a way that is more robust and\nfull-featured than simply starting your own daemon. Here is a list of some of\nthem (see http://news.ycombinator.com/item?id=1368855 for a discussion):\n\n- launchd http://launchd.macosforge.org/\n- upstart http://upstart.ubuntu.com/\n- monit http://mmonit.com/monit/\n- supervisord http://supervisord.org/\n- daemontools http://cr.yp.to/daemontools.html\n- daemonize http://bmc.github.com/daemonize/\n- runit http://smarden.sunsite.dk/runit/\n- perp http://b0llix.net/perp/\n\nFor production systems, I recommend using a tool like one of these. I have\nused supervisord and monit before. Some of these tools work with daemons, like\nmonit, in which case daemoncmd could come in handy. Other tools, like\nsupervisord, can supervise your process in such a way that you do not need to\ndaemonize it.\n\n\n## Contribute\n\nIf this project does not do what you want, please open an issue or a pull\nrequest on github, https://github.com/todddeluca/daemoncmd.\n\n\n## Requirements\n\n- Probably Python 2.7 (since that is the only version it has been tested with.)\n\n\n## Installation\n\n### Install from pypi.python.org\n\nDownload and install python-vagrant:\n\n pip install daemoncmd\n\n### Install from github.com\n\nClone and install daemoncmd:\n\n git clone git@github.com:todddeluca/daemoncmd.git\n cd daemoncmd\n python setup.py install\n\n\n## Usage\n\nThis module has two separate uses cases: \n \n- running a command as a daemon process\n- forking the current python process as a daemon.\n\nDaemonizing a command allows one to start, stop, and restart a non-daemon\ncommand as a daemon process. This requires specifying a pid file which is used\nto interact with the process.\n\nUsage examples:\n\n daemoncmd start --pidfile /tmp/daemon.pid \\\n --stdout /tmp/daemon.log --stderr /tmp/daemon.log sleep 100\n daemoncmd restart --pidfile /tmp/daemon.pid \\\n --stdout /tmp/daemon.log --stderr /tmp/daemon.log sleep 100\n daemoncmd status --pidfile /tmp/daemon.pid\n daemoncmd stop --pidfile /tmp/daemon.pid\n\nAnother use case is forking the current process into a daemon. According\nto pep 3143, forking as a daemon might be done by the standard library some\nday.\n\nUsage example:\n\n import daemoncmd\n import mytask\n\n daemoncmd.daemonize()\n mytask.doit()\n\nOr from the command line:\n\n python -c 'import daemoncmd, mytask; daemoncmd.daemonize(); mytask.doit()'\n\nOther usage notes:\n\n- The command should not daemonize itself, since that is what this script does\n and it would make the pid in the pidfile incorrect.\n- The command should refer to the absolute path of the executable, since\n daemonization sets the current working directory (cwd) to '/'. More\n generally, do not assume what the cwd is.\n- If daemoncmd is run by monit, etc., PATH and other env vars might be\n restricted for security reasons.\n- daemoncmd does not try to run the daemon as a particular uid. That would\n be handled by a process manager like monit, launchd, init, god, etc.\n- When running under monit, etc., pass environment variables to the command\n like so:\n\n FOO=testing daemoncmd start --pidfile /tmp/daemon.pid \\\n --stdout /tmp/daemon.log printenv FOO", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/todddeluca/daemoncmd", "keywords": "daemon python cli init nohup commandline executable script pidfile", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "daemoncmd", "package_url": "https://pypi.org/project/daemoncmd/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/daemoncmd/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/todddeluca/daemoncmd" }, "release_url": "https://pypi.org/project/daemoncmd/0.2.0/", "requires_dist": null, "requires_python": null, "summary": "Turn any command line into a daemon with a pidfile and start, stop, restart, and status commands.", "version": "0.2.0" }, "last_serial": 788751, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "57ea0d260deddbff22dde7f3c624586a", "sha256": "5c7615539b6cd1494d5dfa585344a2fb1c34a78887dbe24ee17b99dedbfbf0b7" }, "downloads": -1, "filename": "daemoncmd-0.1.0.tar.gz", "has_sig": false, "md5_digest": "57ea0d260deddbff22dde7f3c624586a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7558, "upload_time": "2012-06-15T18:08:43", "url": "https://files.pythonhosted.org/packages/81/f7/6b9eeca7986ec5fede32dcdd110675644c4fa3628a9cc725a193bf1b677b/daemoncmd-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "8fbbf65651f026c93e155c5413cc3e2b", "sha256": "056a0cbd3904c26d4ef6ef24dd40cf7e40eedb3505bd5bde109bd3d83d0a9145" }, "downloads": -1, "filename": "daemoncmd-0.2.0.tar.gz", "has_sig": false, "md5_digest": "8fbbf65651f026c93e155c5413cc3e2b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8093, "upload_time": "2013-06-26T16:02:47", "url": "https://files.pythonhosted.org/packages/48/39/ef9d9781cd6ab5a88d59733653edf7ee6dfaf5466797c24af63d917a3304/daemoncmd-0.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8fbbf65651f026c93e155c5413cc3e2b", "sha256": "056a0cbd3904c26d4ef6ef24dd40cf7e40eedb3505bd5bde109bd3d83d0a9145" }, "downloads": -1, "filename": "daemoncmd-0.2.0.tar.gz", "has_sig": false, "md5_digest": "8fbbf65651f026c93e155c5413cc3e2b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8093, "upload_time": "2013-06-26T16:02:47", "url": "https://files.pythonhosted.org/packages/48/39/ef9d9781cd6ab5a88d59733653edf7ee6dfaf5466797c24af63d917a3304/daemoncmd-0.2.0.tar.gz" } ] }