Skip to content

Commit

Permalink
add option to chdir or not
Browse files Browse the repository at this point in the history
  • Loading branch information
ba0f3 committed Feb 22, 2017
1 parent ff6f4e7 commit 82002d8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions daemonize.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ proc onStop(sig: cint) {.noconv.} =

quit(QuitSuccess)

template daemonize*(pidfile, si, so, se: string, body: stmt): stmt {.immediate.} =
template daemonize*(pidfile, si, so, se, cd: string,body: stmt): stmt {.immediate.} =
## deamonizer
##
## pidfile: path to file where pid will be stored
## si: standard input for daemonzied process
## so: standard output for daemonzied process
## se: standard ouput for daemonzied process
## cd: directory to switch to, nil or empty to stay

if fileExists(pidfile):
raise newException(IOError, "pidfile " & pidfile & " already exist, daemon already running?")
Expand All @@ -34,7 +35,8 @@ template daemonize*(pidfile, si, so, se: string, body: stmt): stmt {.immediate.}
if pid > 0:
quit(QuitSuccess)

discard chdir("/")
if not isNilorEmpty(cd):
discard chdir(cd)
discard setsid()
discard umask(0)

Expand Down
2 changes: 1 addition & 1 deletion daemonize.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Package]
name = "daemonize"
version = "0.0.2"
version = "0.0.3"
author = "Huy Doan"
description = "This library makes your code run as a daemon process on Unix-like systems"
license = "MIT"
Expand Down

0 comments on commit 82002d8

Please sign in to comment.