This repository has been archived by the owner on Jan 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce new Daemon.setup_logging() method
This makes things 'just work' without too much boiler plate. Also, succubus itself relies on self.logger to exist, but leaves it to the user to actually set it up.
- Loading branch information
Stefan Nordhausen
committed
Jun 15, 2017
1 parent
22bb321
commit 622067d
Showing
5 changed files
with
135 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env python | ||
"""A daemon that relies on self.logger to be usable""" | ||
from __future__ import print_function, absolute_import, division | ||
|
||
import os | ||
import sys | ||
import time | ||
|
||
from succubus import Daemon | ||
|
||
|
||
class MyDaemon(Daemon): | ||
def run(self): | ||
while True: | ||
self.logger.error("succubus test running") | ||
time.sleep(1) | ||
|
||
|
||
def main(): | ||
daemon = MyDaemon(pid_file=os.environ['PID_FILE']) | ||
sys.exit(daemon.action()) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env python | ||
from __future__ import print_function, absolute_import, division | ||
|
||
import os | ||
import shutil | ||
import subprocess | ||
import tempfile | ||
import time | ||
import unittest2 | ||
|
||
class LoggingDaemonTests(unittest2.TestCase): | ||
def setUp(self): | ||
self.temp_dir = tempfile.mkdtemp(prefix="succubus-test") | ||
self.pid_file = os.path.join(self.temp_dir, 'succubus.pid') | ||
os.environ['PID_FILE'] = self.pid_file | ||
|
||
def tearDown(self): | ||
shutil.rmtree(self.temp_dir) | ||
|
||
def test_daemon_start_status_stop(self): | ||
daemon = "./src/integrationtest/python/logging_daemon.py" | ||
subprocess.check_call([daemon, "start"]) | ||
|
||
time.sleep(0.3) | ||
# Daemon must be running. | ||
subprocess.check_call([daemon, "status"]) | ||
subprocess.check_call([daemon, "stop"]) | ||
|
||
# Daemon must be stopped as soon as "stop" returns. | ||
self.assertRaises(Exception, subprocess.check_call, [daemon, "status"]) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest2.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters