Skip to content
This repository was archived by the owner on Nov 8, 2021. It is now read-only.

Commit 13d7be7

Browse files
mvanbaakmichaelwittig
authored andcommitted
Better way of shutting down processes of the users we are going to delete. Fixes #60 (#61)
1 parent 3f60633 commit 13d7be7

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

import_users.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,16 @@ function create_or_update_local_user() {
152152
}
153153

154154
function delete_local_user() {
155+
# First, make sure no new sessions can be started
155156
/usr/sbin/usermod -L -s /sbin/nologin "${1}"
156-
/usr/bin/pkill -KILL -u "${1}"
157-
/usr/sbin/userdel -r "${1}"
157+
# ask nicely and give them some time to shutdown
158+
/usr/bin/pkill -15 -u "${1}"
159+
sleep 5
160+
# Dont want to close nicely? DIE!
161+
/usr/bin/pkill -9 -u "${1}"
162+
sleep 1
163+
# Remove account now that all processes for the user are gone
164+
/usr/sbin/userdel -f -r "${1}"
158165
}
159166

160167
function clean_iam_username() {

0 commit comments

Comments
 (0)