install-osrf.sh: avoid log spew on cstore max_children
[sitka/sitka-tools.git] / deployment / install-osrf.sh
CommitLineData
0155bbac 1#!/bin/bash
8da49eaf 2DEFAULT_USER="opensrf"
0155bbac 3HOMEDIR="/home/${DEFAULT_USER}"
0f2c1897
JD
4BUILDDIR="${HOMEDIR}/opensrf"
5INSTALLDIR="/srv/openils"
3d3f50ea
JD
6#BRANCH="rel_3_2"
7BRANCH="user/berick/lpxxx-c-backlog-speedbump"
79b2efa0 8HOSTNAME="nonprod"
0155bbac 9SITKACONF="${HOMEDIR}/sysadmin"
98a9b7e7 10SITKACONF_BRANCH="eg35"
ea139441
JD
11
12WEBSOCKETD_VERSION="0.3.0"
13WEBSOCKETD_ZIP="websocketd-${WEBSOCKETD_VERSION}-linux_amd64.zip"
14WEBSOCKETD_URL="https://github.com/joewalnes/websocketd/releases/download/v${WEBSOCKETD_VERSION}/${WEBSOCKETD_ZIP}"
0155bbac 15
a826c73b 16THISHOST=`hostname -s`
35e67cbd 17TIMESTAMP=`date +%Y%m%d%H%M`
a826c73b 18
9f4f2f95 19while getopts ":pWj" opt ; do
e3bcc9bb
JD
20 case $opt in
21 p ) PROD="prod";;
9f4f2f95 22 W ) SKIP_WEBSOCKETS="websockets";;
913bfe44 23 j ) SKIP_EJABBERD_REG="skip_ejabberd_reg";;
e3bcc9bb
JD
24 esac
25done
26shift $(($OPTIND - 1))
27
913bfe44 28# test for ejabberd passwords
29if [ -z "$PRIVATE_ROUTER_PASSWD" -o -z "$PRIVATE_OPENSRF_PASSWD" -o -z "$PUBLIC_ROUTER_PASSWD" -o -z "$PUBLIC_OPENSRF_PASSWD" ]
30then
31 if [[ ! -n "$SKIP_EJABBERD_REG" ]] ; then
32 echo "Missing ejabberd password(s), no OpenSRF install!"
33 exit
34 fi
35fi
36
7b2b5e72 37# always use a proxy for websockets traffic
9f4f2f95 38if [[ ! -n "$SKIP_WEBSOCKETS" ]] ; then
7b2b5e72 39 WSPORT="--with-websockets-port=443"
1b2dcee5
JD
40 # load-balanced installs require mod_rpaf - see LP#1684970
41 apt-get install libapache2-mod-rpaf
7b2b5e72
JD
42else
43 WSPORT=""
44fi
45
e3bcc9bb
JD
46if [[ -n "$PROD" ]] ; then
47 echo 'this is a production install'
34f86bbc 48 [ "$HOSTNAME" == "nonprod" ] && HOSTNAME="prod"
e3bcc9bb
JD
49else
50 echo 'this is NOT a production install'
51fi
0155bbac
JD
52# as root
53usermod -a -G sudo ${DEFAULT_USER}
157b7812 54apt-get install git-core build-essential bsdmainutils unzip
0155bbac
JD
55
56# as DEFAULT_USER
57if [ ! -d "${SITKACONF}" ]
58then
59 # this will fail unless DEFAULT_USER has read access to the repo
e2ad4781 60 su -c "cd ${HOMEDIR} && git clone git+ssh://git@git.sitka.bclibraries.ca/sitka-infra/sysadmin" ${DEFAULT_USER}
0155bbac 61fi
e2ad4781 62su -c "cd ${HOMEDIR}/sysadmin && git fetch origin && git checkout ${SITKACONF_BRANCH} && git pull" ${DEFAULT_USER}
0f2c1897 63if [ ! -d "${BUILDDIR}/.git" ] ; then
ea139441 64 su -c "cd ${HOMEDIR} && git clone git://git.evergreen-ils.org/working/OpenSRF.git opensrf" ${DEFAULT_USER}
e724d7db 65fi
e2ad4781 66su -c "cd ${BUILDDIR} && git fetch origin && git checkout ${BRANCH} && git pull" ${DEFAULT_USER}
0155bbac
JD
67
68# as root
15e3aada
JD
69echo "need a placeholder apache2.conf, installing from config repo..."
70if [ -f '/etc/apache2/apache2.conf' ]
71then
72 mv /etc/apache2/apache2.conf /etc/apache2/apache2.conf.bak
73fi
74cp ${SITKACONF}/files/etc/apache2/apache2.conf/${HOSTNAME} /etc/apache2/apache2.conf
e6bc584b 75sed -i "s|__HOSTNAME__|${THISHOST}|g" /etc/apache2/apache2.conf
15e3aada
JD
76
77# as root
0155bbac 78echo "Installing OpenSRF prerequisites for Ubuntu..."
35e67cbd 79cd ${BUILDDIR} && make -f src/extras/Makefile.install ubuntu-xenial
0155bbac
JD
80
81# as DEFAULT_USER
82echo "Configuring and building OpenSRF..."
e2ad4781 83su -c "cd ${BUILDDIR} && autoreconf -i" ${DEFAULT_USER}
7b2b5e72 84su -c "cd ${BUILDDIR} && ./configure --prefix=${INSTALLDIR} --sysconfdir=${INSTALLDIR}/conf ${WSPORT}" ${DEFAULT_USER}
e2ad4781 85su -c "cd ${BUILDDIR} && make" ${DEFAULT_USER}
0155bbac
JD
86
87# as root
88echo "Installing OpenSRF..."
0f2c1897 89cd ${BUILDDIR} && make install
0155bbac 90useradd -m -s /bin/bash opensrf
f5c7692c 91PATHFILES="/etc/profile /root/.bashrc /home/${DEFAULT_USER}/.bashrc /home/opensrf/.bashrc"
21e6d31c 92for PATHFILE in ${PATHFILES} ; do
1cbdd07d 93 if [[ ! -e "${PATHFILE}" || ! `egrep "PATH=.*${INSTALLDIR}/bin" "${PATHFILE}"` ]] ; then
21e6d31c
JD
94 echo "export PATH=${INSTALLDIR}/bin:\$PATH" >> ${PATHFILE}
95 fi
96done
6e29c057 97chown ${DEFAULT_USER}:${DEFAULT_USER} /home/${DEFAULT_USER}/.bashrc
ad42e546
JD
98if [[ ! -n "$PROD" ]] ; then
99 chown -R opensrf:opensrf ${INSTALLDIR}
100fi
0155bbac
JD
101
102# as root, add the following two lines to /etc/hosts:
103#127.0.1.2 public.localhost public
104#127.0.1.3 private.localhost private
f2df3033
JD
105if [[ ! -n "$PROD" ]] ; then
106 if [[ ! `grep public.localhost /etc/hosts` ]] ; then
107 echo "Updating /etc/hosts..."
108 echo -e "127.0.1.2\tpublic.localhost\tpublic\n127.0.1.3\tprivate.localhost\tprivate\n" | \
109 cat - /etc/hosts > /etc/hosts.new && mv /etc/hosts.new /etc/hosts
110 fi
111else
112 echo 'WARNING: If this is a new production server, you will need to manually update /etc/hosts!'
113fi
0155bbac
JD
114
115# as root
116echo "ldconfig stuff..."
117echo "${INSTALLDIR}/lib" > /etc/ld.so.conf.d/opensrf.conf
118ldconfig
119
120# as root
121echo "Setting up ejabberd..."
35e67cbd
JD
122mv /etc/ejabberd/ejabberd.yml /etc/ejabberd/ejabberd.yml.${TIMESTAMP}
123cp ${SITKACONF}/files/etc/ejabberd/ejabberd.yml/${HOSTNAME} /etc/ejabberd/ejabberd.yml
124sed -i "s|__HOSTNAME__|${THISHOST}|g" /etc/ejabberd/ejabberd.yml
125chgrp ejabberd /etc/ejabberd/ejabberd.yml
126chmod 640 /etc/ejabberd/ejabberd.yml
127systemctl stop ejabberd.service && systemctl start ejabberd.service
913bfe44 128if [[ ! -n "$SKIP_EJABBERD_REG" ]] ; then
b718eda2
JD
129 if [[ ! -n "$PROD" ]] ; then
130 EJABBERD_HOST="localhost"
131 else
132 EJABBERD_HOST=$THISHOST
133 fi
913bfe44 134 sleep 5
bfca727e 135 su -c " \
b718eda2
JD
136 ejabberdctl register router private.${EJABBERD_HOST} ${PRIVATE_ROUTER_PASSWD} && \
137 ejabberdctl register opensrf private.${EJABBERD_HOST} ${PRIVATE_OPENSRF_PASSWD} && \
138 ejabberdctl register router public.${EJABBERD_HOST} ${PUBLIC_ROUTER_PASSWD} && \
bfca727e 139 ejabberdctl register opensrf public.${EJABBERD_HOST} ${PUBLIC_OPENSRF_PASSWD} " ejabberd
913bfe44 140fi
0155bbac
JD
141
142echo "OpenSRF is installed!"
61bfabc2
JD
143
144# websockets install (REQUIRED for web client)
145# XXX a valid SSL cert is required!
9f4f2f95 146if [[ ! -n "$SKIP_WEBSOCKETS" ]] ; then
ea139441 147 [[ -e "/tmp/websocketd" ]] && rm /tmp/websocketd
f91f6ea5 148 [[ ! -e "/tmp/${WEBSOCKETD_ZIP}" ]] && su -c "cd /tmp && wget '${WEBSOCKETD_URL}' && unzip ${WEBSOCKETD_ZIP}" ${DEFAULT_USER}
ea139441 149 cp /tmp/websocketd /usr/local/bin/
aa822e77 150 WEBSOCKETD_INIT="/lib/systemd/system/websocketd-osrf.service"
00e3ecc9 151 [[ -e "${WEBSOCKETD_INIT}" ]] && mv ${WEBSOCKETD_INIT} ${WEBSOCKETD_INIT}.bak
aa822e77
JD
152 cp ${SITKACONF}/files/${WEBSOCKETD_INIT}/${HOSTNAME} ${WEBSOCKETD_INIT}
153 systemctl daemon-reload
154 systemctl enable websocketd-osrf
61bfabc2 155
6298f1c5
JD
156 #echo "websockets is installed!"
157fi