Last active
August 29, 2015 14:15
-
-
Save VigneshChennai/35bb64d41e4a4beb2225 to your computer and use it in GitHub Desktop.
Revisions
-
VigneshChennai revised this gist
Feb 19, 2015 . 1 changed file with 6 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -15,7 +15,7 @@ import os def daemonize(log_folder, wd="/", umask=0): try: f = os.fork() except OSError as e: @@ -27,22 +27,21 @@ def daemonize(log_folder): if f != 0: sys.exit(0) else: signal.signal(signal.SIGHUP, lambda x, y: print("SIGHUP received during process forking, ignoring signal")) os.chdir(wd) os.setsid() os.umask(umask) try: f = os.fork() except OSError as e: print("SEVERE: Error forking.. <{fork}>".format(fork=e)) print("SEVERE: Trace -> {trace}".format( trace=traceback.format_exc())) raise e from None if f != 0: sys.exit(0) print("INFO: Started as Daemon") r = open("/dev/null", "r") os.dup2(r.fileno(), 0) -
VigneshChennai created this gist
Feb 19, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ #!/usr/bin/env python # PyDaemonize is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # PyDaemonize is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with PyDaemonize. If not, see <http://www.gnu.org/licenses/>. import os def daemonize(log_folder): try: f = os.fork() except OSError as e: print("SEVERE: Error forking.. <{fork}>".format(fork=e)) print("SEVERE: Trace -> {trace}".format( trace=traceback.format_exc())) raise e from None if f != 0: sys.exit(0) else: signal.signal(signal.SIGHUP, lambda x, y: print("SIGHUP received during process forking, ignoring signal")) os.chdir("/") os.setsid() os.umask(0) try: f = os.fork() except OSError as e: print("SEVERE: Error forking.. <{fork}>".format(fork=e)) print("SEVERE: Trace -> {trace}".format( trace=traceback.format_exc())) raise e from None if f != 0: sys.exit(0) print("INFO: Started as Daemon") r = open("/dev/null", "r") os.dup2(r.fileno(), 0) buffering = 1 # line buffering w = open(log_folder, "w", buffering=buffering) os.dup2(w.fileno(), 1) os.dup2(w.fileno(), 2)