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 [email protected] /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="[email protected] sudo /sbin/service tomcat5 restart"/>
</exec>
</target>
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 usesudo 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).If you are having issues using sudo and you get a message like this:
Then you should comment out:
Inside
/etc/sudoers
. Since RHEL/CentOS is shipped with that option turned on by default.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:
There are many other ways to do what you ask, tough.