{"id":876,"date":"2012-07-04T10:47:10","date_gmt":"2012-07-04T02:47:10","guid":{"rendered":"http:\/\/www.computersolutions.cn\/blog\/?p=876"},"modified":"2012-07-04T11:02:50","modified_gmt":"2012-07-04T03:02:50","slug":"sysfence-updates-for-debian-startup-script-and-makefile-fix","status":"publish","type":"post","link":"https:\/\/www.computersolutions.cn\/blog\/2012\/07\/sysfence-updates-for-debian-startup-script-and-makefile-fix\/","title":{"rendered":"sysfence updates for debian (startup script, and makefile fix)"},"content":{"rendered":"<p>A while ago I wrote a post about sysfence.  <a href=\"http:\/\/www.computersolutions.cn\/blog\/2010\/12\/debian-system-load-monitoring\/\">http:\/\/www.computersolutions.cn\/blog\/2010\/12\/debian-system-load-monitoring\/<\/a> <\/p>\n<p>As it really was a while ago, I&#8217;ll recap quickly.<\/p>\n<p>Sysfence is a small, light system monitoring app that has a nice heavy hand.  If load goes over user defined limits, it will kill processes specified in its config (with extreme prejudice), and only start them up again once load is back under a certain level.<\/p>\n<p>Got that?<\/p>\n<p>Ok.<\/p>\n<p>sysfence is rather good at what it does, fits my needs, so I&#8217;ve continued to use it over the years.  One of the things I never got around to doing was making a startup script for it &#8211; this is mostly as it works as advertised &#8211; i&#8217;ve had zero issues!<\/p>\n<p>That said, someone finally called my bluff and asked me for my startup script, which of course, I didn&#8217;t have, so I made one this morning.<\/p>\n<p>The script is debian biased, and depends on where you installed sysfence.<\/p>\n<p>You&#8217;ll need 3 files as below.  Change settings to your needs.<\/p>\n<p>1)  Basic settings for sysfence<\/p>\n<p>\/etc\/default\/sysfence<\/p>\n<p><code><br \/>\nSYSFENCE_ENABLE=true                       #Are we enabled (er, yes!)<br \/>\nDAEMON_OPTS=\" \/etc\/sysfence\/sysfence.conf\" #Where is our ruleset<br \/>\nMAILTO=\"root\"                              #Who to call in case of issues.<br \/>\n<\/code><\/p>\n<p>2) Config file for sysfence<\/p>\n<p>\/etc\/sysfence\/sysfence.conf<\/p>\n<p><code><br \/>\n#[Your sysfence watch rules goes here]<br \/>\n#My example below<\/p>\n<p>rule \"Apache\" {<br \/>\n   la1 >= 6.00 or la5 >= 3.5<br \/>\n}<br \/>\nrun '\/usr\/sbin\/apache2ctl stop; sleep 120; \/usr\/sbin\/apache2ctl start'<br \/>\nrule \"warning\" { la1 >= 6.00 } run once 'echo \"Load High: $HOSTNAME\"  | mail $MAILTO'<br \/>\n<\/code><\/p>\n<p>3) Debian Startup script<\/p>\n<p><code><br \/>\n#!\/bin\/sh<br \/>\n### BEGIN INIT INFO<br \/>\n# Provides:             sysfence<br \/>\n# Required-Start:       $local_fs $remote_fs<br \/>\n# Required-Stop:        $local_fs $remote_fs<br \/>\n# Should-Start:         $network<br \/>\n# Should-Stop:          $network<br \/>\n# Default-Start:        2 3 4 5<br \/>\n# Default-Stop:         0 1 6<br \/>\n# Short-Description:    Daemonized version of sysfence<br \/>\n# Description:          Starts the sysfence daemon<br \/>\n#                       \/etc\/default\/sysfence.<br \/>\n### END INIT INFO<br \/>\n# Author: L. Sheed<\/p>\n<p>#The complete default command that is being run is:<br \/>\n#sysfence \" \/etc\/sysfence\/sysfence.conf\"<br \/>\n#obviously this will change with your variables,<br \/>\n#but the entire command is here for testing<br \/>\n# uses \/etc\/default\/sysfence<\/p>\n<p>NAME=\"sysfence\"<br \/>\nSYSFENCE_ENABLE=false<br \/>\nDESC=\"sysfence Daemon\"<\/p>\n<p>DAEMON=`which sysfence`<br \/>\nDAEMON1=\"sffetch\"<br \/>\nDAEMON2=\"sfwatch\"<br \/>\nLOGFILE=\"\/var\/log\/sysfence.log\"<\/p>\n<p>test -x $DAEMON || exit 0<\/p>\n<p>if [ ! -e \"${LOGFILE}\" ]<br \/>\nthen<br \/>\n        touch \"${LOGFILE}\"<br \/>\n        chmod 640 \"${LOGFILE}\"<br \/>\n        chown root:adm \"${LOGFILE}\"<br \/>\nfi<\/p>\n<p>. \/lib\/lsb\/init-functions<\/p>\n<p>if [ -f \/etc\/default\/$NAME ]; then<br \/>\n    . \/etc\/default\/$NAME<br \/>\n    case \"x$SYSFENCE_ENABLE\" in<br \/>\n        xtrue|x1|xyes)<br \/>\n            SYSFENCE_ENABLE=true<br \/>\n            ;;<br \/>\n        *)<br \/>\n            SYSFENCE_ENABLE=false<br \/>\n            exit 1;<br \/>\n            ;;<br \/>\n    esac<br \/>\nfi<\/p>\n<p>case \"$1\" in<br \/>\n    start)<br \/>\n        PID=`ps aux | grep \"$DAEMON1 \" | grep -v grep | awk '{print $2}'`<br \/>\n        if [ \"x$PID\" != \"x\" ]; then<br \/>\n                echo `date` \" * $NAME appears to be already running!\" | tee -a $LOGFILE<br \/>\n                exit<br \/>\n        fi<br \/>\n        if $SYSFENCE_ENABLE; then<br \/>\n           echo \"Starting $DESC\"<br \/>\n           log_daemon_msg \"Starting $DESC\" \"$NAME\"<br \/>\n           $DAEMON $DAEMON_OPTS<\/p>\n<p>           PID=`ps aux | grep \"$DAEMON1 \" | grep -v grep | awk '{print $2}'`<br \/>\n           echo \" * $NAME PID is $PID\"<br \/>\n           echo \"Watching:\"<br \/>\n           ps -ef | grep \"$DAEMON2 \" | grep \"$PID\"<br \/>\n        else<br \/>\n            log_warning_msg \"Not starting $DESC $NAME, disabled via \/etc\/default\/$NAME\"<br \/>\n        fi<br \/>\n        ;;<\/p>\n<p>    stop)<br \/>\n        if $SYSFENCE_ENABLE; then<br \/>\n            PID=`ps aux | grep \"$DAEMON1 \" | grep -v grep | awk '{print $2}'`<br \/>\n            if [ \"x$PID\" = \"x\" ]; then<br \/>\n                echo \" * $NAME is not running\"<br \/>\n            else<br \/>\n                echo \" Stopping $NAME\"<br \/>\n                log_daemon_msg \"Stopping $DESC\" \"$NAME\"<br \/>\n                kill $PID<br \/>\n            fi<br \/>\n        fi<br \/>\n        ;;<\/p>\n<p>   status)<br \/>\n        PID=`ps aux | grep \"$DAEMON1 \" | grep -v grep | awk '{print $2}'`<br \/>\n        if [ \"x$PID\" = \"x\" ]; then<br \/>\n                echo \" * $NAME is not running\"<br \/>\n        else<br \/>\n                echo \" * $NAME PID is $PID\"<br \/>\n                echo \"Watching:\"<br \/>\n                ps -ef | grep \"$DAEMON2 \" | grep \"$PID\"<br \/>\n        fi<br \/>\n        ;;<\/p>\n<p>    *)<br \/>\n        N=\/etc\/init.d\/$NAME<br \/>\n        echo \"Usage: $N {start|stop|status}\" >&2<br \/>\n        exit 1<br \/>\n        ;;<br \/>\nesac<\/p>\n<p>exit 0; <\/p>\n<p><\/code><\/p>\n<p>You can download the init script here &#8211; <a href='http:\/\/www.computersolutions.cn\/blog\/wp-content\/uploads\/2012\/07\/sysfence.init_.txt'>sysfence init script for debian<\/a><\/p>\n<p>Yikes, I almost forgot the other bit of this post.  Tsk tsk&#8230;<\/p>\n<p>The makefile doesn&#8217;t make in some of my servers.  Its probably that dash shell expansion breaks stuff vs bash, but haven&#8217;t investigated it properly.<\/p>\n<p>This is a simple fix <\/p>\n<p>open up the makefile and change the expansion stuff to explicitly list the .o files.<\/p>\n<p>eg<\/p>\n<p>Makefile says:<\/p>\n<p><code>CC=gcc<br \/>\nLDFLAGS=<br \/>\nCFLAGS=-Wall -O2<br \/>\nobjects=conditions.o getstats.o mainloop.o cp2memory.o datastruct.o sysfence.o<br \/>\nparseopt=parseopt\/{confread,lex,parse}.o<br \/>\nsys=sys\/{exit,xalloc,log,communication,sighandlers,processtitle,users}.o<br \/>\n... (rest of the file)<br \/>\n<\/code><\/p>\n<p>Change to:<\/p>\n<p><code><br \/>\nCC=gcc<br \/>\nLDFLAGS=<br \/>\nCFLAGS=-Wall -O2<br \/>\nobjects=conditions.o getstats.o mainloop.o cp2memory.o datastruct.o sysfence.o<br \/>\nparseopt=parseopt\/confread.o parseopt\/lex.o parseopt\/parse.o<br \/>\nsys=sys\/exit.o sys\/xalloc.o sys\/log.o  sys\/communication.o sys\/sighandlers.o  sys\/processtitle.o  sys\/users.o<br \/>\n... (rest of the file)<br \/>\n<\/code><\/p>\n<p>make clean<\/p>\n<p>and<\/p>\n<p>make<\/p>\n<p>Simple!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A while ago I wrote a post about sysfence. http:\/\/www.computersolutions.cn\/blog\/2010\/12\/debian-system-load-monitoring\/ As it really was a while ago, I&#8217;ll recap quickly. Sysfence is a small, light system monitoring app that has a nice heavy hand. If load goes over user defined limits, it will kill processes specified in its config (with extreme prejudice), and only start [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[4],"tags":[421,258,423,422,303],"class_list":["post-876","post","type-post","status-publish","format-standard","hentry","category-useful-info","tag-bash","tag-debian","tag-script","tag-startup","tag-sysfence"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts\/876","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/comments?post=876"}],"version-history":[{"count":5,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts\/876\/revisions"}],"predecessor-version":[{"id":880,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts\/876\/revisions\/880"}],"wp:attachment":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/media?parent=876"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/categories?post=876"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/tags?post=876"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}