function start()
{
if [ -z “${apache_running}” ] ; then
echo "Apache is not running"
echo "Starting Apache Tomcat"
cd /opt/apache-tomcat-7.0.64/bin/
sudo ./startup.sh
else
return 0;
fi
}
it is working fine in ubuntu, centos but it is unable to start the service in redhat and is not showing any error during the run and specifying starting tomcat everytime I run the client. But I was able to start the service with the following command
For a custom init script you should follow this process:
Make your apache starting script a proper init script, so source
/etc/init.d/functions and have a proper exit code from the script (not just
the function)
Deploy your init script to the correct init location for your
distribution, so that a service resource will work
Use a service resource to call your custom init resource
But really, unless your init script is doing something pretty special then
the process should be:
Use Chef to configure all the necessary configuration files
Use a service resource to start the service using the default init script
You are using a function, not a full script. Without something that calls this function, it’s hard to know what might be the reason.
RedHat 7 uses systemctl rather that service xxx start to start daemons. service xxx start usually still works from the command line by redirecting to systemctl, but I would not be surprised if the same call failed from a script, possibly due to selinux, a missing/different environment, or something like that.
To further troubleshoot, you may want to run your script with bash -x to see what exactly is happening. You can also put this into the first line of your script:
#!/bin/bash -x
Just make sure that stdout and stderr are redirected to a file so you can analyze it later.
It seems that my original post was corrupted when one of the characters was interpreted as formatting.
The correct line to put at the beginning of your bash script is “#!/bin/bash -x” (without the quotes) - the first character is a pound sign/hash mark. You would likely already have a similar line there; simply make sure to add the -x option to enable tracing in bash.
I have placed the apache script in /etc/init.d and I was ble to start the service using service apache start this command is working fine and service is getting started which means I think I have placed the script in the correct location. Could you please suggest me something else.