# how to rc.conf in FreeBSD 8



## a129878 (Feb 9, 2010)

How can I work out what *xxxx_enable="YES"* there are ?

E.g. 
	
	



```
mysql_enable="YES"
```

There must be loads more, but where? What man pages point to this mechanism?

Regards
Ian


----------



## tangram (Feb 9, 2010)

a129878 said:
			
		

> Where is there / how can work out what
> xxxx_enable="YES" there are ?
> 
> EG
> ...



For FreeBSD base system ${rc_conf_files} have a look at /etc/defaults/rc.conf and rc.conf(5).

For third party application such as mysql, after port/packages install read the port's message.


----------



## tangram (Feb 9, 2010)

Oh and if you skipped the after install message use pkg_info(1) with [cmd=]-D[/cmd] flag.

For example:

```
% pkg_info -D apache-2.2.14_5                                                                  
Information for apache-2.2.14_5:

Install notice:
To run apache www server from startup, add apache22_enable="YES"
in your /etc/rc.conf. Extra options can be found in startup script.

Your hostname must be resolvable using at least 1 mechanism in
/etc/nsswitch typically DNS or /etc/hosts or apache might
have issues starting depending on the modules you are using.
```


----------



## SirDice (Feb 9, 2010)

Most (all?) ports that respond to rc.conf variables have scripts in /usr/local/etc/rc.d/.

Don't change anything in /etc/defaults/rc.conf! That's what /etc/rc.conf is for


----------



## tangram (Feb 10, 2010)

Also don't copy /etc/defaults/rc.conf over to /etc/rc.conf. Simply place in /etc/rc.conf the local settings that differ from the defaults.


----------



## lme@ (Feb 10, 2010)

In FreeBSD Current and the upcoming 7.3-RELEASE you can use the service(1) command to list all available and/or enabled services.


----------



## DutchDaemon (Feb 10, 2010)

( service is also available on 8-STABLE )


----------



## SirDice (Feb 10, 2010)

DutchDaemon said:
			
		

> ( service is also available on 8-STABLE )


A relatively recent 8-stable


----------



## DutchDaemon (Feb 10, 2010)

Is there any other?  It was available early January in any case (I have one built Jan 5).


----------



## SirDice (Feb 10, 2010)

DutchDaemon said:
			
		

> Is there any other?  It was available early January in any case (I have one built Jan 5).



I have one built on 29 dec (haven't had the time to update it) and it doesn't have the command


----------



## FBSDin20Steps (Feb 10, 2010)

Service (command) Works here as well...


----------



## DutchDaemon (Feb 10, 2010)

Well, that sets the avant-garde apart from the slackers, SirDice ... wheat and chaff, beauty and the beast ...


----------



## SirDice (Feb 10, 2010)

DutchDaemon said:
			
		

> Well, that sets the avant-garde apart from the slackers, SirDice ... wheat and chaff, beauty and the beast ...



Yeah, yeah, I know. It's only one machine, my firewall. Haven't updated it yet because there is no real need to do so :e


----------



## DutchDaemon (Feb 10, 2010)

Who needs a need? "Hey, there's an even newer version" is all you need  

And now that you know that you're missing service(1), how on earth can you live without it?


----------



## FBSDin20Steps (Feb 10, 2010)

"Don't panic. SirDice..." Some advice is needed here! Just update.


----------



## SirDice (Feb 10, 2010)

I've managed without since version 3.x. I think I'll survive LOL


----------



## FBSDin20Steps (Feb 10, 2010)

+1 lOL


----------



## DutchDaemon (Feb 10, 2010)

Yeah, put on a brave face. But I can see the niggling little doubt at the back of your mind there .. and you'll upgrade. In secret.


----------



## FBSDin20Steps (Feb 10, 2010)

Lol


----------



## SirDice (Feb 10, 2010)

/me secure shells into his firewall and runs make installworld without telling anyone...


----------



## FBSDin20Steps (Feb 10, 2010)

Lol A real die hard


----------



## a129878 (Feb 10, 2010)

At Least Tangram attempted to answered the Question.
And a rucking from a Dutch Deamon, what ever next.

I have compiled my own Apache, so in reality there are two version on my system.

Sure pkg_info -D come up with the details, but that is for the Free give away FreeBSD version
The Question remains, where is there information on what xxxx_anable is.

I grep all under /etc for _enable and there is a ton of stuff in a couple of files.

But nothing on what this xxxx_enable actually is.

I assume its a variable that gets chucked into the startup environment and its the apps that have to look for it.

That gets me no where, as I am sure the main rc.conf mechanism does not fire off every goddam thing under the hood.

Oddly "_enable" returns nothing on this forum search, then, perhaps I can't even manage that properly.

Any one having a go at getting me going on what xxxx_enable is / used / how to use.

Oooops I used the "How to", sorry Mr Deamon.

Ian


----------



## phoenix (Feb 10, 2010)

rc(8) will have all the details.

If the application doesn't come with a FreeBSD RC script under /etc/rc.d/ or /usr/local/etc/rc.d, then you won't be able to use the RC system to control it.

IOW, don't install stuff by hand, use the ports tree.


----------



## DutchDaemon (Feb 10, 2010)

Put very simply: when booting, every script in /etc/rc.d and /usr/local/etc/rc.d will be called, but it will refuse to actually execute when the appropriate _enable flag is not set in either /etc/rc.conf or /etc/defaults/rc.conf. In fact, all of those scripts will have the enable flag set to NO, so they need a YES to actually execute.

Random example:
/usr/local/etc/rc.d/mysql-server

```
: ${mysql_enable="NO"}
```

We do want to run mysql at boot time, so what do we have in /etc/rc.conf?

```
mysql_enable="YES"
```

The latter overrules the former, so mysql will be started. That's the basic mechanism of the 'enable' flag.

To find out whether something is enabled, run the start script with the 'rcvar' argument, e.g.


```
# /etc/rc.d/named rcvar
# named
#
named_enable="YES"
#   (default: "")
```


```
# /usr/local/etc/rc.d/mysql-server rcvar
# mysql
#
mysql_enable="YES"
#   (default: "")
```


```
# /etc/rc.d/sendmail rcvar
# sendmail
#
sendmail_enable="YES"
#   (default: "")

# sendmail_clientmqueue
#
sendmail_enable="YES"
#   (default: "")
sendmail_msp_queue_enable="YES"
#   (default: "")
```

Etc.


----------



## phoenix (Feb 10, 2010)

Oh, and for those wanting to use service(1), it's just a shell script, so it can be "backported" to any FreeBSD release that uses RCng.  IOW, it should work on any release since 5.2.  I've tested it no 6.3 and it works quite nicely.


----------



## FBSDin20Steps (Feb 10, 2010)

oh wow... LOL. It's getting better and better...:e


----------



## drm (Feb 12, 2010)

Of course, read manuals and messages, but try reading the rc scripts. It is the best way to get to know the startup system, and you really don't need to know exactly what happens in each of the script to get the feeling of it. 

For example, when I first installed FreeBSD (about a year ago) I had some trouble getting samba to run, as I assumed Samba would start if I put 
	
	



```
samba_enabled="YES"
```
 in rc.conf, since that was the name of the RC script. It didn't, because samba actually started with two separate daemons smbd and nbmd, which I found out after reading the rc script in /usr/local/etc/rc.d/.

Sometimes it is faster to just cat or less the rc script. They mostly aren't rocket science, anyway.


----------



## ghostcorps (Feb 23, 2011)

Hi again

I am trying to run an rc script (below) to start Red5 but it doesn't seem to be working.

The script is placed in /usr/local/etc/rc.d and I have added 
	
	



```
red5_enable="YES"
```
 to rc.conf. I have created an account named red5 and installed it into /home/red5. 

I am advised that the script does work on another system and red5 works for me in standalone mode by running `~/red5.sh` but I need it to run as a service when I boot. I am inclined to think it may have something to do with the fact that the media server is jailed but only the host's dmesg is available and it does not mention red5 at all.

Where else can I look for clues?



```
#!/bin/sh
export RED5_HOME=/home/red5/
export JAVA_HOME=/usr/local/diablo-jdk1.6.0

red5_user="${red5_user:-"red5"}"
red5_pidfile="${red5_pidfile-"/var/run/red5.pid"}"
red5_chdir=$RED5_HOME
. "/etc/rc.subr"

name="red5"
rcvar=`set_rcvar`
command="$RED5_HOME/${name}.sh"
command_args=" > /dev/null 2>&1&"
pidfile="${red5_pidfile}"

start_postcmd=start_postcmd
stop_cmd="echo \"Stopping ${name}.\"; ${RED5_HOME}/red5-shutdown.sh"

start_postcmd() {
    local seconds
    for seconds in 1 2 3; do
      sleep 1
    done
    ps -U red5 -a | grep 'red5.root' | cut -d ' ' -f1 | tr -d '\n' > ${pidfile}
}

load_rc_config "${name}"

run_rc_command "$1"
```


Thanks


----------



## SirDice (Feb 23, 2011)

> ```
> for seconds in 1 2 3; do
> sleep 1
> done
> ```


Seriously? Try "sleep 3" instead of this.



> ```
> ps -U red5 -a | grep 'red5.root' | cut -d ' ' -f1 | tr -d '\n' > ${pidfile}
> ```



This is more readable and works if you've changed the user:

```
pgrep -U ${red5_user} -f red5.root > ${pidfile}
```

One way to trace it is to start it with the -x option:
`# sh -x /usr/local/etc/rc.d/red5 start`


----------



## ghostcorps (Feb 23, 2011)

SirDice said:
			
		

> One way to trace it is to start it with the -x option:
> `# sh -x /usr/local/etc/rc.d/red5 start`



Thanks 

 I got the error below with both versions but I will have to look it up tomorrow, I assume it's just a permissions thing.



```
eval: cannot create /var/run/red5.pid: Permission denied
```


----------



## SirDice (Feb 23, 2011)

Yes, your red5 user doesn't have permission to write there, only root does. Simple solution is to create a /var/run/red5/ directory and give the red5 user permission on that. Store the pid file in the directory.


----------



## ghostcorps (Feb 23, 2011)

Thanks 


Changing the pid location worked when I first ran 
	
	



```
# sh -x /usr/local/etc/rc.d/red5 start
```
 as the user red5! 


But after I rebooted, red5 had not started at all and now it will not start manually as user red5 anymore, there are no errors printed out and top shows a java service running it just doesn't actually work. Though when I run it from root it works perfectly.

Odd.. but at least it works, albeit manually.


----------



## UNIXgod (Feb 23, 2011)

phoenix said:
			
		

> Oh, and for those wanting to use service(1), it's just a shell script, so it can be "backported" to any FreeBSD release that uses RCng.  IOW, it should work on any release since 5.2.  I've tested it no 6.3 and it works quite nicely.



Ha I though I had missed something over the years when I first learned of service in the last month or so. I imagine I will be typing paths to /usr/local/etc/rc.d/service {start|stop} for some time until I can recondition my fingers.

service seems like a nice shell wrapper.


----------

