File: daemon_uid_gid_action.py

package info (click to toggle)
python-daemonize 2.5.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 200 kB
  • sloc: python: 416; makefile: 32
file content (27 lines) | stat: -rw-r--r-- 563 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env python3

from os import getuid, geteuid, getgid, getegid, path
from sys import argv
from time import sleep

from daemonize import Daemonize

pid = argv[1]
log = argv[2]


def priv():
    return open(log, "w"),


def main(f):
    uids = getuid(), geteuid()
    gids = getgid(), getegid()
    f.write(" ".join(map(str, uids + gids)))


group = "nogroup" if path.exists("/etc/debian_version") else "nobody"

daemon = Daemonize(app="test_app", pid=pid, action=main, user="nobody", group=group,
                   privileged_action=priv)
daemon.start()