summarylogtreecommitdiffstats
path: root/quasar-server.install
blob: ff30042ef0d2a9f667b372bf59273e6bfdd0b6a7 (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


pre_install() {
  # Add the quasar group
  line=$(grep quasar /etc/group)
  if [ "$line" == "" ]; then
      groupadd quasar >/dev/null 2>/dev/null
  fi

  # Add the quasar user
  line=$(grep quasar /etc/passwd)
  if [ "$line" == "" ]; then
      useradd -g quasar -d /opt/quasar -s /bin/bash -c Quasar quasar 2>/dev/null
  fi
}


post_install() {
  # check if postgresql is configured
  # it configured the database as ASCII even though my local is set to UTF-8
  if [ ! "$(ls -A /var/lib/postgres/data)" ]; then
      su - postgres -c "initdb --locale en_US.UTF-8 -E UTF8 -D '/var/lib/postgres/data'"
  fi

  # If PostgreSQL is installed, try to start it
  [ $(systemctl is-enabled postgresql) = 'disabled' ] && systemctl enable postgresql
  [ $(systemctl is-active postgresql) = 'inactive' ] && systemctl start postgresql

  # Create a "quasar" user/role
  if [ -x /usr/bin/createuser ]; then
      su - postgres -c "/usr/bin/createuser -s quasar"
      if [ $? != 0 ]; then
	  su - postgres -c "/usr/bin/createuser -a -d quasar"
      fi
  fi

  # Generate the postgresql.cfg file
  if [ ! -e /opt/quasar/config/postgresql.cfg ]; then
  # Figure out library location
      if [ -e /usr/lib64/libpq.so ]; then
	  PQ_LIB=/usr/lib64/libpq.so
      elif [ -e /usr/lib/libpq.so ]; then
	  PQ_LIB=/usr/lib/libpq.so
      else
	  FILES=$(ls /usr/lib64/libpq.so* 2>/dev/null)
	  if [ $? = 0 ]; then
	      PQ_LIB=$(ls /usr/lib64/libpq.so* | head -1)
	  else
	      FILES=$(ls /usr/lib/libpq.so* 2>/dev/null)
	      if [ $? = 0 ]; then
		  PQ_LIB=$(ls /usr/lib/libpq.so* | head -1)
	      fi
	  fi
      fi

      # Write PostgreSQL config file
      echo -e "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE PostgresqlConfig>\n<PostgresqlConfig>\n <hostname></hostname>\n <port>5432</port>\n <library>$PQ_LIB</library>\n <dbaUsername>quasar</dbaUsername>\n <dbaPassword></dbaPassword>\n <username>quasar</username>\n <password></password>\n <charSet>UNICODE</charSet>\n</PostgresqlConfig>" >/opt/quasar/config/postgresql.cfg
      chmod 640 /opt/quasar/config/postgresql.cfg
  fi

  # Create log file directory
  if [ ! -e /var/log/quasar ]; then
      mkdir /var/log/quasar
  fi
  # Set ownership
  chown -R quasar:quasar /var/log/quasar
  chown -R quasar:quasar /opt/quasar

  # Create the xinetd.d entry
  if [ ! -e /etc/xinetd.d/quasard ]; then
      echo -e "service quasard\n{\n        type = UNLISTED\n        flags = KEEPALIVE NODELAY\n        socket_type = stream\n        port = 3599\n        wait = yes\n        user = quasar\n        group = quasar\n        instances = UNLIMITED\n        server = /opt/quasar/bin/quasard\n        server_args = -xinetd\n#       server_args = -xinetd -debug\n        disable = no\n}\n" >/etc/xinetd.d/quasard
  fi

  # check if xinetd is enabled
  if [ $(systemctl is-enabled xinetd) = 'disabled' ]; then
      systemctl enable xinetd
      systemctl start xinetd
  fi
  
  # Restart xinetd so it finds the new entries
  if [ $(systemctl is-active xinetd) = 'active' ]; then
      systemctl restart xinetd
  else
      echo "Error: missing /etc/init.d/xinetd script so xinetd is"
      echo "likely not installed.  You need to install xinetd to"
      echo "use Quasar"
  fi
}


pre_remove() {
  # Remove xinetd.d entries
  if [ -e /etc/xinetd.d/quasard ]; then
      rm /etc/xinetd.d/quasard
  fi

  # Restart xinetd so it forgets about quasar entries
  if [ $(systemctl is-active xinetd) = 'active' ]; then
      systemctl restart xinetd
  fi

  # Shut down quasard
  /usr/bin/killall -q quasard
}


post_remove() {
  # Delete the log files
  rm -rf /var/log/quasar
}