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 -a |
---|
15 | mount |
---|
16 | LC_ALL=C lsof -b +c 0 -w |
---|
17 | echo "END PRINT_PROCESS_INFO" |
---|
18 | } |
---|
19 | |
---|
20 | set -e |
---|
21 | exec >>/var/log/athena-reactivate 2>&1 |
---|
22 | |
---|
23 | # Stop any daemons that were specifically started inside the |
---|
24 | # chroot |
---|
25 | for daemon in $daemons; do |
---|
26 | invoke-rc.d $daemon restart || [ $? = 100 ] |
---|
27 | done |
---|
28 | |
---|
29 | # schroot has already attempted to kill everything inside the chroot, |
---|
30 | # fairly thoroughly. Our job here is to determine if anything is stuck |
---|
31 | # after a kill -9, and reboot. |
---|
32 | for i in /var/lib/schroot/mount/*; do |
---|
33 | if mountpoint -q "$i"; then |
---|
34 | touch /var/run/reboot-required |
---|
35 | echo "rebooting due to active mountpoint $i" |
---|
36 | print_processes_info |
---|
37 | break |
---|
38 | fi |
---|
39 | done |
---|
40 | if [ -n "$USER" -a "$USER" != root ]; then |
---|
41 | if pgrep -u "$USER"; then |
---|
42 | echo "rebooting due to live user processes" |
---|
43 | print_processes_info |
---|
44 | touch /var/run/reboot-required |
---|
45 | fi |
---|
46 | fi |
---|
47 | |
---|
48 | # Cleanup our ticketenv hack |
---|
49 | # Make sure nobody was evil |
---|
50 | chattr -f -i /tmp/ticketenv || : |
---|
51 | # If you made a directory and stored files there, too bad |
---|
52 | rm -rf /tmp/ticketenv |
---|
53 | |
---|
54 | # If either we or an updated package wanted to reboot, now is a |
---|
55 | # perfectly good time to do so -- auto-update is inhibited during a |
---|
56 | # login session. |
---|
57 | if [ -e /var/run/reboot-required ]; then |
---|
58 | echo "Reboot initiated at $(date)" |
---|
59 | reboot |
---|
60 | fi |
---|
61 | |
---|
62 | # Trac: #749 |
---|
63 | service ntp stop |
---|
64 | rdate time.mit.edu |
---|
65 | service ntp start |
---|
66 | |
---|
67 | |
---|
68 | # Yes, we want this here. A reboot will take care of cleaning up |
---|
69 | # /var/run anyway, and since dbus is essential to rebooting these |
---|
70 | # days, we don't want to risk things magically getting spawned inside |
---|
71 | # a crippled chroot |
---|
72 | rm /var/run/debathena-inhibit-dbus-helper |
---|