summarylogtreecommitdiffstats
path: root/orientdb-community.install
blob: 1a8913842f86e29ea4b7e216b44d93f87cc016bb (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
#
# Install scriptlet for OrientDB
#

post_install()
{
  groupadd -r orientdb && echo Group orientdb added

  #A home dir is needed as virtualbox writes to dir if su is used.
  useradd -r -g orientdb -m -d /home/orientdb -c "OrientDB Graph-Document NoSQL - Community Edition" orientdb && echo User orientdb added

  chown -R orientdb.orientdb /opt/orientdb
  chown -R orientdb.orientdb /var/log/orientdb

  ln -sf /opt/orientdb/log /var/log/orientdb
  ln -sf /opt/orientdb/config /etc/orientdb
  ln -sf /opt/orientdb/bin/console.sh /usr/bin/orientdb-console

  echo "==> OrientDB has been installed."
  echo "==> This install is compatible with systemd and orientdb.service is available."
  echo "==> OrientDB server should be launched from user 'orientdb' or by systemctl start orientdb."
  echo "==> When started for the first time, a non-encrypted root password will be generated"
  echo "    automatically and it can be found in /opt/orientdb/config/orientdb-server-config.xml"
  echo "==> The Studio Console can be accessed by browsing localhost:2480"

  systemctl daemon-reload
}

post_upgrade()
{
  #In case the Group and User are not present after re-installing or an upgrade.
  groupadd -r orientdb && echo Group orientdb added

  #A homedir is needed as virtualbox writes to dir if su is used.
  useradd -r -g orientdb -m -d /home/orientdb -c "OrientDB Graph-Document NoSQL - Community Edition" orientdb && echo User orientdb added

  # Remove extra groups and always force User orientdb to have a primary group of orientdb
  if [ $(groups orientdb | wc -w) -gt 1 ]; then
	  usermod -G "" orientdb
      echo "Removed extra groups for User orientdb"
  fi
  usermod -g orientdb orientdb

  chown -R orientdb.orientdb /opt/orientdb
  chown -R orientdb.orientdb /var/log/orientdb

  systemctl daemon-reload
}

pre_remove()
{
  # Cannot use echo -n in this context as stdout is not flushed
  # Server may have been started manually, so systemctl will not stop it
  # Grep only the Server entry, as an orientdb User session may be present
  if [ "$( ps aux | grep -e ^orient | grep com.orientechnologies.orient )" != "" ]; then
    echo "==> OrientDB server is running. Stopping OrientDB. Please wait 60 seconds before using Cntl-C."
    echo "==> Trying systemctl ..........."
    systemctl daemon-reload
    systemctl stop orientdb.service
	sleep 5
	echo "==> Testing if systemctl has stopped Server."
	if [ "$( ps aux | grep -e ^orient | grep com.orientechnologies.orient )" != "" ]; then
	  echo "==> systemctl did not stop Server. Trying directly. Please wait 60 seconds before using Cntl-C."
	else
	  echo "==> systemctl succeeded. Proceeding to remove."
	fi
  fi

    counter1=0
    counter2=0
    while [ "$( ps aux | grep -e ^orient | grep com.orientechnologies.orient )" != "" ]; do

      sleep 1

      counter1=`expr $counter1 + 1`
      counter2=`expr $counter2 + 1`

      if [ $counter1 -le 9 ]
      then
        echo -n "."
      else
        echo "."
        counter1=0
      fi

      if [ $counter2 = 20 ]
      then
        echo ""
        echo "==> Shutting down OrientDB directly."
        #It is correct to use shutdown.sh here as systemd is not involved.
        su -c "/opt/orientdb/bin/shutdown.sh >/dev/null 2>/dev/null" - orientdb
		echo "    Server has been sent shutdown. Please wait for script to end."
      fi

      if [ $counter2 -gt 39 ]
      then
        echo "Server has not stopped. Please resolve manually."
        break
      fi

    done

  echo ""
  rm -rf /etc/orientdb /usr/bin/orientdb-console /usr/lib/systemd/system/orientdb.service /opt/orientdb/log || /bin/true
}

post_remove()
{
  userdel -r orientdb && echo "User orientdb removed"
  groupdel orientdb && echo "Group orientdb removed"

  if [ -d /opt/orientdb ]; then
    echo ""
    echo "==> OrientDB directory is not empty and will not be removed."
    echo "    Backup database?"
    echo "    Please check path '/opt/orientdb' and remove directory manually."
  fi

  if [ -d /var/log/orientdb ]; then
    rm -rf /var/log/orientdb
  fi

  systemctl daemon-reload
}