1Net::Server::Daemonize(U3s)er Contributed Perl DocumentatNieotn::Server::Daemonize(3)
2
3
4
6 Net::Server::Daemonize - Safe fork and daemonization utilities
7
9 use Net::Server::Daemonize qw(daemonize);
10
11 daemonize(
12 'nobody', # User
13 'nobody', # Group
14 '/var/state/mydaemon.pid' # Path to PID file - optional
15 );
16
18 This module is intended to let you simply and safely daemonize your
19 server on systems supporting the POSIX module. This means that your
20 Perl script runs in the background, and it's process ID is stored in a
21 file so you can easily stop it later.
22
24 daemonize
25 Main routine. Arguments are user (or userid), group (or group id
26 or space delimited list of groups), and pid_file (path to file).
27 This routine will check on the pid file, safely fork, create the
28 pid file (storing the pid in the file), become another user and
29 group, close STDIN, STDOUT and STDERR, separate from the process
30 group (become session leader), and install $SIG{INT} to remove the
31 pid file. In otherwords - daemonize. All errors result in a die.
32 As of version 0.89 the pid_file is optional.
33
34 safe_fork
35 Block SIGINT during fork. No arguments. Returns pid of forked
36 child. All errors result in a die.
37
38 set_user
39 Become another user and group. Arguments are user (or userid) and
40 group (or group id or space delimited list of groups).
41
42 set_uid
43 Become another user. Argument is user (or userid). All errors
44 die.
45
46 set_gid
47 Become another group. Arguments are groups (or group ids or space
48 delimited list of groups or group ids). All errors die.
49
50 get_uid
51 Find the uid. Argument is user (userid returns userid). Returns
52 userid. All errors die.
53
54 get_gid
55 Find the gids. Arguments are groups or space delimited list of
56 groups. All errors die.
57
58 is_root_user
59 Determine if the process is running as root. Returns 1 or undef.
60
61 check_pid_file
62 Arguments are pid_file (full path to pid_file). Checks for
63 existance of pid_file. If file exists, open it and determine if
64 the process that created it is still running. This is done first
65 by checking for a /proc file system and second using a "ps" command
66 (BSD syntax). (If neither of these options exist it assumed that
67 the process has ended) If the process is still running, it aborts.
68 Otherwise, returns true. All errors die.
69
70 create_pid_file.
71 Arguments are pid_file (full path to pid_file). Calls
72 check_pid_file. If it is successful (no pid_file exists), creates
73 a pid file and stores $$ in the file.
74
75 unlink_pid_file
76 Does just that.
77
79 Net::Server. Net::Daemon, The Perl Cookbook Recipe 17.15.
80
82 Jeremy Howard <j+daemonize@howard.fm>
83
84 Program flow, concepts and initial work.
85
86 Paul Seamons <paul@seamons.com>
87
88 Code rework and componentization. Ongoing maintainer.
89
91 This package may be distributed under the terms of either the
92 GNU General Public License
93 or the
94 Perl Artistic License
95
96 All rights reserved.
97
98
99
100perl v5.26.3 2017-08-10 Net::Server::Daemonize(3)