summaryrefslogtreecommitdiff
path: root/etc/rc.d/rc.subr
AgeCommit message (Collapse)Author
2013-07-11no double negatives in error message; ok aja@Otto Moerbeek
2013-04-04Show only available actions in RC script usage messages.Vadim Zhukov
Also, prettify representation of actions list a bit. a lot of input and ok halex@ aja@ also ok schwarze@ small nit spotted by marc@ "makes a lot of sense to me" todd@
2012-11-19Remove useless test: rc_rm_runfile() uses rm -f which always returns 0Antoine Jacoutot
so we don't care if the file is present or not; also this function should never return a failure. ok halex@
2012-11-18Don't output "$action is not supported" when running an rc.d(8) scriptAntoine Jacoutot
from /etc/rc(8). This prevents the warning to be displayed at shutdown time when the script has rc_stop=NO. req. and input from fgsch@ "go ahead" schwarze@ input from an ok halex@, ok robert@
2012-11-12Don't check if ${local_rcconf} is defined before sourcing rc.conf but doAntoine Jacoutot
it unconditionally. The only place local_rcconf could have been defined is from /etc/rc sourcing rc.conf but then the variable is not exported so it will never be seen by rc.subr. ok robert@
2012-09-13Simplify the way we call the rc.d(8) script in "restart".Antoine Jacoutot
ok sthen@
2012-09-01Make '-f' only affects the "start" action.Antoine Jacoutot
There is no reason we couldn't reload|stop a daemon even when _flags is set to NO. As a bonus side effect, we can now see usage() on disabled scripts. discussed with sthen@ and espie@ ok sthen@
2012-08-21Use the new "-q" option of pgrep(1) instead of redirecting stdoutAntoine Jacoutot
to /dev/null.
2012-08-13unset _rcflags and _rcuser so that they don't get inherited by rc.d(8)Antoine Jacoutot
scripts; from robert at peichaer dot org ok halex@ While here, put the "sanitation" commands in their own block.
2012-08-13Set the daemon_class as readonly as it should be (and is documented asAntoine Jacoutot
such). from robert at peichaer dot org modified after a discussion with halex@ ok halex@ robert@
2012-08-11Make a couple of variables local.Antoine Jacoutot
from robert at peichaer dot org ok halex@
2012-08-04Add a new rc_usercheck variable (default to YES). When set to no, rootAntoine Jacoutot
privilege is needed to run rc_check. In effect this means /etc/rc.d/foobar check can now be run as a regular user. Discussed with robert@ during g2k12. ok todd@
2012-07-07Simplify rc_wait() (no functionnal change).Antoine Jacoutot
initially from robert at peichaer dot org with some enhancement by halex@ ok halex@
2012-05-30in -d mode, display an error message before exiting, in the case theMarc Espie
daemon is not active (happens often to me, as I forget which box has which daemons). okay ajacoutot@
2011-11-30Fix an issue when uid != euid (e.g. when running shutdown(8) as aAntoine Jacoutot
regular user, member of the operator group); rm(1) was waiting for interactive input to remove the runfiles which made no sense, so just use `-f'. issue spotted by weerd@ ok weerd@ robert@
2011-10-15either set or unset variables that are to be examined further on, don'tAlexander Hall
just leave them untouched ok ajacoutot@ sthen@ schwarze@
2011-10-12Localize _new_pexp unconditionally, or rc_read_runfile()Ingo Schwarze
might pick it up from a polluted environment. Requested by halex@, ok ajacoutot@ halex@
2011-10-09When the _RC_RUNFILE (by some ill chance) happened to be empty orIngo Schwarze
reading it failed, ${pexp} ended up as the empty string and the script would send SIGTERM to init(1), which was really inconvenient. Fix that by never allowing pexp to become empty. My patch considerably simplified by and ok ajacoutot@.
2011-10-09Finally make it possible to restart/stop a daemon after having changedAntoine Jacoutot
its _flags in rc.conf(8). When the rc.d(8) system starts a daemon, it will record its pexp under /var/run/rc.d/rcscriptname and use that to interact with it (errors in creating /var/run/rc.d or missing pexp file are non fatal, the framework will just fallback to what it currently does). deraadt@ doesn't mind a long as it doesn't come in the way of people manually managing their daemons. discussed with and input from sthen@ halex@ robert@ schwarze@ ok sthen@ robert@
2011-10-07Check if we are root right from the start.Antoine Jacoutot
ok robert@
2011-10-07Prepend an underscore to internal variable names; this was reverted byAntoine Jacoutot
mistake in the previous commit. No functionnal change. ok robert@
2011-09-25revert previous and pass on the RC_DEBUG and RC_FORCE flags in the start+stopAlexander Hall
dance on restart rather than exporting them and expose the script to a potentially polluted environment ok ajacoutot@ robert@
2011-09-24Repair "restart" debug and force modes (we need to export RC_DEBUG andAntoine Jacoutot
RC_FORCE since "restart" calls "stop" then "start"). While here, append "_" to these variable names to make it clear they are internal. ok robert@
2011-09-22Add missing "*)" case statement and make sure RC_DEBUG and RC_FORCE areAntoine Jacoutot
unset beforehands; prodded by halex@ Add rc_usage(). ok halex@
2011-09-19Use arugments for rc script instead of environment variables to indicateRobert Nagy
debug mode. This commit also adds a force mode for the script to allow one to force operations even if daemon_flags is set to NO. In this case the sane default values will be used for each script. e.g.: "/etc/rc.d/foo -f start" will start sshd even if it's disabled ok ajacoutot@
2011-07-31when reloading do an rc_wait instead of just an rc_checkRobert Nagy
from david@, okay sthen@ and input from schwarze@
2011-07-31redirect rc_err() output to stderr, from david@Robert Nagy
2011-07-23Print the daemon name before starting, and ok/failed afterwards, providingStuart Henderson
better visual cues as to what's happening. Feedback/ok aja@ schwarze@
2011-07-08add license, ok ajacoutot@, deraadt@Robert Nagy
2011-07-07Fix reload:Antoine Jacoutot
* if we try to reload a non running daemon, just exit gracefully, like we do for 'stop' * add an rc_check call right after rc_reload to make sure the daemon is still around; until now we only checked the pkill(1) return code but that is not enough ok robert@
2011-07-06Add rc.d(8) script for the system daemons that are restartable.Robert Nagy
From now on rc(8) is going to call these scripts to start them up on boot in the same order than before. In addition the inetd and rwhod variables in rc.conf are deprecated so that inetd_flags and rwhod_flags should be used. The old flags are still going to be used for some time to allow users to switch. There are more rc modifications to come later so let's put this in so we can base more work on this. It is important to mention that you can still keep using rc.local just like the way you did before, and we have no intention to remove that either. I'd also like to thank ajacoutot@, halex@, sthen@ and schwarze@ for working on this with me.
2011-07-03let reload report (ok) or (failed) just like all other actions;Ingo Schwarze
ajacoutot@ and robert@ couldn't really remember the reason to be different, either
2011-06-20Refactoring for simplicity, no functional change:Ingo Schwarze
* Instead of nesting subshells, perform a linear series of operations and bail out as soon as one of them fails. * Rename rc_print to rc_exit, let it calculate the exit code itself and let it exit, considerably simplifying error handling; new name suggested by sthen@. OK ajacoutot@ sthen@
2011-06-10Finally deal with background processes: "rc_cmd start" will now returnAntoine Jacoutot
the correct code according whether the daemon did start successfully or not. rc_wait() This function has been extended, first we need to pass in which mode we are running (start or stop) and second we can pass a number of seconds to wait (optionnal, will default to 30s). The function will return the correct code whether we are running during "rc_cmd start" or "rc_cmd stop". rc_cmd() start If we are running in background mode, then we call rc_wait with the "start" argument. The sleep(1) is needed to prevent a race condition where the process will appear in the list before failing and rc_check will see it as running. Call rc_post() when failing to prevent being left in an inconsistent state (because rc_pre() would have run successfully) rc_cmd() stop We are now calling rc_wait with the "stop" argument. "looks good" sthen@, ok robert@
2011-05-19Setting RC_DEBUG is enough, it does not need to be explicitely set toAntoine Jacoutot
"1". hint from MERIGHI Marcus ok robert@
2011-04-09Fix multiple issues and make the code simpler and more robust:Ingo Schwarze
- As noticed by ajacoutot@, re_format(7) does not treat '\t' as a tab, so some t's got stripped from daemon names. - The tr(1) failed to sanitize mixtures of blanks and tabs. ok ajacoutot@
2011-04-06- in case reload fails, print the failed message (from Piotr Sikora)Robert Nagy
- (ok) is only printed while in interactive mode, but (failed) stays even for rc if the command fails ok ajacoutot@
2011-04-06Remove leading/trailing spaces from daemon_flags.Antoine Jacoutot
ok schwarze@
2011-04-05Handle a daemon_flags of '-n' by using printf '%s\n' instead of echoPhilip Guenthe
ok otto@, aja@
2011-04-05Quote $daemon_flags to prevent echo(1) picking them as input flags.Antoine Jacoutot
from Piotr Sikora ok robert@
2011-03-25Bump timeout to 30s.Antoine Jacoutot
ok robert@
2011-03-24if daemon_flags=NO is set, just exitRobert Nagy
ok ajacoutot@
2011-03-19Since we now use pkill -0 for "check", it must be run as root,Ian Darwin
so remove that test condition. Commented by schwarze@, OK ajacoutot@
2011-03-17- introduce the INRC environment variable so that rc.subr(8) knows if itRobert Nagy
gets called from rc.local or rc.shutdown - notify the user if a given operation was successfull or not by appending the (ok) or (failed) strings to the end of the daemon name - hide stdout and stdin unless RC_DEBUG=1 is set, otherwise all the function names will be printed out and all output sent to stdin or stdout - since from now on rc.subr is taking care of printing out the daemon names on startup, we don't need to do this from rc.{local,shutdown} anymore brainkilling work done by me and ajacoutot@, ok ajacoutot@
2011-03-14Return proper codes so that we don't rc_start if rc_pre failed and weAntoine Jacoutot
don't rc_post if rc_stop failed. "I agree with the direction" sthen@ ok robert@
2011-03-10Add a small comment at the top to explain what this file does.Antoine Jacoutot
Use $() constructs as it's safer than ``. Both req. by deraadt@ Use pkill instead of pgrep in rc_check so that we don't need to fiddle with redirections in reload. prodded by schwarze@ ok robert@
2011-03-09Make reload and check consistent with start/stop.Antoine Jacoutot
ok robert@
2011-03-09Move the redirections into the rc_cmd itself instead of rc_start andAntoine Jacoutot
rc_stop so scripts don't need to set it. ok sthen@ (on a much bigger diff) robert@
2011-03-09Move rc_pre and rc_post out of the rc_start/rc_stop functions into theAntoine Jacoutot
rc_cmd start/stop actions. This way when rc.d(8) scripts override these functions, we don't loose rc_{pre,post}. Add a max 5 secs loop after rc_stop in the rc_cmd top action. This seems to be a good default for returning to command line only after the daemon has really stopped. This fixes "restart" for some daemons and allows to properly stop some others at shutdown time. Note that this is just a best-effort default, some daemons may need a lot more time to shutdown but this case is usually handled in the rc.d(8) script itself and we obviously do not want to hang the shutdown process. Call rc_cmd start/stop in restart and _not_ rc_start/rc_stop which can get overriden in a script. discussed with and inputs from sthen@ and schwarze@ ok sthen@ robert@
2011-03-06Add an "rc_bg" variable that is undefined by default and allows to startAntoine Jacoutot
a daemon in the background. man page tweaks from schwarze@ discussed with an ok schwarze@ robert@