Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
satella
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
satella
Commits
c2547b47
Commit
c2547b47
authored
7 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
shorter
parent
bfbf174e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
satella/posix/daemon.py
+14
-5
14 additions, 5 deletions
satella/posix/daemon.py
with
14 additions
and
5 deletions
satella/posix/daemon.py
+
14
−
5
View file @
c2547b47
...
...
@@ -4,20 +4,24 @@ from __future__ import print_function, absolute_import, division
import
logging
import
os
import
sys
import
six
try
:
import
pwd
import
grp
except
ImportError
:
pass
# Windows?
# Windows?
class
L
(
object
):
# always return UID=GID=0
def
__getattr__
(
self
,
item
):
return
lambda
q
:
0
pwd
=
grp
=
L
()
from
satella.coding
import
typed
,
Callable
logger
=
logging
.
getLogger
(
__name__
)
@typed
(
Callable
,
bool
,
(
None
,
int
),
(
None
,
int
))
def
daemonize
(
exit_via
=
sys
.
exit
,
redirect_std_to_devnull
=
True
,
...
...
@@ -38,8 +42,10 @@ def daemonize(exit_via=sys.exit,
Refer -
"
Advanced Programming in the UNIX Environment
"
13.3
:param exit_via: callable used to terminate process
:param redirect_std_to_devnull: whether to redirect stdin, stdout and stderr to /dev/null
:param uid: User to set (via seteuid). Default - this won
'
t be done. You can pass either user name as string or UID.
:param redirect_std_to_devnull: whether to redirect stdin, stdout and
stderr to /dev/null
:param uid: User to set (via seteuid). Default - this won
'
t be done. You
can pass either user name as string or UID.
:param gid: Same as UID, but for groups. These will be resolved too.
:raises KeyError: uid/gid was passed as string, but getpwnam() failed
"""
...
...
@@ -60,15 +66,18 @@ def _parse_ug(no, module, fieldname, osfun):
no
=
getattr
(
module
.
getpwnam
(
no
),
fieldname
)
osfun
(
no
)
def
_redirect_descriptors_to_null
():
sys
.
stdin
=
open
(
'
/dev/null
'
,
'
rb
'
)
sys
.
stdout
=
open
(
'
/dev/null
'
,
'
wb
'
)
sys
.
stderr
=
open
(
'
/dev/null
'
,
'
wb
'
)
def
_close_descriptors
():
for
d
in
[
sys
.
stdin
,
sys
.
stdout
,
sys
.
stderr
]:
d
.
close
()
def
_double_fork
(
exit_via
):
os
.
umask
(
0
)
...
...
@@ -79,4 +88,4 @@ def _double_fork(exit_via):
if
os
.
fork
()
>
0
:
exit_via
()
# parent exits
os
.
chdir
(
'
/
'
)
\ No newline at end of file
os
.
chdir
(
'
/
'
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment