-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.sh
58 lines (49 loc) · 1.82 KB
/
service.sh
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
#!/bin/bash
SERVICE_NAME=robinye.github.io
APP_HOME=/opt/app/blog/$SERVICE_NAME
LOG_HOME=/opt/logs/blog/$SERVICE_NAME
safemkdir(){
if [ ! -d $1 ] ; then
mkdir -p $1
fi
}
PID_FILE=$APP_HOME/pid/$APP_NAME.pid
dateFormat=$(date '+%Y-%m-%d')
ACCESS_LOG=${LOG_HOME}/${dateFormat}/${SERVICE_NAME}.log
safemkdir $APP_HOME/pid/
safemkdir $LOG_HOME/$dateFormat
started="#################################################################\n
$SERVICE_NAME Started At $(date) \n
#################################################################\n"
stoped="#################################################################\n
$SERVICE_NAME Stopped At $(date) \n
###################################################################\n"
if [ "$1" == "start" ]; then
if [ ! -f "$PID_FILE" ]; then
export JEKYLL_ENV=production
echo -e $started | tee -a $LOG_HOME/$dateFormat/$SERVICE_NAME.log
bundle exec jekyll serve 1>> ${ACCESS_LOG} 2>> ${ACCESS_LOG} 2>&1 &echo $! > ${PID_FILE}
sleep 3
tail -n 500 $LOG_HOME/$dateFormat/$SERVICE_NAME.log
else
echo "$SERVICE_NAME service already started, please stop first and try again"
fi
elif [ "$1" == "stop" ]; then
if [ -f "$PID_FILE" ]; then
echo -e $stoped | tee -a $LOG_HOME/$dateFormat/$SERVICE_NAME.log
cat $PID_FILE | xargs sudo kill -9
rm $PID_FILE
echo "$SERVICE_NAME stop : [OK]"
else
echo "$SERVICE_NAME service not started yet, please start first and try again"
fi
elif [ "$1" == "log" ]
then if [ "$2" == "error" ]
then
tail -f $LOG_HOME/$dateFormat/$SERVICE_NAME-error.log
else
tail -f $LOG_HOME/$dateFormat/$SERVICE_NAME.log
fi
else
echo "Usage: start|stop|log/error"
fi