⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 configtuning-starting-services.html

📁 FreeBSD操作系统的详细使用手册
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta name="generator" content="HTML Tidy, see www.w3.org" /><title>Starting Services</title><meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.7" /><link rel="HOME" title="FreeBSD Handbook" href="index.html" /><link rel="UP" title="Configuration and Tuning" href="config-tuning.html" /><link rel="PREVIOUS" title="Application Configuration"href="configtuning-appconfig.html" /><link rel="NEXT" title="Configuring the cron Utility" href="configtuning-cron.html" /><link rel="STYLESHEET" type="text/css" href="docbook.css" /></head><body class="SECT1" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#840084"alink="#0000FF"><div class="NAVHEADER"><table summary="Header navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><th colspan="3" align="center">FreeBSD Handbook</th></tr><tr><td width="10%" align="left" valign="bottom"><a href="configtuning-appconfig.html"accesskey="P">Prev</a></td><td width="80%" align="center" valign="bottom">Chapter 11 Configuration and Tuning</td><td width="10%" align="right" valign="bottom"><a href="configtuning-cron.html"accesskey="N">Next</a></td></tr></table><hr align="LEFT" width="100%" /></div><div class="SECT1"><h1 class="SECT1"><a id="CONFIGTUNING-STARTING-SERVICES"name="CONFIGTUNING-STARTING-SERVICES">11.5 Starting Services</a></h1><i class="AUTHORGROUP"><span class="CONTRIB">Contributed by</span> Tom Rhodes.</i> <p>Many users choose to install third party software on FreeBSD from the portscollection. In many of these situations it may be necessary to configure the software ina manner which will allow it to be started upon system initialization. Services, such as<a href="http://www.FreeBSD.org/cgi/url.cgi?ports/mail/postfix/pkg-descr"><ttclass="FILENAME">mail/postfix</tt></a> or <ahref="http://www.FreeBSD.org/cgi/url.cgi?ports/www/apache13/pkg-descr"><ttclass="FILENAME">www/apache13</tt></a> are just two of the many software packages whichmay be started during system initialization. Thus it is only fair that an explanation beprovided on the procedures available for working with third party software, in the rarecases something goes wrong and the application does not start up properly.</p><p>In FreeBSD, most included services, such as <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=cron&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">cron</span>(8)</span></a>, are startedthrough the system start up scripts. These scripts may different depending on FreeBSD orvendor version; however, the most important aspect to consider is that their start upconfiguration can be handled through simple startup scripts.</p><p>Since the advent of rcNG, it became clear that system initialization for third partyutilities could be simplified. For years applications would drop a simple start up scriptinto the <tt class="FILENAME">/usr/local/etc/rc.d</tt> directory which would be read bythe system initialization scripts. These scripts would then be executed during the latterstages of system start up.</p><p>While many individuals have spent hours trying to merge the old configuration styleinto the new system, the fact remains that some third party utilities still require ascript simply dropped into the aforementioned directory. The subtle differences in thescripts depend whether or not rcNG is being used. Any version of FreeBSD prior to 5.1will not require the extra bit of configuration; indeed, in almost all cases the soon tobe recognized script would do just fine.</p><p>While every script must meet some minimal requirements, most of the time theserequirements are FreeBSD version agnostic. Each script must have a <ttclass="FILENAME">.sh</tt> extension appended to the end and every script must beexecutable by the system. The latter may be achieved by using the <ttclass="COMMAND">chmod</tt> and setting the unique permissions of <varclass="LITERAL">755</var>. There should also be, at minimal, an option to <varclass="LITERAL">start</var> the application and an option to <varclass="LITERAL">stop</var> the application.</p><p>The simplest start up script would probably look a little bit like this one:</p><pre class="PROGRAMLISTING">#!/bin/shecho -n ' utility'case "$1" instart)        /usr/local/bin/utility        ;;stop)        kill -9 `cat /var/run/utility.pid`        ;;*)        echo "Usage: `basename $0` {start|stop}" &#62;&#38;2        exit 64        ;;esacexit 0</pre><p>This script provides for a <var class="LITERAL">stop</var> and <varclass="LITERAL">start</var> option for the application hereto referred simply as <varclass="LITERAL">utility</var>. This application could then have the following line placedin <tt class="FILENAME">/etc/rc.conf</tt>:</p><pre class="PROGRAMLISTING">utility_enable="YES"</pre><p>Could be started manually with:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT"><ttclass="FILENAME">/usr/local/etc/rc.d/utility.sh</tt> start</kbd></pre><p>While not all third party software requires the line in <ttclass="FILENAME">rc.conf</tt>, almost every day a new port will be modified to acceptthis configuration. Check the final output of the installation for more information on aspecific application. Some third party software will provide start up scripts whichpermit the application to be used with rcNG; although, this will be discussed in the nextsection.</p><div class="SECT2"><h2 class="SECT2"><a id="AEN15795" name="AEN15795">11.5.1 Extended ApplicationConfiguration</a></h2><p>Now that FreeBSD includes rcNG, configuration of application start up has become moreoptimal; indeed, it has become a bit more in depth. Using the key words discussed in the<a href="configtuning-rcng.html">rcNG</a> section, applications may now be set to startafter certain other services for example <acronym class="ACRONYM">DNS</acronym>; maypermit extra flags to be passed through <tt class="FILENAME">rc.conf</tt> in place ofhard coded flags in the start up script, etc. A basic script may look similar to thefollowing:</p><pre class="PROGRAMLISTING">#!/bin/sh## PROVIDE: utility# REQUIRE: DAEMON# BEFORE: LOGIN# KEYWORD: FreeBSD shutdown## DO NOT CHANGE THESE DEFAULT VALUES HERE# SET THEM IN THE /etc/rc.conf FILE#utility_enable=${utility_enable-"NO"}utility_flags=${utility_flags-""}utility_pidfile=${utility_pidfile-"/var/run/utility.pid"}. /etc/rc.subrname="utility"rcvar=`set_rcvar`command="/usr/local/sbin/utility"load_rc_config $namepidfile="${utility_pidfile}"start_cmd="echo \"Starting ${name}.\"; /usr/bin/nice -5 ${command} ${utility_flags} ${command_args}"run_rc_command "$1"</pre><p>This script will ensure that the provided <b class="APPLICATION">utility</b> will bestarted before the <var class="LITERAL">login</var> service but after the <varclass="LITERAL">daemon</var> service. It also provides a method for setting and trackingthe <acronym class="ACRONYM">PID</acronym>, or process <acronymclass="ACRONYM">ID</acronym> file.</p><p>This new method also allows for easier manipulation of the command line arguments,inclusion of the default functions provided in <tt class="FILENAME">/etc/rc.subr</tt>,compatibility with the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=rcorder&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">rcorder</span>(8)</span></a> utility andprovide for easier configuration via the <tt class="FILENAME">rc.conf</tt> file. Inessence, this script could even be placed in <tt class="FILENAME">/etc/rc.d</tt>directory. Yet, that has the potential to upset the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=mergemaster&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">mergemaster</span>(8)</span></a> utilitywhen used in conjunction with software upgrades.</p></div><div class="SECT2"><h2 class="SECT2"><a id="AEN15818" name="AEN15818">11.5.2 Using Services to StartServices</a></h2><p>Other services, such as <acronym class="ACRONYM">POP</acronym>3 server daemons,<acronym class="ACRONYM">IMAP</acronym>, etc. could be started using the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=inetd&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">inetd</span>(8)</span></a>. Thisinvolves installing the service utility from the ports collection with a configurationline appended to the <tt class="FILENAME">/etc/inetd.conf</tt> file, or uncommenting oneof the current configuration lines. Working with <tt class="COMMAND">inetd</tt> and itsconfiguration is described in depth in the <a href="network-inetd.html">inetd</a>section.</p><p>In some cases, it may be more plausible to use the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=cron&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">cron</span>(8)</span></a> daemon tostart system services. This approach has a number of advantages because <ttclass="COMMAND">cron</tt> runs these processes as the <tt class="COMMAND">crontab</tt>'sfile owner. This allows regular users to start and maintain some applications.</p><p>The <tt class="COMMAND">cron</tt> utility provides a unique feature, <varclass="LITERAL">@reboot</var>, which may be used in place of the time specification. Thiswill cause the job to be run when <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=cron&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">cron</span>(8)</span></a> is started,normally during system initialization.</p></div></div><div class="NAVFOOTER"><hr align="LEFT" width="100%" /><table summary="Footer navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><td width="33%" align="left" valign="top"><a href="configtuning-appconfig.html"accesskey="P">Prev</a></td><td width="34%" align="center" valign="top"><a href="index.html"accesskey="H">Home</a></td><td width="33%" align="right" valign="top"><a href="configtuning-cron.html"accesskey="N">Next</a></td></tr><tr><td width="33%" align="left" valign="top">Application Configuration</td><td width="34%" align="center" valign="top"><a href="config-tuning.html"accesskey="U">Up</a></td><td width="33%" align="right" valign="top">Configuring the <tt class="COMMAND">cron</tt>Utility</td></tr></table></div><p align="center"><small>This, and other documents, can be downloaded from <ahref="ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/">ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/</a>.</small></p><p align="center"><small>For questions about FreeBSD, read the <ahref="http://www.FreeBSD.org/docs.html">documentation</a> before contacting &#60;<ahref="mailto:questions@FreeBSD.org">questions@FreeBSD.org</a>&#62;.<br />For questions about this documentation, e-mail &#60;<ahref="mailto:doc@FreeBSD.org">doc@FreeBSD.org</a>&#62;.</small></p></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -