summarylogtreecommitdiffstats
path: root/flexibee
blob: 5a12b7a2e31d74720eeb2258391cc6a052122b41 (plain)
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
129
130
131
132
133
134
#!/bin/bash
# Created by Max Devaine <maxdevaine@gmail.com>
# Last update : 7.7.2014

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/opt/java/jre/bin
FLEXIBEE_PID=/var/run/flexibee.pid
FLEXIBEE_USER="flexibee"
MYLANG=`echo $LANG | cut -c 1-2`
CONFIGFILE=/etc/flexibee/flexibee-server.xml
DEFAULTCONFIGFILE=/etc/default/flexibee

case "$1" in
	start)

### detect flexibee default configuration file		
if [ -f /etc/default/flexibee ]; then
   . /etc/default/flexibee
fi

### detect flexibee server mode (if is define)
if [ x"$DEFAULTCONFIGFILE" = x"client" ]; then

    if [ x"$MYLANG" = x"cs" ]; then
        echo "FlexiBee je vypnutý. Změňte hodnotu FLEXIBEE_CFG z 'client' na 'local' nebo 'server' v /etc/default/flexibee"
      else 
	echo "FlexiBee is disabled. Change FLEXIBEE_CFG from 'client' to 'local' or 'server' in /etc/default/flexibee"
    fi
    exit 0
fi


### detect postgresql server runing
if [ ! 'systemctl status postgresql' ]; then

    if [ x"$MYLANG" = x"cs" ]; then
        echo "Neběží postgresql databáze. Spusťte jí pomocí : systemctl start postgresql"
          else
	    echo "Postgresql database not running, run the database : systemctl start postgresql "
    fi
    exit 0
fi


### detect flexibee running
          if [ -e $FLEXIBEE_PID ]; then

            if [ x"$MYLANG" = x"cs" ]; then
             echo "Flexibee server je už spuštěn!"
             else
	       echo "Flexibee server is running!"
            fi
             exit 0
          fi

### run flexibee server
        /usr/sbin/flexibee-server

### detect running flexibee server
          if [ -e $FLEXIBEE_PID ]; then

            if [ x"$MYLANG" = x"cs" ]; then
               echo "Flexibee server byl úspěšně spuštěn."
             else
	       echo "Flexibee server successfully started"
            fi
            exit 0
          else
            if [ x"$MYLANG" = x"cs" ]; then
               echo "Chyba při spouštění flexibee serveru!"
             else
	       echo "Error when starting flexibee server!"
            fi

          fi
         

		;;
	stop)

          if [ ! -e $FLEXIBEE_PID ]; then

            if [ x"$MYLANG" = x"cs" ]; then
             echo "Chyba : Flexibee server není spuštěn."
             else
	       echo "Error : Flexibee server is not running"
            fi
             exit 0
          fi

          kill `cat $FLEXIBEE_PID`
          rm -f $FLEXIBEE_PID           

		;;
	restart)
		$0 stop
		sleep 2
		$0 start
		;;
	install)

           echo "---> 1) Create system user and group : flexibee"
           echo "     useradd --system --home-dir /tmp --no-create-home --user-group --shell /bin/false flexibee"
           useradd --system --home-dir /tmp --no-create-home --user-group --shell /bin/false flexibee

           echo "---> 2) Create database role with random secret password : "
           echo "     su - postgres -c CREATE ROLE dba PASSWORD '********' CREATEDB SUPERUSER CREATEROLE INHERIT LOGIN;"

           ### generate random password
           pass=`</dev/urandom tr -dc A-Za-z0-9| (head -c $1 > /dev/null 2>&1 || head -c 23)`

           ### create database role
           su - postgres -c "psql -c \"CREATE ROLE dba PASSWORD '$pass' CREATEDB SUPERUSER CREATEROLE INHERIT LOGIN;\""


           echo "---> 3) The database role password adding to flexibee configuration file $CONFIGFILE"
           echo "     cat $CONFIGFILE | sed '/password/s/7971/**********/g' > $CONFIGFILE.new"
           echo "     mv $CONFIGFILE.new $CONFIGFILE"
	   cat $CONFIGFILE | sed '/password/s/7971/'$pass'/g' > $CONFIGFILE.new
           mv $CONFIGFILE.new $CONFIGFILE
           pass=0

           echo "---> 4) Change file permission to flexibee configuration file"
           echo "     chmod 600 $CONFIGFILE"
           echo "     chown flexibee $CONFIGFILE"
           chmod 600 $CONFIGFILE
           chown flexibee $CONFIGFILE


		;;
	*)
		echo "usage: $0 {start|stop|restart|install}"
esac
exit 0