# Problems with restarting from rc.d folder



## magrathea (May 28, 2014)

I would very much appreciate any hint on a problem with restarting apache and other programs. I've installed apache24 and it works just fine except for one thing. Once I try to execute `root@enterprise:/usr/local/etc/rc.d/apache24 restart` I get back this error:

```
root@enterprise:/usr/local/etc/rc.d # ls
apache24   dbus   htcacheclean   nagios
avahi-daemon   kpropd   openvpn   avahi-dnsconfd
hald   mysql-server   php-fpm
root@enterprise:/usr/local/etc/rc.d # apache24 restart
apache24: command not found.
```
At the time this was not such a big problem since apache is otherwise working and instead restarting it this way I would restart the computer. However, now I have a similar problem with connecting nagios with nrpe2. Nagios is working on a server but when I install and try to run nrpe2 check with `/usr/local/libexec/nagios # check_nrpe2 -H localhost` I get the same problem:

```
root@enterprise: /usr/local/libexec/nagios # ls -l check_nrpe2
-r-xr-xr-x 1 root wheel 14736 May 27 20:46 check_nrpe2
root@enterprise: /usr/local/libexec/nagios # check_nrpe2 -H localhost
check_nrpe2: Command not found
```
So, even a file that is clearly in the directory it can't be executed!

Just to mention, other commands that are suggested as a test whether nrpe2 is functioning are producing expected output, such as

```
# ps auxww | grep nrpe
root 1331  0.0 0.1 10280 1920 v1 S+ 7:46 PM  0:00.00 grep nrpe
# netstat -a | grep 5666
tcp4   0   0  *.5666   *.* LISTEN
tcp6   0   0  *.5666   *.* LISTEN
```
I've tried everything suggested on the net (`rehash` and similar) but with zero effect. At this point I'm really out of options and any help would really be appreciated.

*T*han*ks*.


----------



## ljboiler (May 28, 2014)

When you try to run any command, it must be found in a directory listed in the PATH environment variable, or you must type in some absolute or relative path information where it can be found. By default, the current directory (".") is NOT included as part of the PATH, and for good reasons.
If you `cd` to the directory where the command you want to run lives, put the relative ./ in front of the command name, like this:

```
cd /usr/local/etc/rc.d
./apache24 restart
cd /usr/local/libexec/nagios
./check_nrpe2 -H localhost
```


----------



## wblock@ (May 28, 2014)

Don't run the rc.d scripts directly, use service(8): `service apache24 restart`

There are completions for various shells so it will autocomplete from the list of services.


----------

