Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I have a simple service script tomcat7 in /etc/init.d/ to start and stop my app server (tomcat) under the tomcat user. On RHEL6.

#!/bin/bash
# description: Tomcat Start Stop
# processname: tomcat
# chkconfig: 234 20 80

CATALINA_HOME=/usr/local/www/tomcat-7.0.54

case $1 in
start)
/bin/su tomcat $CATALINA_HOME/bin/startup.sh
;;
stop)
/bin/su tomcat $CATALINA_HOME/bin/shutdown.sh 30
;;
esac
exit 0

Which works fine. Both startup.sh and shutdown.sh call a script called catalina.sh. These are pre-made scripts that come with the app server.

I can use catalina.sh directly like: ./catalina.sh stop 30 -force

Which lets me specify a wait time of 30 seconds and then does a kill -9 if the process hasn't ended. But I can't get the variables to work in the tomcat7 service script. If I change it to:

stop)
/bin/su tomcat $CATALINA_HOME/bin/catalina.sh stop 30 -force

I get an error:

[root@543917-web1 bin]# service tomcat7 stop
/bin/su: invalid option -- 'o'

Can I pass the three arguments without altering the catalina.sh script?

TIA

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You can use su with -c:

/bin/su tomcat -c "$CATALINA_HOME/bin/catalina.sh stop 30 -force"

From su man page:

-c, --command=COMMAND
    pass a single COMMAND to the shell with -c
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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