No description
Find a file
2025-05-21 03:19:04 +08:00
.github/workflows Update action.yml 2020-06-27 22:20:20 +08:00
src v0.2.1 2025-05-21 03:19:04 +08:00
tests v0.2.1 2025-05-21 03:19:04 +08:00
.gitignore have no permission run daemon on mac? 2018-08-25 07:02:31 +08:00
daemonim.nimble v0.2.1 2025-05-21 03:19:04 +08:00
README.md o 2018-08-26 15:32:48 +08:00

daemonim

This package that will daemonize your program so it can continue running in the background. It works on Unix, Linux and OS X, creates a PID file and has standard commands (start, stop, restart) .

Based on python-daemon

see also PEP 3143

Usage

    import daemonim
    import os
    const
        DEVNULL = "/dev/null"
    var d = initDaemon("/tmp/daemonim.pid",open(DEVNULL,fmRead),open(DEVNULL,fmAppend),open(DEVNULL,fmAppend))
    daemonize(d):
        echo d.pidfile
        while true:
            echo d.is_running()
            sleep(2000)

or

    import daemonim
    import os
    const
        defaultAppName = "daemonim"
        STD_ERR_LOG = "$#-stderr.log" % defaultAppName
        STD_OUT_LOG = "$#-stdout.log" % defaultAppName
        STD_IN_LOG = "$#-stdin.log" % defaultAppName

    var d2 = initDaemon(defaultPidPath,STD_IN_LOG,STD_OUT_LOG,STD_ERR_LOG)
    # or var d2 = initDaemon(defaultPidPath)
    daemonize(d2):
        echo d2.pidfile
        while true:
            echo d2.is_running()
            sleep(2000)

Actions

  • start() - starts the daemon (creates PID and daemonizes).
  • stop() - stops the daemon (stops the child process and removes the PID).
  • restart() - does stop() then start().