Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am trying to reboot my tomcat version 5 on a centos server from my dev box. I can login as a normal user(not root) but I need to be able to reboot the service. Is there a config file that I can modify or a group my my user needs to be in to be able to restart the tomcat5 service?

EDIT: I will be running this task in Ant, and sudo will not work for this as Ant does not give you a virtual terminal.

EDIT: here is the error when I try to restart tomcat as root via ant.

ssh root@server.com /sbin/service tomcat5 restart

restartTomcat:
 [exec] Pseudo-terminal will not be allocated because stdin is not a terminal.

This is running as root,which has ssh privileges. The command as is works fine.

EDIT

vi /etc/sudoers (EDIT: please use visudo instead)
comment out: #Default requiretty

This fixes the tty item. Now it works as the normal user.

Here is my ant target

<target name="restartTomcat">
  <exec executable="/usr/bin/ssh">
    <arg line="user@server.com sudo /sbin/service tomcat5 restart"/>
  </exec>
</target>
share|improve this question
1  
Can you connect in as the user that tomcat is running as? (which is the 'tomcat' user on my machines) or maybe su to them? –  Matt Simmons May 30 '09 at 16:21
    
It's not good practice to give application users shell access - stick to sudo. –  Xerxes May 30 '09 at 16:35

3 Answers 3

up vote 2 down vote accepted

If you are having issues using sudo and you get a message like this:

sudo: sorry, you must have a tty to run sudo

Then you should comment out:

Defaults    requiretty

Inside /etc/sudoers. Since RHEL/CentOS is shipped with that option turned on by default.

share|improve this answer

If the server has sudo installed, you can add yourself to the sudoers file (using the visudo command) - you can either allow everything, or just that particular command. Then use sudo somecommand to run it with root privileges.

But no matter what method, you will need to login as root at least once - or get someone else to login as root.

Edit: sudo has a passwordless option (NOPASSWD in sudoers), which doesn't require a tty (if I remember correctly).

share|improve this answer
    
vi /etc/sudoers (EDIT: please use visudo instead) comment out: #Default requiretty –  Milhous May 30 '09 at 16:47

Get the admin to add "/etc/init.d/tomcat" to the list of commands you can execute w/o password, that way you can sudo it without a pty:

yourname machinename=(ALL) NOPASSWD:/etc/init.d/tomcat

There are many other ways to do what you ask, tough.

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.