Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: joejulian/beaver
base: a636c8fbf4
...
head fork: joejulian/beaver
compare: b8d46f9b01
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 2 contributors
Commits on Dec 20, 2012
Jose Diaz-Gonzalez Updated requirements for Python 2.6. Closes #77 1642823
Commits on Dec 22, 2012
@joejulian Add support for daemonizing b8d46f9
View
10 README.rst
@@ -37,6 +37,7 @@ optional arguments::
-c CONFIG, --configfile CONFIG
ini config file path
-d, --debug enable debug mode
+ -D, --daemon daemonize in the background
-f FILES [FILES ...], --files FILES [FILES ...]
space-separated filelist to watch, can include globs
(*.log). Overrides --path argument
@@ -129,6 +130,15 @@ Example 4: Sending logs from /var/log files to a redis list::
# From the commandline
beaver -c /etc/beaver.conf -t redis
+Example 4: Sending logs from /var/log files to a redis list as a background daemon::
+
+ # /etc/beaver.conf
+ [beaver]
+ redis_url: redis://localhost:6379/0
+
+ # From the commandline
+ beaver -c /etc/beaver.conf -t redis -D
+
Example 5: Use environment variables to send logs from /var/log files to a redis list::
# /etc/beaver.conf
View
82 bin/beaver
@@ -41,6 +41,9 @@ Example 5: Use environment variables to send logs from /var/log files to a redis
Example 6: Zeromq listening on port 5556 (all interfaces)
cli: ZEROMQ_ADDRESS="tcp://*:5556" beaver -m bind -t zmq
+Example 7: Run beaver as a daemon in the background
+ cli: beaver -D
+
Please see the readme for more complete examples.
"""
@@ -48,6 +51,7 @@ parser = argparse.ArgumentParser(description='Beaver logfile shipper',
epilog=epilog_example,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('-c', '--configfile', help='ini config file path', dest='config', default='/dev/null')
+parser.add_argument('-D', '--daemon', help='daemonize in the background', dest='daemon', default=False, action='store_true')
parser.add_argument('-d', '--debug', help='enable debug mode', dest='debug', default=False, action='store_true')
parser.add_argument('-f', '--files', help='space-separated filelist to watch, can include globs (*.log). Overrides --path argument', dest='files', default=None, nargs='+')
parser.add_argument('--format', help='format to use when sending to transport', default=None, dest='format', choices=['json', 'msgpack', 'string'])
@@ -60,53 +64,61 @@ parser.add_argument('--fqdn', help="use the machine's FQDN for source_host", des
args = parser.parse_args()
-if args.version:
- formatter = logging.Formatter('%(message)s')
- logger = beaver.utils.setup_custom_logger('beaver', debug=args.debug, formatter=formatter)
- logger.info("Beaver {0}".format(full_version))
- sys.exit(0)
+def main(args):
+ if args.version:
+ formatter = logging.Formatter('%(message)s')
+ logger = beaver.utils.setup_custom_logger('beaver', debug=args.debug, formatter=formatter)
+ logger.info("Beaver {0}".format(full_version))
+ sys.exit(0)
-logger = beaver.utils.setup_custom_logger('beaver', debug=args.debug)
+ logger = beaver.utils.setup_custom_logger('beaver', debug=args.debug)
-file_config = beaver.file_config.FileConfig(args, logger=logger)
-beaver_config = beaver.beaver_config.BeaverConfig(args, logger=logger)
-beaver_config.update_files(file_config)
-beaver_config.check_for_deprecated_usage()
+ file_config = beaver.file_config.FileConfig(args, logger=logger)
+ beaver_config = beaver.beaver_config.BeaverConfig(args, logger=logger)
+ beaver_config.update_files(file_config)
+ beaver_config.check_for_deprecated_usage()
-failure_count = 0
+ failure_count = 0
-ssh_tunnel = beaver.worker.create_ssh_tunnel(file_config, beaver_config)
-if ssh_tunnel is not None:
- logger.info("Proxying transport using through local ssh tunnel")
+ ssh_tunnel = beaver.worker.create_ssh_tunnel(file_config, beaver_config)
+ if ssh_tunnel is not None:
+ logger.info("Proxying transport using through local ssh tunnel")
-while 1:
- try:
- worker = beaver.worker.run_worker(file_config, beaver_config, logger, ssh_tunnel=ssh_tunnel)
- except beaver.transport.TransportException, e:
- failure_count = failure_count + 1
- if failure_count > int(beaver_config.get('max_failure')):
- failure_count = int(beaver_config.get('max_failure'))
+ while 1:
+ try:
+ worker = beaver.worker.run_worker(file_config, beaver_config, logger, ssh_tunnel=ssh_tunnel)
+ except beaver.transport.TransportException, e:
+ failure_count = failure_count + 1
+ if failure_count > int(beaver_config.get('max_failure')):
+ failure_count = int(beaver_config.get('max_failure'))
- sleep_time = int(beaver_config.get('respawn_delay')) ** failure_count
- logger.info("Caught transport exception, respawning in %d seconds" % sleep_time)
+ sleep_time = int(beaver_config.get('respawn_delay')) ** failure_count
+ logger.info("Caught transport exception, respawning in %d seconds" % sleep_time)
+
+ try:
+ time.sleep(sleep_time)
+ except KeyboardInterrupt:
+ logger.info("User cancelled respawn.")
+ if ssh_tunnel is not None:
+ logger.info("Closing ssh tunnel.")
+ ssh_tunnel.close()
+
+ sys.exit(0)
- try:
- time.sleep(sleep_time)
except KeyboardInterrupt:
- logger.info("User cancelled respawn.")
+ logger.info("Shutting down. Please wait.")
+ worker.close()
if ssh_tunnel is not None:
logger.info("Closing ssh tunnel.")
ssh_tunnel.close()
+ logger.info("Shutdown complete.")
sys.exit(0)
- except KeyboardInterrupt:
- logger.info("Shutting down. Please wait.")
- worker.close()
- if ssh_tunnel is not None:
- logger.info("Closing ssh tunnel.")
- ssh_tunnel.close()
-
- logger.info("Shutdown complete.")
- sys.exit(0)
+if __name__ == "__main__":
+ if args.daemon:
+ with daemon.DaemonContext():
+ main(args = args)
+ else:
+ main(args = args)
View
1  requirements/base.txt
@@ -2,3 +2,4 @@ argparse>=1.2.0
pika>=0.9.5
redis==2.4.11
ujson>=1.9
+daemon>=1.5.2
View
3  requirements/base26.txt
@@ -1,5 +1,6 @@
argparse>=1.2.0
pika>=0.9.5
redis==2.4.11
-ujson==1.9
+ujson>=1.9
ordereddict
+daemon>=1.5.2

No commit comments for this range

Something went wrong with that request. Please try again.