Difference between running rc.d scripts during bootup and as root

Some of the recent upgrades broke my Rails webservers' startup. I don't know which one made it, either apache or rvm or passenger. My servers were working the same way, and the issue I want to solve is FreeBSD or system related even if it's connected to some upstream change.

The problem is that after rebooting any of the servers the Rails websites start displaying Internal server error. Running /usr/local/etc/rc.d/apache22 restart solves the problem every time. It goes wrong only after reboot.

The reason can be seen in the apache error log:
Code:
env: bash: No such file or directory

This is inside the wrapper script:
Code:
#!/usr/bin/env bash

It seems to me that /usr/bin/env can not see bash when apache is starting from rc.d at bootup. It works fine after I restart apache as root. What is the difference between running the rc script manually and the bootup process? I know that cron, for example, has very limited environment, however, the same config has been working for Rails for years until some recent updates. (Now I have this problem on a fresh testing install too so I can't tell why.)

I never modify PATH values in root's profile files neither the /etc/login.* things. I want to fix this an elegant way and make it permanent fix which survives upgrades.

Thank you.
 
plus, is /usr or /usr/local on a different filesystem? Those aren't mounted at boot.. You should probably complain to the maintainer to fix that rc script to use /bin/sh instead of bash
 
I'm pretty sure the apache22 start script should be configured to wait for file systems by default. Besides, if /usr/local wasn't mounted it wouldn't be able to run the apache22 start script at all.

Very strange problem, especially if it used to work. I can only guess that env is trying to look in the PATH but there's no PATH set at that point so it can't find bash. Doesn't explain why it used to work though.

Is this a script that came with software or did you write it yourself? I would suggest changing the first line to call bash directly rather than using /usr/bin/env and see how that goes.
 
I am pretty sure that the config is the same. I have very solid installation scripts for my FreeBSD servers (starting from zpool create). These servers are running from 2012 February.

Changing from env to full path of bash solves the current problem and generates another:
Code:
"Could not find a JavaScript runtime."
apache22 bootup start is totally broken now for me.

The new problem above also can be fixed by restarting apache22 as root. Everything gets working then. I am 80% sure that things broke after apache22 upgrade, however I have rsnapshot backups from the server and I can't see the difference between the rc.d startup scripts. I am also sure that the last time I upgraded the world and rebooted it was working. I would have noticed if my servers show "Internal server errors". And uname -a shows the last time I rebooted them. I upgraded apache22 yesterday, however, I upgraded many other software together. The world was not upgraded yet.

I can produce this error on a fresh install of FreeBSD at home and apache22 is the very last daemon starts at the bootup. The whole system runs on ZFS so everything should be mounted already.

UPDATE: sshd, cron and "Starting background filesystem checks" run after apache22.
 
When you say fresh install what do you mean. I am 99.9% certain that apache22 itself has absolutely no dependency on bash during startup and definitely not JavaScript. Do you mean a fresh install with the various Ruby/Rails packages you need installed? As I suspect it's the rails services which are having a problem starting.

In fact, where is this 'wrapper script' on the system and what is it supposed to do? Was it provided or have you written it?
 
As for "fresh install" I mean http://wiki.freebsd.org/RootOnZFS/GPTZFSBoot and the wrapper script is created by RVM during the ruby installation. /bin/sh won't work and setting the absolute path of bash also doesn't help because there are other programs required to run like nodejs and the PATH is totally missing or wrong.

And sorry, I was browsing my rsnapshot archives again and I figured out that I had this issue some months ago and I put the PATH into the apache22 rc.d script. I just forgot that. My bad. Anyway, this seems to be a nasty fix for me. Shouldn't rc.d scripts have PATH set on boot?
 
The rc.d scripts work perfectly. It's obviously the 'wrapper script' that ruby has tied into Apache that is causing the problem - it's probably targeted at Linux.

Have you tried setting the PATH at the top of the wrapper script (you'll still need to hardcode the bash path on the #! line). I'd rather do in the script that needs it than modify the Apache rc.d script.
 
Back
Top