This repository has been archived by the owner on Aug 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
seafile
executable file
·128 lines (116 loc) · 2.89 KB
/
seafile
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#! /bin/bash
# SEAFILE
# Maintainer: @hadret
# App Version: 1.7.0
### BEGIN INIT INFO
# Provides: seafile
# Required-Start: $local_fs $remote_fs $network $syslog nginx mysql
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Seafile synchronization and collaboration
# Description: Seafile synchronization and collaboration
### END INIT INFO
APP_ROOT="/home/seafile/seafile/seafile-server-latest"
SEAFILE_PID="/home/seafile/seafile/pids/seaf-server.pid"
SEAHUB_PID="$APP_ROOT/runtime/seahub.pid"
STOP_SEAFILE="$APP_ROOT/seafile.sh stop"
START_SEAFILE="$APP_ROOT/seafile.sh start"
STOP_SEAHUB="$APP_ROOT/seahub.sh stop"
START_SEAHUB="$APP_ROOT/seahub.sh start-fastcgi"
NAME="seafile"
DESC="Seafile service"
check_pid(){
if [ -f $SEAFILE_PID ]; then
PID=`cat $SEAFILE_PID`
SPID=`cat $SEAHUB_PID`
STATUS=`ps aux | grep $PID | grep -v grep | wc -l`
else
STATUS=0
PID=0
fi
}
start() {
cd $APP_ROOT
check_pid
if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then
# Program is running, exit with error code 1.
echo "Error! $DESC $NAME is currently running!"
exit 1
else
if [ `whoami` = root ]; then
sudo -u seafile -H bash -l -c "$START_SEAFILE"
sudo -u seafile -H bash -l -c "$START_SEAHUB"
echo "$DESC started"
fi
fi
}
stop() {
cd $APP_ROOT
check_pid
if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then
## Program is running, stop it.
sudo -u seafile -H bash -l -c "$STOP_SEAHUB"
sleep 5
sudo -u seafile -H bash -l -c "$STOP_SEAFILE"
echo "$DESC stopped"
else
## Program is not running, exit with error.
echo "Error! $DESC not started!"
exit 1
fi
}
restart() {
cd $APP_ROOT
check_pid
if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then
echo "Restarting $DESC..."
sudo -u seafile -H bash -l -c "$STOP_SEAHUB"
sleep 5
sudo -u seafile -H bash -l -c "$STOP_SEAFILE"
if [ `whoami` = root ]; then
sudo -u seafile -H bash -l -c "$START_SEAFILE"
sudo -u seafile -H bash -l -c "$START_SEAHUB"
fi
echo "$DESC restarted."
else
echo "Error, $NAME not running!"
exit 1
fi
}
status() {
cd $APP_ROOT
check_pid
if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then
echo "$DESC / Seafile with PID $PID is running."
echo "$DESC / Seahub with PID $SPID is running."
else
echo "$DESC is not running."
exit 1
fi
}
## Check to see if we are running as root first.
## Found at http://www.cyberciti.biz/tips/shell-root-user-check-script.html
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root"
exit 1
fi
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo "Usage: sudo service seafile {start|stop|restart|status}" >&2
exit 1
;;
esac
exit 0