After installing Tomcat6 via the Synaptic package manager, Tomcat is automatically started at boottime. This was fine, until I started playing with Grails. Without changing any configuration settings, Grails will start its own web server instance at the default http port, 8080, the same as Tomcat's default. This results in an error when trying to start a Grails application :
grails run-app
Server failed to start: java.net.BindException: Address already in use
There are different ways to avoid this error. Make Grails use Tomcat's instance, change either Grails or Tomcat's default http port, or don't start Tomcat at boot time. I decided to remove Tomcat's automatic startup. How do we do that in Ubuntu ?
Init scripts are in /etc/init.d, and symbolic links to these scripts are separated in runlevels, each residing in /etc/rcX.d/, where X is the runlevel. We could remove them by hand, but this can be done easily with one single command : update-rc.d
sudo update-rc.d tomcat6 disable
update-rc.d: warning: tomcat6 start runlevel arguments (none) do not match LSB Default-Start values (2 3 4 5)
update-rc.d: warning: tomcat6 stop runlevel arguments (none) do not match LSB Default-Stop values (0 1 6)
Disabling system startup links for /etc/init.d/tomcat6 ...
Removing any system startup links for /etc/init.d/tomcat6 ...
/etc/rc0.d/K20tomcat6
/etc/rc1.d/K20tomcat6
/etc/rc2.d/S20tomcat6
/etc/rc3.d/S20tomcat6
/etc/rc4.d/S20tomcat6
/etc/rc5.d/S20tomcat6
/etc/rc6.d/K20tomcat6
Adding system startup for /etc/init.d/tomcat6 ...
/etc/rc0.d/K20tomcat6 -> ../init.d/tomcat6
/etc/rc1.d/K20tomcat6 -> ../init.d/tomcat6
/etc/rc6.d/K20tomcat6 -> ../init.d/tomcat6
/etc/rc2.d/K80tomcat6 -> ../init.d/tomcat6
/etc/rc3.d/K80tomcat6 -> ../init.d/tomcat6
/etc/rc4.d/K80tomcat6 -> ../init.d/tomcat6
/etc/rc5.d/K80tomcat6 -> ../init.d/tomcat6
There are a couple of warning because I used the disable command without any parameters. These can be ignored. As the man page says : "If no start runlevel is specified after the disable or enable keywords, the script will attempt to modify links in all start run‐levels.". Enabling back the service at bootime is as simple (same warnings):
sudo update-rc.d tomcat6 enable
update-rc.d: warning: tomcat6 start runlevel arguments (none) do not match LSB Default-Start values (2 3 4 5)
update-rc.d: warning: tomcat6 stop runlevel arguments (none) do not match LSB Default-Stop values (0 1 6)
Enabling system startup links for /etc/init.d/tomcat6 ...
Removing any system startup links for /etc/init.d/tomcat6 ...
/etc/rc0.d/K20tomcat6
/etc/rc1.d/K20tomcat6
/etc/rc2.d/K80tomcat6
/etc/rc3.d/K80tomcat6
/etc/rc4.d/K80tomcat6
/etc/rc5.d/K80tomcat6
/etc/rc6.d/K20tomcat6
Adding system startup for /etc/init.d/tomcat6 ...
/etc/rc0.d/K20tomcat6 -> ../init.d/tomcat6
/etc/rc1.d/K20tomcat6 -> ../init.d/tomcat6
/etc/rc6.d/K20tomcat6 -> ../init.d/tomcat6
/etc/rc2.d/S20tomcat6 -> ../init.d/tomcat6
/etc/rc3.d/S20tomcat6 -> ../init.d/tomcat6
/etc/rc4.d/S20tomcat6 -> ../init.d/tomcat6
/etc/rc5.d/S20tomcat6 -> ../init.d/tomcat6
To disable the running service without having to reboot:
sudo /etc/init.d/tomcat6 stop
* Stopping Tomcat servlet engine tomcat6 [ OK ]
After that, Grails applications will be happy to run:
grails run-app
Welcome to Grails 1.1.1 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /usr/local/lib/grails-1.1.1
Base Directory: /home/kuriqoo/eclipse/workspace/hubbub
Running script /usr/local/lib/grails-1.1.1/scripts/RunApp.groovy
Environment set to development
Running Grails application..
Server running. Browse to http://localhost:8080/hubbub
Tomcat can be manually started using :
sudo /etc/init.d/tomcat6 start
* Starting Tomcat servlet engine tomcat6
Using CATALINA_BASE: /var/lib/tomcat6
Using CATALINA_HOME: /usr/share/tomcat6
Using CATALINA_TMPDIR: /tmp/tomcat6-tmp
Using JRE_HOME: /usr/lib/jvm/java-6-openjdk
Using CLASSPATH: /usr/share/tomcat6/bin/bootstrap.jar [ OK ]
Thanks! I appreciated the simple post and the explanatory output. Though it's user friendly, Ubuntu's default of automatically starting up any service that has been installed seems strange and insecure to me.
ReplyDeleteuseful article, thanks
ReplyDelete