-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsingle-exec.sh
More file actions
53 lines (48 loc) · 1.15 KB
/
single-exec.sh
File metadata and controls
53 lines (48 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
############################################
########### SETUP VARIABLES ################
############################################
for last; do true; done
TASK_NAME=`echo $last|sed -e "s/\//_/g"`
PIDFILE_PATH=$1
PIDFILE=$PIDFILE_PATH'/'$TASK_NAME'.pid'
############################################
############ LOCKING LOGIC #################
############################################
if [ ! -d $PIDFILE_PATH ]; then
mkdir data/tmp
fi
if [ -f $PIDFILE ]
then
PID=$(cat $PIDFILE)
ps -p $PID > /dev/null 2>&1
if [ $? -eq 0 ]
then
echo "Process already running"
exit 1
else
## Process not found assume not running
echo $$ > $PIDFILE
if [ $? -ne 0 ]
then
echo "Could not create PID file"
exit 1
fi
fi
else
echo $$ > $PIDFILE
if [ $? -ne 0 ]
then
echo "Could not create PID file"
exit 1
fi
fi
############################################
############ EXECUTING TASK ################
############################################
shift
$@
############################################
########### Removing PIDFILE ###############
############################################
rm $PIDFILE