Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Kill processes and restart them
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Kill processes and restart them

SaikuSaiku Member, Host Rep

Could someone help me make a cron and bash script to kill a certain processes and restart the app when the server's RAM usage is above 80%?

Thanks!

Comments

  • agentmishraagentmishra Member, Host Rep

    there was a tread of this kind a few days back

  • SaikuSaiku Member, Host Rep

    @agentmishra said:
    there was a tread of this kind a few days back

    I remember there was that thread, unfortunately, I couldn't find it anymore (could be one of those thread that missing from LET)

  • mca295188mca295188 Member
    edited October 2013

    @Saiku

    yeah that thread was started by me....and now even me can not find it

    you want to check simple ram usage or swap usage also...

  • This will restart httpd process, when cpu spikes. You can customize this with kill all / kill command.

    !/bin/bash

    LOAD=cat /proc/loadavg|awk ' { print $1 } ' | sed -e "s/\.//" | sed -e "s/^0//g"

    if [ $LOAD -gt 2000 ]; then

    /sbin/service httpd restart

    fi

    Thanked by 1Saiku
  • Workarounds are not solutions to problems.

  • XSXXSX Member, Host Rep
    edited October 2013




    I remember such a shell http://wangyan.org/blog/sys-mon-shell-script.html

    But you need to understand some simple Chinese or translated.

    Thanked by 1Saiku
  • SaikuSaiku Member, Host Rep

    @Zen said:
    You can check my post out from the other thread.

    If only I could find your post :P (It's probably missing anyway, went through a few pages from your discussion/comments and it's really not there xD

  • @Saiku

    i think you forgot to check my reply...

  • SaikuSaiku Member, Host Rep

    @mca295188 said:
    Saiku

    i think you forgot to check my reply...

    oops. It's only ram usage. the VPS rarely use swap so I don't really care.

  • @Saiku

    execute this command

    free -m | grep "Mem" > /home/ram.txt

    and give me that ram.txt file...

  • SaikuSaiku Member, Host Rep

    @mca295188

    Mem: 996 887 109 0 16 209

    That is the output from ram.txt

  • @Saiku

    i can not count the place index from this file...i need that txt file as it is...

    or tell me you can count the index yourself or not...

  • wcypierrewcypierre Member
    edited October 2013

    For total memory

    free -m | grep "Mem" | awk '{print $2}'

    For memory in use

    free -m | grep "\-/+" | awk '{print $3}'

  • SaikuSaiku Member, Host Rep

    @mca295188 said:
    Saiku

    i can not count the place index from this file...i need that txt file as it is...

    or tell me you can count the index yourself or not...

    Never mind for now, I probably won't need it anymore. Thanks for the effort to help me tho!

    @Spirit you can close this thread now. Thanks.

  • Old thread is back: http://lowendtalk.com/discussion/13812/need-script-to-reboot-server-if-memory-usage-go-above-95

    @Saiku said:
    Spirit you can close this thread now. Thanks.

    Of course.

This discussion has been closed.