Differences

This shows you the differences between two versions of the page.

Link to this comparison view

tech:linux:start_stop_script [2015/03/11 06:46] (current)
Line 1: Line 1:
 +====== Script to start/stop jobs ======
 +Startup scripts samples.
 +
 +===== Start =====
 +THIS DOES NOT QUITE WORK!  The job starts but the pid is not the real pid!  So the stop is also bad because of this.
 +<code bash>
 +#!/bin/bash
 +RUN_FILE=/​var/​run/​somejob.pid
 +nohup some-job > /dev/null 2>&1 &
 +echo $! >> $RUN_FILE
 +exit
 +</​code>​
 +
 +===== Stop =====
 +THIS DOES NOT QUITE WORK!
 +<code bash>
 +#!/bin/bash
 +RUN_FILE=/​var/​run/​somejob.pid
 +for pids in `cat $RUN_FILE`;
 +do
 +  echo "​Killing:​ $pids"
 +  kill -9 $pids
 +done
 +</​code>​
 +
 +===== Restart =====
 +<code bash>
 +#!/bin/bash
 +/​path/​to/​stop-job.bash
 +#sleep 5
 +/​path/​to/​start-job.bash
 +</​code>​
 +
 +
 +====== Other scripts ======
 +===== Simple start =====
 +<code bash>
 +#!/bin/bash
 +HAPCOUNT=`pgrep haproxy|wc -l`
 +if [ $HAPCOUNT -eq 0 ]
 +then
 +  echo "​Starting haproxy ..."
 +  haproxy -f /​etc/​haproxy/​haproxy.cfg
 +else
 +  echo "​haproxy already running"​
 +fi
 +exit
 +</​code>​
 +
 +===== Simple stop =====
 +<code bash>
 +#!/bin/bash
 +HAPCOUNT=`pgrep haproxy|wc -l`
 +if [ $HAPCOUNT -eq 0 ]
 +then
 +  echo "​haproxy not running"​
 +  exit
 +fi
 +#
 +for pids in `pgrep haproxy`;
 +do
 +  echo "​Killing:​ $pids"
 +  kill -9 $pids
 +done
 +exit
 +</​code>​
  

QR Code
QR Code tech:linux:start_stop_script (generated for current page)