forked from dwiel/gphoto2-timelapse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rc.timelapse
executable file
·81 lines (70 loc) · 1.61 KB
/
rc.timelapse
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
#The user that will run
RUN_AS=pi
#Clean name of the script to execute
CLEAN_NAME=TIMELAPSE
#Name of the screen-session
NAME="$CLEAN_NAME"_AUTO_screen
#executable files in the following paths that are perhaps needed by the script
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin
#your path to the pogram directory
DIR=/home/pi/gphoto2-timelapse
#Description
DESC="${CLEAN_NAME}"
#Command
CMD="python timelapse.py >> timelapse.log 2>&1"
function run_as ()
{
if [[ "X${RUN_AS}" == "X${USER}" ]];then
eval "$*"
else
sudo su ${RUN_AS} -c "$*"
fi
}
case "$1" in
start)
if [[ $(run_as "screen -ls |grep $NAME") ]]
then
echo "$CLEAN_NAME is already running!"
else
echo "Starting $DESC: $NAME"
run_as "cd $DIR; screen -dmS $NAME $CMD"
fi
;;
stop)
if [[ $(run_as "screen -ls |grep $NAME") ]]
then
echo -n "Stopping $DESC: $NAME"
run_as "screen -XS $NAME quit"
echo " ... done."
else
echo "Coulnd't find a running $DESC"
fi
;;
restart)
if [[ $(run_as "screen -ls |grep $NAME") ]]
then
echo -n "Stopping $DESC: $NAME"
run_as "screen -XS ${NAME} quit"
echo " ... done."
else
echo "Coulnd't find a running $DESC"
fi
echo "Starting $DESC: $NAME"
run_as "cd $DIR; screen -dmS $NAME $CMD"
echo " ... done."
;;
status)
if [[ $(run_as "screen -ls |grep $NAME") ]]
then
echo "$CLEAN_NAME is RUNNING"
else
echo "$CLEAN_NAME is DOWN"
fi
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
exit 1
;;
esac
exit 0