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

I'm running the latest version of Jenkins on CentOS. In my Jenkins job, I can run post build steps, and included this command,

sudo /bin/rm /usr/java/jboss/server/default/deploy/myclient-1.0.war

which dies with the error

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

Is there a way I can rewrite the above to run the command through a tty shell? In our /etc/sudoers file, we have the line

Defaults    requiretty

but our sysadmin has forbade us from commenting it out. So any other solutions are greatly appreciated, - Dave

share|improve this question
3  
Is there some reason you have to deploy as root? It sounds like you and the sysadmin need to have a long talk. –  Michael Hampton Sep 17 '12 at 16:56
add comment

3 Answers

up vote 1 down vote accepted

If /usr/java/jboss/server/default/deploy/myclient-1.0.war has to be removed by root you might be doing something wrong. I can't think of a good reason that file would need to be owned by root.

The other option is to see how your sysadmin feels about disabling requiretty for that one command.

Cmnd_Alias           NOTTYCMD = /bin/rm /usr/java/jboss/server/default/deploy/myclient-1.0.war
Defaults!NOTTYCMD   !requiretty
share|improve this answer
    
Could you explain your comment " ... has to be removed by root you might be doing something wrong "? The files in the deploy directory are owned by the 'jboss' user with 755 perms and Jenkins runs under user 'jenkins'. –  Dave Sep 17 '12 at 19:19
    
@Dave Since the file is owned by jboss then it can be removed by jboss. No need to involve root. –  ablackhat Feb 3 at 8:04
add comment

but our sysadmin has forbade us from commenting it out.

He can disable only for the jenkins user:

Defaults:jenkins    !requiretty

The files in the deploy directory are owned by the jboss user with 755 perms and Jenkins runs under user jenkins.

or make the deploy folder group writable and set the SGID bit:

chmod -R g+w /usr/java/jboss/server/default/deploy/
chmod g+s /usr/java/jboss/server/default/deploy/

and add the jenkins user to the jboss group:

usermod -a -G jboss jenkins

then you can delete /usr/java/jboss/server/default/deploy/myclient-1.0.war without using sudo.

share|improve this answer
add comment

I had this problem too when trying to start jboss as jboss user. The problem was solved by changing a line in the file /etc/init.d/jboss in the following way:

before: su - $JBOSS_USER -c "LAUNCH_JBOSS_IN_BACKGROUND=1 JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT -c $JBOSS_CONFIG" 2>&1 > $JBOSS_CONSOLE_LOG &

after: su - $JBOSS_USER -c "LAUNCH_JBOSS_IN_BACKGROUND=1 JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT -c $JBOSS_CONFIG 2>&1 > $JBOSS_CONSOLE_LOG &"

share|improve this answer
add comment

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.