rc.d script does not start

I'm trying to configure GlassFish to start within a jail.

I've written this simple script:

Code:
#!/bin/sh

. /etc/rc.subr

name=glassfish
rcvar=glassfish_enable

start_cmd="${name}_start"
stop_cmd="${name}_stop"

glassfish_start()
{
        /usr/local/glassfish/glassfish3/bin/asadmin start-domain
}

glassfish_stop()
{
        /usr/local/glassfish/glassfish3/bin/asadmin stop-domain
}

load_rc_config $name
run_rc_command "$1"

The script is located in the /usr/local/etc/rc.d directory. Filename is glassfish. Permission is set to 555.

I've also added
Code:
glassfish_enable="YES"
to rc.conf.

GlassFish does NOT start when I reboot the machine or restart the jail. However, when I execute the command [cmd=]/usr/local/etc/rc.d/glassfish start[/cmd] from within the jail (as the root user), it does start as it should.

What is the problem in my configuration? Why does it start on reboot or jail restart?
 
I've changed my script to:

Code:
#!/bin/sh

. /etc/rc.subr

name="glassfish"

rcvar=glassfish_enable
start_cmd="glassfish_start"
stop_cmd="glassfish_stop"
glassfish_user=root
glassfish_admin=/usr/local/glassfish/glassfish3/bin/asadmin
glassfish_passwordfile=/usr/local/glassfish/glassfish3/config/password.txt

glassfish_start()
{
        for _glassfish_domain in ${glassfish_domains}
        do
                /usr/bin/su -l ${glassfish_user} -c "${glassfish_admin} start-domain ${_glassfish_domain}"
        done
}

glassfish_stop()
{
	for _glassfish_domain in ${glassfish_domains}
	do
		/usr/bin/su -l ${glassfish_user} -c "${glassfish_admin} stop-domain ${_glassfish_domain}"
	done
}

glassfish_status()
{
	/usr/bin/su -l ${glassfish_user} -c "${glassfish_admin} list-domains"
}

load_rc_config $name
cmd="$1"

case "${cmd}" in
status | onestatus)
        glassfish_status
        ;;
*)
        run_rc_command "${cmd}"
        ;;
esac

It still does not work. Please help!
 
Lowell said:
Add a ".sh" to the end of the script's filename.

I don't understand this. You mean, for the case of starting up GlassFish, I have to change the name of the script asadmin to asadmin.sh?

Further, I've checked other start scripts in other jails (under /usr/local/etc/rc.d) and they all do not contain any ".sh" suffix - for example, cherokee, postgresql start scripts.
 
Alright, I got it work! When I restarts the jail or reboot the machine, GlassFish runs automatically!

Code:
glassfish# pwd
/usr/local/etc/rc.d
glassfish# ls -l
total 2
-r-xr-xr-x  1 root  wheel  909 Jun 28 18:18 glassfish.sh

BUT, I don't understand it. In the other jails - MySQL, PostgreSQL, Nginx, Cherokee - do not have that ".sh" suffix and they work well.
 
Check with service(8) in which order the scripts are run, a script may fail if it's started too early before other essential services are started.

# service -e
 
rc(8) says:

Code:
foo.sh        Scripts that are to be sourced into the current shell
              rather than a subshell have a .sh suffix.  Extreme
              care must be taken in using this, as the startup
              sequence will terminate if the script does.

It also talks about using rcorder(8).
 
I'm going to bootstrap another question to this thread that is loosely related. If I write a script that starts a group of programs and I want to run this script at startup via /etc/rc.conf what is the best way to do this?
 
Back
Top