1

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>
Milhous
  • 133
  • 2
  • 9

3 Answers3

3

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).

user1686
  • 8,717
  • 25
  • 38
2

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.

kovert
  • 437
  • 3
  • 8
1

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.

niXar
  • 2,023
  • 17
  • 23