cat /etc/passwd (last line):


I need to make an init.d script to run Tomcat EE like service tomee start.

So I have 2 problems:

  1. How I can execute command (from root) as a tomee user (no bash login) ?

    sudo su - tomee -c "some command"

Doesn't work.

sudo - tomee -s "/bin/bash" -c "some command"

works, but I think it looks horrible.

  1. As far as I said I'm going to use it it /etc/init.d/tomee service bash script, and the problem here I need somehow to have JAVA_HOME envirioment variable set before executing the above command. (So how it could be done if tomee user is system and doesnt have shell?)

And I also have an issue (warning) that couldn't change dir to /home/tomee. Yes, it doesn't exist, but I created the user as a system one.

I'm using an RHEL (not the newest, so there isn't systemd). How do I run TomEE as a service on RHEL6?


[root@localhost httpd]# su tomee /usr/local/tomee-webprofile-1.7.2/bin/startup.sh
[root@localhost httpd]#

And no results. Only

su - tomee -s "/bin/bash" /usr/local/tomee-webprofile-1.7.2/bin/startup.sh

works, but I don't want to see this awful -s "/bin/bash" part.

And moreover, according to JAVA_HOME, if I put it inside init.d script (tomee) so it has sense for root only as init.d scripts run as root, so there will be no JAVA_HOME for the tomee user?


[root@localhost ~]# su tomee -s "/bin/bash" -c "echo hi"

It prints "hi" - it is OK.

[root@localhost ~]# su tomee -c "echo hi"

It prints nothing. Why?


I finally made it working with:

su -s /bin/bash $TOMCAT_USER $TOMCAT_CATALINA_SH stop

I noticed oracle db's init scripts use the same approach, so I think it's ok.

BTW, I still can't understand why we need to specify shell while we executing a *.sh file as there is the first line where #!/bin/bash etc.

  • Your question should be titled "How do I run TomEE as a service on RHEL6?" and you should repeat that question at the end of your question body to make your need clear. I have answered assuming that is your question. – Alain O'Dea Jul 2 '15 at 16:42
  • UPD #3 should be post as answer and mark as accepted. Please do not include answers in the question section. – 030 Jul 2 '15 at 17:49
  • To the close voters: TomEE is actually an EJB supporting fork of Tomcat. EJB is: Enterprise Java Beans, maybe it is enough strong argument to show, it is an ontopic question. – peterh Jul 6 '15 at 21:14
  • I've tried to save your question by formatting it to a readable form, but I don't think you deserved that. How do you want a helping answer from people here, if you don't commit every possible to make their work as easy as you can? – peterh Jul 6 '15 at 21:20
  • hi peterh, sorry If I do smth wrong, Im new here and dont know what should i do? ) – user3070377 Jul 8 '15 at 14:15

service start tomee is run by root to start the tomee service. It's not the actual command the init script would run. The init script for this is included below.

JAVA_HOME should be set in the init script.

/etc/init.d/tomee (needs to be marked executable):

# description: TomEE Start Stop Restart
# processname: tomee
# chkconfig: 234 20 80
export JAVA_HOME
export PATH

case $1 in
/bin/su $TOMEE_USER $CATALINA_HOME/bin/startup.sh
/bin/su $TOMEE_USER $CATALINA_HOME/bin/shutdown.sh
/bin/su $TOMEE_USER $CATALINA_HOME/bin/shutdown.sh
/bin/su $TOMEE_USER $CATALINA_HOME/bin/startup.sh
exit 0

Adapted from http://www.davidghedini.com/pg/entry/apache_tomee_on_centos_6.

Edit CATALINA_HOME above to be the absolute path of your TomEE install. Make sure it is readable by the tomee user and that the webapps, logs, temp, and work directories within it are writable by the tomee user.

  • Thank you for your reply, I have made an update to my answer, your solution uses "/bin/su $TOMEE_USER $CATALINA_HOME/bin/startup.sh", which is not working and i try to find out why. – user3070377 Jul 2 '15 at 17:01
  • @user3070377 I've added steps to my answer. Please share the errors you are encountering running this. I may have a typo. – Alain O'Dea Jul 2 '15 at 17:11
  • I understood what u mean, but basically I cannot execute "/bin/su <user> <command>" - it just doesn't work for me (no errors - just as i haven't executed anything) ((( – user3070377 Jul 2 '15 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.