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've just started learning puppet and have came across a problem I was wondering if anyone knew how to fix.I m trying to remove a user I get an error message stating that they are logged in so can't be removed.

Now in this case I know what server they're logged into so I could simply just log the user out and proceed from there.My question is however what do you do when you don't know what servers they're logged into? Keeping in mind it could be many servers.

Is there a force remove option or a way to log users out in puppet?

Code below:

user {'art':

ensure => absent,

}

Errors:

Error: Could not delete user art: Execution of '/usr/sbin/userdel art' returned 8: userdel: user art is currently logged in

Error: /Stage[main]/Main/Node[demo]/User[art]/ensure: change from present to absent failed: Could not delete user art: Execution of '/usr/sbin/userdel art' returned 8: userdel: user art is currently logged in

share|improve this question

2 Answers 2

According to this post, you can disconnect users using pkill -STOP -u USERNAME.
You can create a resource definition something this in puppet:

define kill_and_delete {
    exec { "killing $title":
        command => "pkill -STOP -u $title",
        onlyif  => "grep '^$title' /etc/passwd",
        before => User[$title],
    }
    user { $title: ensure => absent}
}

Afterwards, you use it like this:
kill_and_delete {'art': }
Note: I didn't test this.
see resource ordering - before and require and type reference - exec.

share|improve this answer
2  
You're almost there. -STOP will simply suspend the processes, not kill them. –  Michael Hampton Jul 18 at 11:41

You terminate a session by killing its parent process, called the session leader. Find out which process it is with:

ps -dN|grep pts/3

or

As mentioned by @Nitz

pkill -9 -u username

And for reference check this link:

How can I force other users to log out?

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.