Commit Graph

59 Commits

Author SHA1 Message Date
Maxim Sobolev
dffc6929bf Fix a typo in the 366098.
Reported by:	0mp
MFC after:	2 weeks
		(along with 366098)
2020-09-24 19:12:03 +00:00
Maxim Sobolev
4cd407ec93 dd a new option (-H) to daemon(8) to catch SIGHUP and re-open output_file file when
received.

The default system log rotation mechanism (newsyslog(8)) requires ability to send
signal to a daemon in order to properly complete rotation of the logs in an "atomic"
manner without having to making a copy and truncating original file. Unfortunately
our built-in mechanism to convert "dumb" programs into daemons has no way to handle
this rotation properly. This change adds this ability, to be enabled by supplying -H
option in addition to the -o option.

Reviewed by:	markj, rpokala (manpages)
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D26526
2020-09-24 02:44:58 +00:00
Ian Lepore
b6fa976de2 Bump .Dd for earlier update (should have been part of r353024). 2019-10-02 23:19:34 +00:00
Ian Lepore
0ec0f10d66 Clarify how the -f option for daemon(8) interacts with other options
related to redirecting stdout and stderr.
2019-10-02 23:06:17 +00:00
Conrad Meyer
09a3675d96 daemon(8): Don't block SIGTERM during restart delay
I believe this was introduced in the original '-r' commit, r231911 (2012).
At the time, the scope was limited to a 1 second sleep.  r332518 (2018)
added '-R', which increased the potential duration of the affected interval
(from 1 to N seconds) by permitting arbitrary restart intervals.

Instead, handle SIGTERM normally during restart-sleep, when the monitored
process is not running, and shut down promptly.

(I noticed this behavior when debugging a child process that exited quickly
under the 'daemon -r -R 30' environment.  'kill <daemonpid>' had no
immediate effect and the monitor process slept until the next restart
attempt.  This was annoying.)

Reviewed by:	allanjude, imp, markj
Differential Revision:	https://reviews.freebsd.org/D20509
2019-06-04 16:07:01 +00:00
Michael Gmelin
4f6714d53b Correct contradictory information on default syslog logging priority.
MFC after:	1 week
2019-03-25 21:14:51 +00:00
Mateusz Piotrowski
a641e44515 Cross-reference nohup(1) and daemon(8).
Reviewed by:	bcr
Approved by:	krion (mentor, implicit), mat (mentor, implicit)
Differential Revision:	https://reviews.freebsd.org/D17920
2018-11-09 13:47:06 +00:00
Mateusz Piotrowski
26e19acaeb Add a missing "Ar" macro to the description of the -R flag in the manpage.
Approved by:	bjk (doc committer), krion (mentor)
Differential Revision:	https://reviews.freebsd.org/D16520
2018-08-01 12:18:52 +00:00
Ian Lepore
c1ee3587a1 Fix cut-and-pasted line to have the right option letter.
Reported by:	0mp@
Pointy hat:	ian@
2018-04-16 03:35:43 +00:00
Ian Lepore
37820b8746 Add an option to daemon(8) to specify a delay between restarts of a
supervised program.  The existing -r option has a hard-coded delay of one
second.  This change adds a -R option which takes a delay in seconds.  This
can be used to prevent log spam and rapid restarts, similar to init(8)'s
behavior of adding a delay between rapid restarts when it's supervising a
program.
2018-04-15 21:46:08 +00:00
Maxim Konovalov
53c2c7918d o A command line flag for the syslog_facility fixed in the SYNOPSIS.
PR:		225441
2018-01-26 08:52:28 +00:00
Pedro F. Giffuni
1de7b4b805 various: general adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

No functional change intended.
2017-11-27 15:37:16 +00:00
Bryan Drewery
ea825d0274 DIRDEPS_BUILD: Update dependencies.
Sponsored by:	Dell EMC Isilon
2017-10-31 00:07:04 +00:00
Bryan Drewery
490a8aa9a1 DIRDEPS_BUILD: Update dependencies.
MFC after:	2 weeks
Sponsored by:	Dell EMC Isilon
2016-11-13 00:11:30 +00:00
Jilles Tjoelker
53d49b370a daemon: Allow logging daemon stdout/stderr to file or syslog.
There are various new options, documented in the man page, to send the
daemon's standard output and/or standard error to a file or to syslog.

Submitted by:	ank at iki.fi
Reviewed by:	wblock (man page only)
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D7993
2016-10-22 11:26:22 +00:00
Maxim Konovalov
64778f377f o -t comman line option added to the usage(). 2016-03-03 07:07:44 +00:00
Conrad Meyer
112bfcf5e4 daemon(8): Add -t option to set process title
The default process title is taken from the argv[0] value (any
particular hardlink name).  Add a -t option to override the default.

PR:		205016
Submitted by:	Yuri <yuri@rawbw.com>
No objection from:	freebsd-current@
Sponsored by:	EMC / Isilon Storage Division
2016-03-02 19:10:39 +00:00
Simon J. Gerraty
ccfb965433 Add META_MODE support.
Off by default, build behaves normally.
WITH_META_MODE we get auto objdir creation, the ability to
start build from anywhere in the tree.

Still need to add real targets under targets/ to build packages.

Differential Revision:       D2796
Reviewed by: brooks imp
2015-06-13 19:20:56 +00:00
Simon J. Gerraty
44d314f704 dirdeps.mk now sets DEP_RELDIR 2015-06-08 23:35:17 +00:00
Simon J. Gerraty
98e0ffaefb Merge sync of head 2015-05-27 01:19:58 +00:00
Baptiste Daroussin
c6db8143ed Convert usr.sbin to LIBADD
Reduce overlinking
2014-11-25 16:57:27 +00:00
Simon J. Gerraty
fae50821ae Updated dependencies 2014-05-16 14:09:51 +00:00
Simon J. Gerraty
76b28ad6ab Updated dependencies 2014-05-10 05:16:28 +00:00
Simon J. Gerraty
3b8f084595 Merge head 2014-04-28 07:50:45 +00:00
Jaakko Heinonen
ceda7f069d Fork a child process and wait until the process terminates when the -P
option is specified. This behavior is documented on the manual page.

PR:		bin/187265
Submitted by:	Kimo R
MFC after:	2 weeks
2014-04-06 16:35:49 +00:00
Simon J. Gerraty
3caf0790a8 Merge head@256284 2013-10-13 02:35:19 +00:00
Mikolaj Golub
9da0ef1316 1. Properly clean pid files in the case of the error.
2. Write the supervisor pid before the restart loop, so we don't
   uselessly rewrite it after every child restart.
3. Remove duplicate ppfh and pfh initialization.

Approved by:	re (glebius)
MFC after:	2 weeks
2013-09-19 18:00:05 +00:00
Joel Dahl
40e463f4d9 mdoc: remove EOL whitespace.
Approved by:	re (blanket)
2013-09-13 19:19:21 +00:00
John-Mark Gurney
32b17786bd add support for writing the pid of the daemon program to a pid file so
that daemon can be used w/ rc.subr and ports can use the additional
functionality, such as keeping the ldap daemon up and running, and have
the proper program to signal to exit..

PR:		bin/181341
Submitted by:	feld
Approved by:	re (glebius)
2013-09-13 16:57:28 +00:00
Simon J. Gerraty
7cf3a1c6b2 Updated dependencies 2013-03-11 17:21:52 +00:00
Simon J. Gerraty
f5f7c05209 Updated dependencies 2013-02-16 01:23:54 +00:00
David E. O'Brien
d9a447559b Sync with HEAD. 2013-02-08 16:10:16 +00:00
Marius Strobl
7c0360c4c8 Remove bogus '-' from getopt(3) string hit when porting daemon(8) to
GNU/Linux *duck*.

MFC after:	1 week
2013-01-03 00:49:11 +00:00
Simon J. Gerraty
23090366f7 Sync from head 2012-11-04 02:52:03 +00:00
Marcel Moolenaar
7750ad47a9 Sync FreeBSD's bmake branch with Juniper's internal bmake branch.
Requested by: Simon Gerraty <sjg@juniper.net>
2012-08-22 19:25:57 +00:00
Mikolaj Golub
76462499eb Document -r option in SYNOPSIS and usage statement.
Submitted by:	Andrey Zonov <andrey zonov.org>
MFC after:	3 days
2012-06-04 09:25:01 +00:00
Mikolaj Golub
c60d51f964 On a child exit, call waitpid(2) to clean up the process table.
Submitted by:	Andrey Zonov <andrey zonov.org>
MFC after:	1 week
2012-06-04 09:22:22 +00:00
Mikolaj Golub
53c49998d5 If permitted protect the supervisor against pageout kill.
Suggested by:	Andrey Zonov <andrey zonov org>
MFC after:	2 weeks
2012-02-19 10:38:55 +00:00
Mikolaj Golub
b6193c2409 Add -r option to restart the program if it has been terminated.
Suggested by:	Andrey Zonov <andrey zonov org>
MFC after:	2 weeks
2012-02-19 10:36:29 +00:00
Mikolaj Golub
195fc497a2 If the supervising process receives SIGTERM, forward it to the spawned
process.  Normally it will cause the child to exit followed by the
termination of the supervisor after removing the pidfile.

This looks like desirable behavior, because termination of a
supervisor usually supposes termination of its charge. Also it will
fix the issue with stale pid files after reboot due to init kills a
supervisor before its child exits.

MFC after:	2 weeks
2012-02-19 10:23:51 +00:00
Mikolaj Golub
2ad4302785 The pidfile_open(3) is going to be fixed to set close-on-exec in order
not to leak the descriptor after exec(3). This raises the issue for
daemon(3) of the pidfile lock to be lost when the child process
executes.

To solve this and also to have the pidfile cleaned up when the program
exits, if a pidfile is specified, spawn a child to exec the command
and wait in the parent keeping the pidfile locked until the child
process exits and remove the file.

Reported by:	Andrey Zonov <andrey zonov org>
Suggested by:	pjd
Reviewed by:	pjd
MFC after:	2 weeks
2012-02-19 10:20:37 +00:00
Guy Helmer
b34650e320 Change the notes about the pidfile to include Doug's preference
for pre-creating the pidfile with appropriate owner and permissions.

Requested by dougb
2012-02-01 16:40:59 +00:00
Guy Helmer
704523b073 Revert 229667: After some discussion of this change, it seems it is
better to leave the pidfile open where it was. Add a note to the
man page describing pidfile strategies to use if the daemon is to
be run as a user other than root.
2012-01-25 14:50:12 +00:00
Guy Helmer
074db536b3 Allow daemon(8) to run pidfile_open() before relenquishing privileges
so pid files can be written in /var/run when started as root.

I do not expect this to cause any security issues, but if anyone objects
it could be easily reverted.

PR:		bin/159568
MFC after:	4 weeks
2012-01-05 22:48:36 +00:00
Ivan Voras
27ad5065fe Slightly improve wording. 2010-05-17 11:18:33 +00:00
Ed Schouten
71ccf09269 The last big commit: let usr.sbin/ use WARNS=6 by default. 2010-01-02 11:07:44 +00:00
Peter Wemm
12d5df2b3c Unbreak rev 1.7's getopt usage. The -f switch does not take an argument.
The stray ':' was from the defunct '-g' group arg.
2007-04-19 16:43:30 +00:00
Tom Rhodes
e6d4b388b9 Improve previous commit by using setusercontext(3) and removing the group
option.  Bump doc date for manual page changes.

Reviewed by:	rwatson, ru, will (older version)
2007-03-19 12:12:53 +00:00
Tom Rhodes
15543aadb3 Initialize *pfh to NULL to quiet a gcc warning, not part of my original
commit because it was not part of the new code.
2007-03-09 09:40:23 +00:00
Tom Rhodes
12d7249e24 Add support for dropping privileges to a specified user and/or group.
PR:		108523
Submitted by:	Dmitri Alenitchev <dmitri@dworlds.ru> (original version)
Reviewed by:	mpp (first reply to PR)
2007-03-09 09:33:19 +00:00