updated on Wed Jan 11 00:07:16 UTC 2012
[aur-mirror.git] / ioreniced / ioreniced.sh
blobee410b6a1faa9d1955f8a89b9669d0baa4b21b31
1 #!/bin/bash
3 # ioReniceD 0.1.4
5 # GPL - jan.mette@berlin.de
9 #############################################################################
10 # SETUP
11 #############################################################################
13 # load config
14 source /etc/conf.d/ioreniced
16 # initialize pidlist for garbage collection
17 if [ "${BEHAVIOR}" = "smart" ]
18 then
19 IONICED_LIST=""
22 # delete old logs
23 rm -rf ${LOG_FILE} &>/dev/null
25 # set traps
26 trap 'echo "source /etc/conf.d/ioreniced' 1
27 trap 'rm -f /var/run/ioreniced.run; exit' 0
28 trap 'rm -f /var/run/ioreniced.run; exit' 3
29 trap 'rm -f /var/run/ioreniced.pid; exit' 15
32 #############################################################################
33 # MAIN LOOP
34 #############################################################################
36 while :
38 # update date var
39 DATE=`date '+%b%e %H:%M:%S'`
41 if [ "${BEHAVIOR}" = "smart" ]
42 then
44 # create logfile if it doesnt exist
45 if [ "${ENABLE_LOGGING}" = "yes" ]
46 then
47 if [ ! -e "${LOG_FILE}" ]
48 then
49 touch ${LOG_FILE}
50 echo " ">>${LOG_FILE}
51 echo "-------------------------------------">>${LOG_FILE}
52 echo " ioReniceD Logfile ">>${LOG_FILE}
53 echo "-------------------------------------">>${LOG_FILE}
54 echo " ">>${LOG_FILE}
58 # garbage collection
59 if [ "${ENABLE_LOGGING}" = "yes" ]
60 then
61 echo "${DATE} >>>> Running Garbage Collector">>${LOG_FILE}
64 for pid2 in ${IONICED_LIST}
66 check_running=`ps -A | grep ${pid2}`
68 if [ -z "$check_running" ]
69 then
70 if [ "${ENABLE_LOGGING}" = "yes" ]
71 then
72 echo "${DATE} >> PID ${pid2} not running anymore, removing from process list">>${LOG_FILE}
75 IONICED_LIST=`echo ${IONICED_LIST} | sed "s/${pid2}//g"`
77 if [ "${ENABLE_LOGGING}" = "yes" ]
78 then
79 echo "${DATE} >> PID LIST: ${IONICED_LIST}">>${LOG_FILE}
82 done
84 # walk through the list of processes we want to ionice
85 if [ "${ENABLE_LOGGING}" = "yes" ]
86 then
87 echo "${DATE} >>>> Ionicing Processes">>${LOG_FILE}
90 for item in `echo ${IONICE_ME[*]}`
91 do
92 # filter process list and remove stuff we dont want to ionice. just to be sure we dont hit anything cruicial ;) needs to be simplified
93 for pid in `ps -A | grep "${item}" | grep -e "acpi" -e "work_on_cpu" -e "startkde" -v | sed "s/[^ 0-9].*//g"`
94 do
95 # check if we already have ionized this process
96 PID_TMP=`echo ${IONICED_LIST} | grep -e "${pid}"`
98 if [ -z "${PID_TMP}" ]
99 then
100 if [ "${ENABLE_LOGGING}" = "yes" ]
101 then
102 echo "${DATE} >> ionicing new process ${item} (PID ${pid}) with PRIO ${IONICE_PRIO}">>${LOG_FILE}
105 /usr/bin/ionice -c${IONICE_PRIO} -p${pid} &>/dev/null
107 IONICED_LIST="${IONICED_LIST} ${pid}"
108 else
109 if [ "${ENABLE_LOGGING}" = "yes" ]
110 then
111 echo "${DATE} >> process ${item} (PID ${pid}) already ioniced with PRIO ${IONICE_PRIO}, skipping">>${LOG_FILE}
114 done
115 done
117 # delete logfile it if its size is over 1mib
118 if [ -e "${LOG_FILE}" ]
119 then
120 LOGSIZE=$(stat -c%s "${LOG_FILE}")
122 if [ "${LOGSIZE}" -gt 1048576 ]
123 then
124 rm -rf ${LOG_FILE}
128 # marker
129 if [ "${ENABLE_LOGGING}" = "yes" ]
130 then
131 echo "${DATE} >>>> ---------------------------------MARK">>${LOG_FILE}
135 if [ "${BEHAVIOR}" = "brute" ]
136 then
137 # create logfile if it doesnt exist
138 if [ "${ENABLE_LOGGING}" = "yes" ]
139 then
140 if [ ! -e "${LOG_FILE}" ]
141 then
142 touch ${LOG_FILE}
143 echo " ">>${LOG_FILE}
144 echo "-------------------------------------">>${LOG_FILE}
145 echo " ioReniceD Logfile ">>${LOG_FILE}
146 echo "-------------------------------------">>${LOG_FILE}
147 echo " ">>${LOG_FILE}
151 # walk through the list of processes we want to ionice
152 if [ "${ENABLE_LOGGING}" = "yes" ]
153 then
154 echo "${DATE} >>>> Ionicing Processes">>${LOG_FILE}
157 for item in `echo ${IONICE_ME[*]}`
159 # filter process list and remove stuff we dont want to ionice. just to be sure we dont hit anything cruicial ;) needs to be simplified
160 for pid in `ps -A | grep "${item}" | grep -e "acpi" -e "work_on_cpu" -e "startkde" -v | sed "s/[^ 0-9].*//g"`
162 if [ "${ENABLE_LOGGING}" = "yes" ]
163 then
164 echo "${DATE} >> ionicing process ${item} (PID ${pid}) with PRIO ${IONICE_PRIO}">>${LOG_FILE}
166 /usr/bin/ionice -c${IONICE_PRIO} -p${pid} &>/dev/null
167 done
168 done
170 # delete logfile it if its size is over 1mib
171 if [ -e "${LOG_FILE}" ]
172 then
173 LOGSIZE=$(stat -c%s "${LOG_FILE}")
175 if [ "${LOGSIZE}" -gt 1048576 ]
176 then
177 rm -rf ${LOG_FILE}
181 # marker
182 if [ "${ENABLE_LOGGING}" = "yes" ]
183 then
184 echo "${DATE} >>>> ---------------------------------MARK">>${LOG_FILE}
188 # polling interval
189 sleep ${POLLING_INTERVAL}
190 done