updated on Sun Jan 15 04:04:02 UTC 2012
[aur-mirror.git] / kfs / kfs-metaserv.rc
blob6a8661fc0ee7231ecd9dee8e6e25357313f3de33
1 #!/bin/bash
3 . /etc/rc.conf
4 . /etc/rc.d/functions
5 . /etc/conf.d/kfs
7 CP_DIR=`cat $KFS_CONF 2>/dev/null | grep metaServer.cpDir | cut -d '=' -f 2 | sed 's/ //g'`
8 LOG_DIR=`cat $KFS_CONF 2>/dev/null | grep metaServer.logDir | cut -d '=' -f 2 | sed 's/ //g'`
10 case "$1" in
11 start)
12 stat_busy "Starting KFS MetaServer"
14 [ -z "$KFS_CONF" ] && { echo "KFS_CONF not set. You need to specify it in /etc/conf.d/kfs file"; stat_fail; exit 0; }
15 [ -z "$KFS_WEBUI_CONF" ] && { echo "KFS_WEBUI_CONF not set. You need to specify it in /etc/conf.d/kfs file"; stat_fail; exit 0; }
16 [ -z "$KFS_DIR" ] && { echo "KFS_DIR not set. You need to specify it in /etc/conf.d/kfs file"; stat_fail; exit 0; }
18 [ -f "$KFS_CONF" ] || { echo "$KFS_CONF doesn't exist"; stat_fail; exit 0; }
19 [ -f "$KFS_WEBUI_CONF" ] || { echo "$KFS_WEBUI_CONF doesn't exist"; stat_fail; exit 0; }
21 [ -d "$KFS_DIR" ] || mkdir -p "$KFS_DIR" || { echo "Could not create $KFS_DIR"; stat_fail; exit 0; }
23 [ -z "$CP_DIR" ] && { echo "$KFS_CONF doesn't have metaServer.cpDir set"; stat_fail; exit 0; }
24 [ -z "$LOG_DIR" ] && { echo "$KFS_CONF doesn't have metaServer.logDir set"; stat_fail; exit 0; }
26 cd "$KFS_DIR"
28 [ -d "$CP_DIR" ] || mkdir -p "$CP_DIR" || { echo "Could not create $CP_DIR directory"; stat_fail; exit 0; }
29 [ -d "$LOG_DIR" ] || mkdir -p "$LOG_DIR" || { echo "Could not create $LOG_DIR directory"; stat_fail; exit 0; }
31 [ -d "bin" ] || ln -s /usr/share/kfs/bin || { echo "Could not create link to /usr/share/kfs/bin in $KFS_DIR"; stat_fail; exit 0; }
32 [ -d "scripts" ] || ln -s /usr/share/kfs/scripts || { echo "Could not create link to /usr/share/kfs/scripts in $KFS_DIR"; stat_fail; exit 0; }
33 [ -d "logs" ] || mkdir -p "logs" || { echo "Could not create $KFS_DIR/logs"; stat_fail; exit 0; }
35 if [ ! -d "webui" ]; then
36 mkdir -p "webui" || { echo "Could not create webui directory in $KFS_DIR"; stat_fail; exit 0; }
37 ( cd webui && ln -s /usr/share/kfs/webui/kfsstatus.py ) || { echo "Could not create link to /usr/share/kfs/webui/kfsstatus.py in $KFS_DIR/webui"; stat_fail; exit 0; }
38 ( cd webui && ln -s /usr/share/kfs/webui/files ) || { echo "Could not create link to /usr/share/kfs/webui/files in $KFS_DIR/webui"; stat_fail; exit 0; }
39 ( cd webui && ln -s "$KFS_WEBUI_CONF" server.conf ) || { echo "Could not create link to $KFS_WEBUI_CONF in $KFS_DIR/webui"; stat_fail; exit 0; }
42 [ -d "$KFS_DIR/webui/files" ] || { echo "$KFS_DIR/webui/files doesn't exist or is not a directory"; stat_fail; exit 0; }
43 [ -e "$KFS_DIR/webui/kfsstatus.py" ] || { echo "$KFS_DIR/webui/kfsstatus.py exist"; stat_fail; exit 0; }
44 [ -e "$KFS_DIR/webui/server.conf" ] || { echo "$KFS_DIR/webui/server.conf doesn't exist"; stat_fail; exit 0; }
46 if [ -z "$BACKUP_NODE" ]; then
47 scripts/kfsrun.sh --start --meta --file "$KFS_CONF"
49 ret=$?
50 else
51 [ -z "$BACKUP_PATH" ] && BACKUP_PATH="."
53 # Needed? I'm not sure how backup_path works...
54 mkdir -p "$BACKUP_PATH" || { echo "Could not create $BACKUP_PATH directory"; stat_fail; exit 0; }
56 echo "Running with BACKUP_NODE=$BACKUP_NODE and BACKUP_PATH=$BACKUP_PATH"
58 scripts/kfsrun.sh --start --meta --file "$KFS_CONF" --backup_node "$BACKUP_NODE" --backup_path "$BACKUP_PATH"
60 ret=$?
63 if [ $ret -gt 0 ]; then
64 stat_fail
65 else
66 add_daemon kfs-metaserv
67 stat_done
70 stop)
71 stat_busy "Stopping KFS MetaServer"
73 cd "$KFS_DIR"
75 if [ -z "$BACKUP_NODE" ]; then
76 scripts/kfsrun.sh --stop --meta --file "$KFS_CONF"
78 ret=$?
79 else
80 [ -z "$BACKUP_PATH" ] && BACKUP_PATH="."
82 scripts/kfsrun.sh --stop --meta --file "$KFS_CONF" --backup_node "$BACKUP_NODE" --backup_path "$BACKUP_PATH"
84 ret=$?
87 if [ $ret -gt 0 ]; then
88 stat_fail
89 else
90 rm_daemon kfs-metaserv
91 stat_done
94 restart)
95 $0 stop
96 sleep 1
97 $0 start
100 echo "usage: $0 {start|stop|restart}"
101 esac
102 exit 0