Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/system/bin/sh
- # Change Log
- # 3.1
- # Re-Added memory clear from 2.0
- # Added disabling and re-enabling of multi-cpus
- # 3.0
- # Leaving /system processes alone
- # 2.0 aka dynamic
- # Dynamically determining which services to stop
- # 1.0 Initial hard-coded service list
- echo $0
- ##### md5sum e24d678d9c18c7811e16f4755dfd1e19 /system/sbin/busybox-armv7l
- ### Make sure 'free' command is in the path, recommend /system/sbin/busybox-armv7l --install -s /system/sbin
- which free >/dev/null 2>&1
- if [[ $? -ne 0 ]]
- then
- echo "Unable to find 'which' and/or 'free' command, install busybox-armv7l
- # mount -o rw,remount /system
- # mkdir /system/sbin
- # download https://busybox.net/downloads/binaries/latest/busybox-armv7l to /system/sbin
- # chmod 777 /system/sbin/busybox-armv7l
- # /system/sbin/busybox-armv7l --install -s /system/sbin
- # rm -f /system/sbin/ps"
- exit 1
- fi
- ### Determine list of init rc scripts to reference when looking to pair a process name with a service name
- init_rc_list=`ls /init*rc | grep -v goldfish | tr '\n' ' '`
- service_restart_list=""
- abort=0
- ### Determine which services and processes need to be stopped for /extdata and /data to happily umount
- for blocking_pid in `fuser -m /extdata /data | sort | uniq`
- do
- ### Find the name and parent pid of the blocking pid
- comm=`cat /proc/${blocking_pid}/comm`
- ppid=`cat /proc/${blocking_pid}/stat | awk '{print $4}'`
- ### If the parent pid is another process, set the blocking pid to the parent, the children will stop when the parent stops
- if [[ $ppid -gt 1 ]]
- then
- #echo -n "PARENT ppid = [${ppid}] "
- blocking_pid=${ppid}
- comm=`cat /proc/${blocking_pid}/comm`
- fi
- ### Add service and process names to variables for us to work with later.
- if [[ "${comm}" == "sh" ]]
- then
- echo "There is an open shell using something in /extdata and/or /data... aborting."
- abort=1
- elif [[ "${comm}" == "zygote" ]]
- then
- ### Only add zygote to the list once
- if [[ "$zygote_stopped" == "" ]]
- then
- echo "Adding [zygote] to the list of services to stop"
- service_restart_list=" zygote ${service_restart_list} "
- zygote_stopped=yes
- fi
- elif [[ "${comm}" == "keystore" ]]
- then
- echo "Ignoring keystore, it will be handled by pioneer /sbin/andsnap"
- elif [[ "${comm}" != "" ]]
- then
- echo -n "blocking_pid = [${blocking_pid}] comm = [${comm}] "
- service_name=`grep "^service.*\/${comm}" ${init_rc_list} | awk '{print $2}'`
- if [[ "${service_name}" != "" ]]
- then
- echo "${service_restart_list}" | grep -q " ${service_name} "
- if [[ $? -eq 0 ]]
- then
- echo "Service [${service_name}] has already been dealt with"
- else
- echo "Adding [${service_name}] to the list of services to stop"
- service_restart_list=" ${service_name} ${service_restart_list} "
- fi
- else
- echo "No match for service, killing [${service_name}]"
- killall_list=" ${killall_list} ${comm} "
- fi
- fi
- done
- echo "service_restart_list = [${service_restart_list}]"
- [ $abort -ne 0 ] && exit 1
- echo "No changes have been made yet, Ctrl-C to abort within 10 seconds"
- for i in `seq 1 10`
- do
- echo -n '.'
- sleep 1
- done
- echo "Continuing on..."
- echo "Stopping Services"
- for service in ${service_restart_list}
- do
- echo "Stopping ${service}"
- stop ${service}
- done
- echo "Done Stopping Services"
- for rogue_process in ${killall_list}
- do
- echo "Killing Rogue Process: [${rogue_process}]"
- killall ${rogue_process}
- done
- multi_cpus=`find /sys/devices/system/cpu/cpu[1-9] -name online 2>/dev/null`
- if [[ "${multi_cpus}" == "" ]]
- then
- echo "Single CPU, continuing..."
- else
- for cpu_online in ${multi_cpus}
- do
- echo "Disabling [${cpu_online}]"
- echo 0 > ${cpu_online}
- done
- fi
- echo "Sleeping for 10 seconds to let system end processes"
- sleep 10
- echo "Zero out the memory for a small clean snapshot"
- head -n2 /proc/meminfo
- sync && echo 3 > /proc/sys/vm/drop_caches && echo ""
- memfree=$(free -m | awk '/^Mem/ {print $4-32}')
- echo "memfree=[${memfree}]"
- if [ $memfree -gt 0 ]; then
- dd if=/dev/zero of=/dev/null bs=${memfree}M count=1
- fi
- head -n2 /proc/meminfo
- sync
- sleep 10
- sync
- /sbin/andsnap $*
- if [[ "${multi_cpus}" == "" ]]
- then
- echo "Single CPU, continuing..."
- else
- for cpu_online in ${multi_cpus}
- do
- echo "Re-enabling [${cpu_online}]"
- echo 1 > ${cpu_online}
- done
- fi
- echo "Re-Starting Services"
- for service in ${service_restart_list}
- do
- echo "Starting ${service}"
- start ${service}
- done
- echo "Done!"
Advertisement
Add Comment
Please, Sign In to add comment