1 | #!/bin/bash |
---|
2 | # |
---|
3 | # Cleans up after a login snapshot to make the machine ready for the |
---|
4 | # next login. |
---|
5 | # |
---|
6 | # This script may choose to reboot the machine in order to clear |
---|
7 | # user processes or processes using the login snapshot, although |
---|
8 | # that circumstance should be fairly rare. |
---|
9 | |
---|
10 | print_processes_info() { |
---|
11 | echo "BEGIN PRINT_PROCESS_INFO" |
---|
12 | pstree -alcnpu |
---|
13 | ps eauxwww |
---|
14 | schroot --list |
---|
15 | LC_ALL=C lsof -b +c 0 -w |
---|
16 | echo "END PRINT_PROCESS_INFO" |
---|
17 | } |
---|
18 | |
---|
19 | set -e |
---|
20 | exec >>/var/log/athena-reactivate 2>&1 |
---|
21 | |
---|
22 | # Stop any daemons that were specifically started inside the |
---|
23 | # chroot |
---|
24 | for daemon in $daemons; do |
---|
25 | invoke-rc.d $daemon restart || [ $? = 100 ] |
---|
26 | done |
---|
27 | |
---|
28 | # schroot has already attempted to kill everything inside the chroot, |
---|
29 | # fairly thoroughly. Our job here is to determine if anything is stuck |
---|
30 | # after a kill -9, and reboot. |
---|
31 | for i in /var/lib/schroot/mount/*; do |
---|
32 | if mountpoint -q "$i"; then |
---|
33 | touch /var/run/reboot-required |
---|
34 | echo "rebooting due to active mountpoint $i" |
---|
35 | print_processes_info |
---|
36 | break |
---|
37 | fi |
---|
38 | done |
---|
39 | if [ -n "$USER" -a "$USER" != root ]; then |
---|
40 | if pgrep -u "$USER"; then |
---|
41 | echo "rebooting due to live user processes" |
---|
42 | print_processes_info |
---|
43 | touch /var/run/reboot-required |
---|
44 | fi |
---|
45 | fi |
---|
46 | |
---|
47 | # Cleanup our ticketenv hack |
---|
48 | # Make sure nobody was evil |
---|
49 | chattr -f -i /tmp/ticketenv || : |
---|
50 | # If you made a directory and stored files there, too bad |
---|
51 | rm -rf /tmp/ticketenv |
---|
52 | |
---|
53 | # If either we or an updated package wanted to reboot, now is a |
---|
54 | # perfectly good time to do so -- auto-update is inhibited during a |
---|
55 | # login session. |
---|
56 | if [ -e /var/run/reboot-required ]; then |
---|
57 | reboot |
---|
58 | fi |
---|