]> git.evergreen-ils.org Git - working/Evergreen.git/blob - 1.6/admin/AdminMisc.xml
[working/Evergreen.git] / 1.6 / admin / AdminMisc.xml
1 <?xml version='1.0' encoding='UTF-8'?>\r
2 <chapter xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude"\r
3             xmlns:xl="http://www.w3.org/1999/xlink" version="5.0" xml:id="adminmisc">\r
4         <info>\r
5                 \r
6         <title>Server Operations and Maintenance</title>\r
7         <indexterm><primary>receipt template editor</primary></indexterm>\r
8                 <abstract>\r
9                         <para>This chapter deals with basic server operations such as starting and stopping <application>Evergreen</application> as well wall \r
10                         security, backing up and troubleshooting <application>Evergreen</application>.</para>\r
11                 </abstract>\r
12         </info>    \r
13         <section xml:id="startingopensrf">\r
14                 <title>Starting, Stopping and Restarting</title>\r
15                 <para>Occasionally, you may need to restart <application>Evergreen</application>. It is imperative that you understand the basic \r
16                 commands to stop and start the <application>Evergreen</application> server. You can start and stop <application>Evergreen</application> from the command line of \r
17                 the server using the <command>osrf_ctl.sh</command> script located in the \r
18                 <filename class="directory">openils/bin</filename> directory.</para>   \r
19                 <note><para><command>The osrf_ctl.sh</command> command must be run as the <systemitem class="username">opensrf</systemitem> user.</para></note>\r
20                 <para>To view help on <command>osrf_ctl.sh</command> and get all of its options, run:</para>\r
21                 <screen><userinput>osrf_ctl.sh -h</userinput></screen>\r
22                 <para>To start Evergreen, run:</para>\r
23                 <screen><userinput>osrf_ctl.sh -l -a start_all</userinput></screen>\r
24                 <para>The <option>-l</option> flag is used to indicate that Evergreen is configured to use <systemitem class="domainname">localhost</systemitem> as \r
25                 the host. If you have configured <filename>opensrf.xml</filename> to use your real hostname, do not use the <option>-l</option> flag. The <option>-a</option> \r
26                 option is required and indicates the <emphasis>action</emphasis> of the command. In this case \r
27                 <option>start_all</option>.    \r
28                 </para> \r
29                 <note>\r
30                         <para>If you receive the error message: <errortext>osrf_ctl.sh: command not found</errortext>, then your environment variable \r
31                         <varname>PATH</varname><indexterm><primary>environment variable</primary><secondary>PATH</secondary></indexterm> does not include the \r
32                         <filename class="directory">/openils/bin</filename> directory. You can set it using the following command:</para>\r
33                         <screen><userinput>export <varname>PATH</varname>=$PATH:<filename class="directory">/openils/bin</filename></userinput></screen>\r
34                         <para>If you receive the error message <errortext>Can't locate OpenSRF/System.pm in @INC … BEGIN \r
35                         failed–compilation aborted</errortext>, then your environment variable <varname>PERL5LIB</varname><indexterm><primary>environment \r
36                         variable</primary><secondary>PERL5LIB</secondary></indexterm> does not \r
37                         include the <filename class="directory">/openils/lib/perl5</filename> directory.  You can set it \r
38                         using the following command:</para>\r
39                         <screen><userinput>export <varname>PERL5LIB</varname>=$PERL5LIB:<filename class="directory">/openils/lib/perl5</filename></userinput></screen>\r
40                 </note>         \r
41                 <para>It is also possible to start a specific service. For example:</para>\r
42                 <screen><userinput>osrf_ctl.sh -l -a start_router</userinput></screen>\r
43                 <para>will only start the <systemitem class="service">router</systemitem> service.</para>\r
44                 <caution>\r
45                         <para>If you decide to start each service individually, you need to start them in a specific order \r
46                         for Evergreen to start correctly. Run the commands in this exact order:</para>\r
47 <screen><userinput>osrf_ctl.sh -l -a start_router</userinput></screen>\r
48 <screen><userinput>osrf_ctl.sh -l -a start_perl</userinput></screen>\r
49 <screen><userinput>osrf_ctl.sh -l -a start_c</userinput></screen>\r
50                 </caution>      \r
51                 <para>After starting or restarting Evergreen, it is also necessary to restart the <systemitem class="service">Apache web server</systemitem>\r
52                 <indexterm><primary>web server</primary><secondary>Apache</secondary></indexterm> for the OPAC to work correctly.</para>  \r
53                 <para>To stop <application>Evergreen</application>, run:</para>\r
54                 <screen><userinput>osrf_ctl.sh -l -a stop_all</userinput></screen>\r
55                 <para>As with starting, you can choose to stop services individually.</para>\r
56                 <para>To restart <application>Evergreen</application>, run:</para>\r
57                 <screen><userinput>osrf_ctl.sh -l -a restart_all</userinput></screen>\r
58                 <simplesect>\r
59                         <title>Starting Specific Perl Services</title>\r
60                         <para>It is also possible to start and stop a specific perl service using <filename>opensrf-perl.pl</filename>.  Here is the syntax for starting a perl service with this command:</para>\r
61 <screen><userinput>opensrf-perl.pl --service <systemitem class="service">&lt;service-name&gt;</systemitem> -a start -p <filename class="directory">&lt;PID-directory&gt;</filename> </userinput></screen>\r
62 <para>Example (starting the booking module):</para>\r
63 <screen><userinput>opensrf-perl.pl --service <systemitem class="service">open-ils.booking</systemitem> -a start -p <filename class="directory">/openils/var/run/opensrf</filename></userinput></screen>\r
64 \r
65 <para>This is the syntax for stopping a perl service with this command:</para>\r
66 <screen><userinput>opensrf-perl.pl --service <systemitem class="service">&lt;service-name&gt;</systemitem> -a stop -p <filename class="directory">&lt;PID-directory&gt;</filename> </userinput></screen>\r
67 <para>Example (stopping the booking module):</para>\r
68 <screen><userinput>opensrf-perl.pl --service <systemitem class="service">open-ils.booking</systemitem> -a stop -p <filename class="directory">/openils/var/run/opensrf</filename></userinput></screen>\r
69                         <para>These commands can be very useful when you edit Perl modules and only need to restart the specific service for changes to take effect.</para>\r
70                         \r
71                         <note>\r
72                         <para>The default for the PID-directory: <filename class="directory">/openils/var/run/opensrf</filename></para>\r
73                         <para>For a clustered server instance of Evergreen, you must store the PIDs on a directory \r
74                         that is local to each server, or else one of your cluster servers may try killing processes on itself that actually have PIDs on other servers.</para>\r
75                         <para>For services running on the local server use the <option>--localhost</option> to force the hostname to be <systemitem class="domainname">localhost</systemitem>, \r
76                         instead of the fully qualified domain name for the machine.</para>\r
77                         <para>To see other options run the command with the <option>-h</option> option:</para>\r
78 <screen><userinput>opensrf-perl.pl  -h</userinput></screen>\r
79                         </note>\r
80 <para>For a list of Evergreen/OpenSRF perl services see: <xref linkend="_evergreen_specific_opensrf_services"/>.</para>\r
81                 </simplesect>\r
82         </section>\r
83         <section xml:id="evergreen_startup_script">\r
84                 <title>Automating Evergreen Startup and Shutdown</title>\r
85                 <para>Once you understand starting and stopping Evergreen, you will want to create a start up script for two purposes:</para>\r
86                 <itemizedlist>\r
87                         <listitem>Allow you to start, restart and stop Evergreen, SIP, reporter and z39.50 services with one command.</listitem>\r
88                         <listitem>Allow Evergreen to stop and start properly during a system restart.</listitem>\r
89                 </itemizedlist>\r
90                 <para>The following procedure is for Debian or Ubuntu distributions of Linux.</para>\r
91                 <procedure>\r
92                         <step>\r
93                                 <para>Create a bash script for starting Evergreen and all associated services. Here is an example script:</para>  \r
94 \r
95 <programlisting><![CDATA[\r
96 #!/bin/bash\r
97 \r
98 OPENILS_BASE="/openils"\r
99 OPENILS_CORE="${OPENILS_BASE}/conf/opensrf_core.xml"\r
100 SRU_LOG="${OPENILS_BASE}/var/log/sru.log"\r
101 \r
102 SIP_PID="${OPENILS_BASE}/var/run"\r
103 SIP_CONF="${OPENILS_BASE}/conf/oils_sip.xml"\r
104 \r
105 REP_LOCK="${OPENILS_BASE}/var/lock/reporter-LOCK"\r
106 REP_NAME="Clark Kent, waiting for trouble"\r
107 \r
108 sru_name='simple2zoom'\r
109 \r
110 if [ $(whoami) != 'opensrf' ]; then\r
111  PERL5LIB='/openils/lib/perl5:$PERL5LIB';\r
112 fi;\r
113 \r
114 start() {\r
115         sleep 3\r
116         echo "Starting Evergreen"\r
117         sudo -u opensrf /bin/bash -c \ \r
118         "PERL5LIB=${PERL5LIB}:${OPENILS_BASE}/lib/perl5 PATH=${PATH}:${OPENILS_BASE}/bin osrf_ctl.sh \\r
119         -l -a start_all"\r
120 }\r
121 \r
122 stop() {\r
123         echo "Stopping Evergreen"\r
124         sudo -u opensrf /bin/bash -c \\r
125         "PERL5LIB=${PERL5LIB}:${OPENILS_BASE}/lib/perl5 PATH=${PATH}:${OPENILS_BASE}/bin osrf_ctl.sh \\r
126         -l -a stop_all"\r
127 }\r
128 \r
129 autogen() {\r
130         echo "Running Autogen Update"\r
131         sudo -u opensrf /bin/bash -c \ \r
132         "PERL5LIB=${PERL5LIB}:${OPENILS_BASE}/lib/perl5 PATH=${PATH}:${OPENILS_BASE}/bin autogen.sh \\r
133          -u -c ${OPENILS_CORE}"\r
134 }\r
135 \r
136 sip_start() {\r
137         sudo -u opensrf /bin/bash -c \\r
138         "PERL5LIB=${PERL5LIB}:${OPENILS_BASE}/lib/perl5 PATH=${PATH}:${OPENILS_BASE}/bin oils_ctl.sh \\r
139         -d ${SIP_PID} \\r
140         -s ${SIP_CONF} \\r
141         -a start_sip"\r
142 }\r
143 \r
144 sip_stop() {\r
145         sudo -u opensrf /bin/bash -c \ \r
146         "PERL5LIB=${PERL5LIB}:${OPENILS_BASE}/lib/perl5 PATH=${PATH}:${OPENILS_BASE}/bin oils_ctl.sh \\r
147         -d ${SIP_PID} \\r
148         -s ${SIP_CONF} \\r
149         -a stop_sip"\r
150 }\r
151 \r
152 sip_restart() {\r
153         sudo -u opensrf /bin/bash -c \\r
154         "PERL5LIB=${PERL5LIB}:${OPENILS_BASE}/lib/perl5 PATH=${PATH}:${OPENILS_BASE}/bin oils_ctl.sh \\r
155         -d ${SIP_PID} \\r
156          -s ${SIP_CONF} \\r
157         -a restart_sip"\r
158 }\r
159 ]]></programlisting>\r
160 <programlisting><![CDATA[\r
161 \r
162 start_rep() {\r
163         pids="$(pidof "$REP_NAME")"\r
164         if [ ! x"$pids" = x ] ; then\r
165           echo FAILURE ; echo $"Starting Reporting: already running as $pids" \r
166           return 1\r
167         fi\r
168         rm -f $REP_LOCK\r
169         sudo -u opensrf bash -c \\r
170         "PERL5LIB=${PERL5LIB}:${OPENILS_BASE}/lib/perl5 PATH=${PATH}:${OPENILS_BASE}/bin clark-kent.pl \\r
171         --lockfile=${REP_LOCK} --boostrap=${OPENILS_CORE} --concurrency=1 --sleep=30 --daemon" ;\r
172         pids="$(pidof "$REP_NAME")"\r
173         if [ x"$pids" = x ] ; then\r
174           echo FAILURE \r
175         else \r
176           echo OK\r
177         fi\r
178         echo "Starting Reporting: $pids" \r
179         return $RETVAL\r
180 }\r
181 \r
182 stop_rep() {\r
183         pids="$(pidof "$REP_NAME")"\r
184         if [ x"$pids" = x ] ; then\r
185           echo FAILURE ; echo $"Stopping Reporting: not running" ; RETVAL=1\r
186         else \r
187           kill $pids ; RETVAL=$?\r
188           if [ $RETVAL ] ; then\r
189             echo OK ; echo $"Stopping Reporting: $pids"\r
190           else\r
191             echo FAILURE \r
192           fi\r
193         fi\r
194         rm -f $REP_LOCK\r
195         return $RETVAL\r
196 }\r
197 \r
198 z39_50_start() {\r
199         pids=`ps -eo pid,args | grep $sru_name | grep -v grep | cut -c1-6`\r
200         if [ ! x"$pids" = x ] ; then\r
201           echo FAILURE ; echo $"Starting Z39.50/SRU: already running as $pids" \r
202           return 1\r
203         fi\r
204         sudo -u opensrf bash -c "touch ${SRU_LOG}"\r
205         sudo bash -c \ \r
206         "PERL5LIB=${PERL5LIB}:${OPENILS_BASE}/lib/perl5 PATH=${PATH}:${OPENILS_BASE}/bin z39_50.sh >> ${SRU_LOG} 2>&1" &\r
207         sleep 1\r
208         pids=`ps -eo pid,args | grep $sru_name | grep -v grep | cut -c1-6`\r
209         if [ x"$pids" = x ] ; then\r
210           echo FAILURE \r
211         else \r
212           echo OK\r
213         fi\r
214         echo "Starting Z39.50/SRU: $pids" \r
215         return $RETVAL\r
216 }\r
217 \r
218 z39_50_stop() {\r
219         pids=`ps -eo pid,args | grep $sru_name | grep -v grep | cut -c1-6`\r
220         if [ x"$pids" = x ] ; then\r
221           echo FAILURE ; echo $"Stopping Z39.50/SRU: not running" ; RETVAL=1\r
222         else \r
223           kill $pids ; RETVAL=$?\r
224           if [ $RETVAL ] ; then\r
225             echo OK ; echo $"Stopping Z39.50/SRU: $pids"\r
226           else\r
227             echo FAILURE \r
228           fi\r
229         fi\r
230         return $RETVAL\r
231 }\r
232 ]]></programlisting>\r
233 <programlisting><![CDATA[\r
234 case "$1" in\r
235     start)\r
236         start\r
237         start_rep\r
238         z39_50_start\r
239         sip_start\r
240     ;;\r
241     stop)\r
242         sip_stop\r
243         z39_50_stop\r
244         stop_rep\r
245         stop\r
246     ;;\r
247     restart)\r
248         echo "Restarting Evergreen, Reporter and Z39.50 Processes"\r
249         sip_stop\r
250         z39_50_stop\r
251         stop_rep\r
252         stop\r
253         start\r
254         start_rep\r
255         z39_50_start\r
256         sip_start\r
257     ;;\r
258     autogen)\r
259         autogen\r
260     ;;\r
261     sip_start)\r
262         sip_start\r
263     ;;\r
264     sip_stop)\r
265         sip_stop\r
266     ;;\r
267     sip_restart)\r
268         sip_restart\r
269     ;;\r
270     start_reporter)\r
271         start_rep\r
272     ;;\r
273     stop_reporter)\r
274         stop_rep\r
275     ;;\r
276     restart_reporter)\r
277         stop_rep\r
278         start_rep\r
279     ;;\r
280     z39_50_start)\r
281         z39_50_start\r
282     ;;\r
283     z39_50_stop)\r
284         z39_50_stop\r
285     ;;\r
286     z39_50_restart)\r
287         z39_50_stop\r
288         z39_50_start\r
289     ;;\r
290     start_router|stop_router|restart_router|start_perl|stop_perl|restart_perl| \\r
291     start_c|stop_c|restart_c|start_osrf|stop_osrf|restart_osrf|stop_all|start_all|restart_all)\r
292         sudo -u opensrf /bin/bash -c \\r
293         "PERL5LIB=${PERL5LIB}:${OPENILS_BASE}/lib/perl5 PATH=${PATH}:${OPENILS_BASE}/bin osrf_ctl.sh -l -a $1"\r
294     ;;\r
295     *)\r
296         echo " * Usage: /etc/init.d/evergreen {start|stop|restart|autogen"\r
297         echo "  |sip_start|sip_stop|sip_restart"\r
298         echo "  |z39_50_start|z39_50_stop|z39_50_restart"\r
299         echo "  |start_reporter|stop_reporter|restart_reporter"\r
300         echo "  |start_router|stop_router|restart_router|start_perl|stop_perl|restart_perl"\r
301         echo "  |start_c|stop_c|restart_c|start_osrf|stop_osrf|restart_osrf|stop_all|start_all|restart_all}"\r
302         exit 1\r
303     ;;\r
304 esac;\r
305 ]]></programlisting>\r
306                         </step>\r
307                         <step>\r
308                                 <para>Save file in <filename class="directory">/etc/bin</filename> folder as <filename>evergreenstart</filename> \r
309                                 if you would like this as a manual script for starting Evergreen services.</para> \r
310                                 \r
311                                 <para>Save file in <filename class="directory">/etc/init.d</filename> folder as <filename>evergreenstart</filename> \r
312                                 if you would like to run this script automatically during your server's boot process as explained in later steps.</para> \r
313                         </step>\r
314                         <step>\r
315                         <para>Ensure that the script is executable.</para>\r
316 <screen><userinput>sudo chmod 755 evergreenstart </userinput></screen>\r
317                         </step> \r
318                         <step>\r
319                                 <para>Test the script by running it from the command line as the <systemitem class="username">root</systemitem> user.</para>\r
320 <screen><userinput>/etc/init.d/evergreenstart restart</userinput></screen>\r
321                                 <para>You will also need to restart apache as the <systemitem class="username">root</systemitem> user.</para>\r
322 <screen><userinput>/etc/init.d/apache2 restart</userinput></screen>\r
323                         </step> \r
324                         <step>\r
325                                 <note>\r
326                                         <para>The next steps are optional if you want to automate Evergreen so it starts during your server's boot process.</para>\r
327                                 </note>\r
328                                 <para>Update runlevel defaults of the new evergreenstart service as the <systemitem class="username">root</systemitem>  user:</para>\r
329 <screen><userinput>update-rc.d evergreenstart defaults 80 20</userinput></screen>\r
330                                 <note>\r
331                                         <para>For Evergreen to start properly during a reboot, you will want to ensure that the first number \r
332                                         (<option>80</option>) is lower than the assigned \r
333                                         starting priority for Apache, so it starts before Apache. It should also have a larger stopping priority number \r
334                                         (<option>20</option>) than Apache so it stops \r
335                                         after Apache during a boot cycle.</para>\r
336                                 </note>\r
337                         </step> \r
338                         <step>\r
339                         <para>Test the startup script by rebooting the Evergreen Server and checking to ensure that all Evergreen sercices started properly.</para>\r
340                         </step> \r
341                 </procedure>\r
342                 <caution><para>This has not yet been tested in a Evergreen multi-server, <quote>brick</quote> configuration.</para></caution> \r
343                 <para>For more information on update-rc.d you should review the documentation on this topic for \r
344                 <link xl:href="http://www.debuntu.org/how-to-manage-services-with-update-rc.d">\r
345                 Debian</link> or <link xl:href="http://manpages.ubuntu.com/manpages/hardy/man8/update-rc.d.8.html">Ubuntu</link> \r
346                 depending on your distribution of Linux.</para>         \r
347         </section>\r
348         <section xml:id="backingup">\r
349                 <title>Backing Up</title>\r
350                 <indexterm><primary>databases</primary><secondary>backing up</secondary></indexterm>\r
351                 <para>Backing up your system files and data is a critical task for server and database administrators. \r
352                 Having a strategy for backing up and recovery could be the difference between a minor annoyance for users and\r
353                 a complete catastrophe.</para>   \r
354                 <simplesect>\r
355                         <title>Backing up the <application>Evergreen</application> Database</title><indexterm><primary>databases</primary></indexterm>\r
356                         <para>Most of the critical data for an <application>Evergreen</application> system – patrons, bibliographic records, holdings, \r
357                         transactions, bills – is stored in the <application>PostgreSQL</application><indexterm><primary>databases</primary>\r
358                         <secondary>PostgreSQL</secondary></indexterm>  database. You can therefore use normal \r
359                         <application>PostgreSQL</application> backup procedures to backup this data. For example, the simplest method of backing up the Evergreen\r
360                         database is to use the <command>pg_dump</command> command to create a live backup of the database without having to \r
361                         interrupt any Evergreen services. Here is an example pg_dump command which will dump a local Evergreen database into a the file \r
362                         <filename>evergreen_db.backup</filename>:</para>\r
363                         <screen><userinput>pg_dump -U evergreen -h localhost -f evergreen_db.backup evergreen</userinput></screen>\r
364                         <para>To restore the backed up database into a new database, create a new database using the \r
365                         template0 database template and the UTF8 encoding, and run the <command>psql</command> command, specifying the new \r
366                         database as your target:</para>\r
367                         <screen><userinput>createdb -T template0 -E UTF8 -U evergreen -h localhost new_evergreen</userinput></screen>\r
368                         <screen><userinput>psql -U evergreen -h localhost -f evergreen_db.backup new_evergreen</userinput></screen>\r
369                         <note>\r
370                                 <para>This method of backup is only suitable for small Evergreen instances. Larger sites \r
371                                 should consider implementing continuous archiving (also known as <quote>log shipping</quote>) to provide \r
372                                 more granular backups with lower system overhead. More information on backing up <application>PostgreSQL</application> \r
373                                 databases can be found in the official <link xl:href="http://www.postgresql.org/docs/"><application>PostgreSQL</application> \r
374                                 documentation</link>.</para>\r
375                         </note>\r
376                 </simplesect>\r
377                 <simplesect>\r
378                         <title>Backing up Evergreen Files</title>\r
379                         <indexterm><primary>directories</primary><secondary>backing up</secondary></indexterm>\r
380                         <para>When you deploy Evergreen, you will probably customize many aspects of your system including \r
381                         the system configuration files, <application>Apache</application> configuration files, OPAC and Staff Client. In order to \r
382                         protect your investment of time, you should carefully consider the best approach to backing up \r
383                         files.</para>\r
384                         <para>There are a number of ways of tackling this problem. You could create a script that regularly \r
385                         creates a time-stamped tarball of all of these files and copies it to a remote server - but that \r
386                         would build up over time to hundreds of files. You could use <link xl:href="http://www.samba.org/rsync/"><application>rsync</application></link>\r
387                         <indexterm><primary>rsync</primary></indexterm> to ensure that the files of \r
388                         interest are regularly updated on a remote server - but then you would lose track of the changes to \r
389                         the files, should you make a change that introduces a problem down the road.</para>\r
390                         <para>Perhaps one of the best options is to use a version control system like <link xl:href="http://bazaar.canonical.com">\r
391                         <application>Bazaar</application></link><indexterm><primary>Version Control System</primary><secondary>Subversion</secondary></indexterm>, \r
392                         <link xl:href="http://git-scm.com/"><application>git</application></link><indexterm><primary>Version Control System</primary><secondary>git</secondary></indexterm> \r
393                         or <link xl:href="http://subversion.apache.org/"><application>Subversion</application></link><indexterm><primary>Version Control System</primary>\r
394                         <secondary>Subversion</secondary></indexterm> to regularly push updates of the files you care about to a repository on a \r
395                         remote server. This gives you the advantage of quickly being able to run through the history of the \r
396                         changes you made, with a commenting system that reminds you why each change was made, combined with \r
397                         remote storage of the pertinent files in case of disaster on site. In addition, your team can create \r
398                         local copies of the repository and test their own changes in isolation from the production \r
399                         system. Using a version control system also helps to recover system customizations after an \r
400                         upgrade.</para>\r
401                 </simplesect>\r
402                 <simplesect>\r
403                         <title>Full System Backup</title>\r
404                         <para>A full system backup archives every file on the file system. Some basic methods require you \r
405                         to shut down most system processes; other methods can use mirrored RAID<indexterm><primary>RAID</primary></indexterm> setups or \r
406                         SAN<indexterm><primary>SAN</primary></indexterm> storage to \r
407                         take <quote>snapshot</quote> backups of your full system while the system continues to run. The subject of how \r
408                         to implement full system backups is beyond the scope of this documentation.</para>\r
409                 </simplesect>\r
410         </section>\r
411         <section xml:id="security">\r
412                 <title>Security</title>\r
413                 <indexterm><primary>security</primary></indexterm>\r
414                 <para>As with an ILS and resource accessible from the world wide web careful consideration needs to be \r
415                 given to the security of your <application>Evergreen</application> servers and database. While it is impossible to cover all aspects \r
416                 of security, it is important to take several precautions when setting up production <application>Evergreen</application> site.</para>\r
417                 <orderedlist>\r
418                         <listitem>\r
419                                 <para>Change the Evergreen <systemitem class="username">admin</systemitem> password and keep it secure. The \r
420                                 default admin password is known by anyone who has installed <application>Evergreen</application>. It is not a secret \r
421                                 and needs to be changed by the Administrator. It should also only be shared by those who \r
422                                 need the highest level of access to your system.</para>\r
423                         </listitem>\r
424                         <listitem>\r
425                                 <para>Create strong passwords using a combination of numerical and alphabetical characters \r
426                                 for all of the Administrative passwords including the <systemitem class="username">postgres</systemitem> and \r
427                                 <systemitem class="username">opensrf</systemitem> users</para>     \r
428                         </listitem>\r
429                         <listitem>\r
430                                 <para>Open ports in the firewall<indexterm><primary>firewall</primary></indexterm> with caution - It is only necessary to open ports \r
431                                 <systemitem class="protocol">80</systemitem> and <systemitem class="protocol">443</systemitem>\r
432                                 for <systemitem class="protocol">TCP</systemitem> connections to the Evergreen server from the OPAC and the staff client.  It is \r
433                                 critical for administrators to understand the concepts of network security and take precautions to minimize vulnerabilities. \r
434                                 </para>\r
435                         </listitem>\r
436                         <listitem>\r
437                                 <para>Use permissions <indexterm><primary>permissions</primary></indexterm> and permission groups wisely - it is important to understand the \r
438                                 purpose of the permissions and to only give users the level of access that they require.\r
439                                 </para> \r
440                         </listitem>\r
441                                         </orderedlist>  \r
442         </section>\r
443         <section xml:id="logfiles">\r
444                 <title>Managing Log Files</title>\r
445                 <indexterm><primary>logs</primary><secondary>managing</secondary></indexterm>\r
446                 <para><application>Evergreen</application> comes with a sophisticated logging system, but it is important to manage the <application>OpenSRF</application> \r
447                 and <application>Evergreen</application> logs. This section will provide a couple of log management techniques and tools.</para>        \r
448                 <simplesect>\r
449                         <title>Using the <systemitem class="service">logrotate</systemitem> Utility to Manage Log Size</title> \r
450                         <indexterm><primary>logs</primary><secondary>Log Rotate</secondary></indexterm>\r
451                          <para>Fortunately, this is not a new problem for <systemitem class="osname">Unix</systemitem> administrators, and \r
452                         there are a number of ways of keeping your logs under control. \r
453                         On <systemitem class="osname">Debian</systemitem> and <systemitem class="osname">Ubuntu</systemitem>, for example, \r
454                         the <systemitem class="service">logrotate</systemitem> utility controls when old log files are compressed and a new log file is started. \r
455                         <systemitem class="service">logrotate</systemitem> runs once a day and checks all log files that it knows about to see if a \r
456                         threshold of time or size has been reached and rotates the log files if a threshold condition has been met.</para>\r
457                         <para>To teach <systemitem class="service">logrotate</systemitem> to rotate Evergreen logs on a weekly basis, or if they are > 50MB in size, \r
458                         create a new file <filename>/etc/logrotate.d/evergreen</filename> with the following contents: </para>\r
459 <programlisting>\r
460 compress\r
461 /openils/var/log/*.log {\r
462 # keep the last 4 archived log files along with the current log file\r
463  # log log.1.gz log.2.gz log.3.gz log.4.gz\r
464  # and delete the oldest log file (what would have been log.5.gz)\r
465 rotate 5\r
466 # if the log file is > 50MB in size, rotate it immediately\r
467 size 50M\r
468  # for those logs that don't grow fast, rotate them weekly anyway\r
469   weekly\r
470 }\r
471 </programlisting>\r
472                 </simplesect>\r
473                 <simplesect>\r
474                         <title>Changing Logging Level for <application>Evergreen</application></title>\r
475                         <indexterm><primary>logs</primary><secondary>logging levels</secondary></indexterm>\r
476                         <para>Change the Log Levels in your config files. Changing the level of logging will help \r
477                         narrow down errors.</para> \r
478                         <tip>\r
479                                 <para>A high logging level is not wise to do in a production environment since  it \r
480                                 will produce vastly larger log files and thus reduce server performance.</para>\r
481                         </tip>\r
482                         <para>Change logging levels by editing the configuration file \r
483                         <filename>/openils/conf/opensrf_core.xml</filename><indexterm><primary>configuration files</primary><secondary>opensrf_core.xml</secondary></indexterm></para>\r
484                         <para>you will want to search for lines containing &lt;loglevel&gt;.</para>\r
485                         <para> the default setting for loglevel is 3 which will log <emphasis>errors</emphasis>, \r
486                         <emphasis>warnings</emphasis> and <emphasis>information</emphasis>.</para>\r
487                         <para>The next level is 4 which is for debugging and provides additional information \r
488                         helpful for the debugging process.</para>\r
489                         <para>Thus, lines with:</para>\r
490                         <programlisting>&lt;loglevel&gt;3&lt;/loglevel&gt;</programlisting>\r
491                         <para>Should be changed to:</para>\r
492                         <programlisting>&lt;loglevel&gt;4&lt;/loglevel&gt;</programlisting>\r
493                         <para>to allow debugging level logging</para>\r
494                         <para>Other logging levels include <emphasis>0</emphasis> for no logging, \r
495                         <emphasis>1</emphasis> for logging errors and <emphasis>2</emphasis> for logging warnings \r
496                         and errors.</para>\r
497                 </simplesect>\r
498         </section>\r
499         <section xml:id="InstallingPostgreSQL">\r
500                 <title>Installing PostgreSQL from Source</title>\r
501                 <indexterm><primary>databases</primary><secondary>PostgreSQL</secondary></indexterm>\r
502                 <para>Some <systemitem class="osname">Linux</systemitem> distributions, such as <systemitem class="osname">Debian Etch (4.0)</systemitem>, do not offer PostgreSQL \r
503                 version 8.2 as an installable package. Before you continue, examine the software dependencies listed in <xref linkend="serversideinstall-software-dependencies"/> \r
504                 to ensure that your Linux distribution supports the required version of PostgreSQL.</para>\r
505 \r
506                 <note>\r
507                         <para>Some <systemitem class="osname">Linux</systemitem> distributions, such as <systemitem class="osname">Debian Etch (4.0)</systemitem>, do not offer PostgreSQL \r
508                 version 8.2 as an installable package. Before you continue, examine the software dependencies listed in <xref linkend="serversideinstall-software-dependencies"/> \r
509                 to ensure that your Linux distribution supports the required version of PostgreSQL.</para>\r
510                 </note>\r
511                 \r
512                 <procedure>\r
513                         <step>\r
514                                 <para>Install the application <application>stow</application> on your system if it is not already installed. Issue the following command as \r
515                                 the <systemitem class="username">root</systemitem> user:</para>\r
516 <screen>\r
517 <userinput>apt-get install stow</userinput>\r
518 </screen>\r
519                         </step>\r
520                         <step>\r
521                                 <para>Download, compile, and install the latest release for PostgreSQL 8.2 (which was version <literal>8.2.12</literal> at the time of this writing). \r
522                                 As the <systemitem class="username">root</systemitem> user, follow these steps:</para>\r
523                                 \r
524 <screen>\r
525 <userinput>\r
526 wget http://wwwmaster.postgresql.org/redir/198/h/source/v8.2.17/postgresql-8.2.17.tar.bz2\r
527 tar xzf postgresql-8.2.17.tar.gz\r
528 cd postgresql-8.2.17\r
529 ./configure --with-perl --enable-integer-datetimes --with-openssl --prefix=/usr/local/stow/pgsql\r
530 make\r
531 make install\r
532 cd contrib\r
533 make\r
534 make install\r
535 cd xml2\r
536 make\r
537 make install\r
538 cd /usr/local/stow\r
539 stow pgsql\r
540 </userinput>\r
541 </screen>\r
542                                 \r
543                         </step>\r
544                         <step>\r
545                                 <para>Create the new user <systemitem class="username">postgres</systemitem> to run the PostgreSQL processes. \r
546                                 As the <systemitem class="username">root</systemitem> user, execute this command:</para>\r
547                                 <screen><userinput>adduser postgres</userinput></screen>\r
548                         </step>\r
549                         <step>\r
550                                 <para>Initialize the database directory and start up PostgreSQL. As the <systemitem class="username">root</systemitem> user, follow these steps:</para>\r
551                                 \r
552 <screen>\r
553 <userinput>\r
554 mkdir -p /usr/local/pgsql/data\r
555 chown postgres /usr/local/pgsql/data\r
556 su - postgres\r
557 initdb -D /usr/local/pgsql/data -E UNICODE --locale=C\r
558 pg_ctl -D /usr/local/pgsql/data -l /home/postgres/logfile start\r
559 </userinput>\r
560 </screen>\r
561                                 <note>\r
562                                         <para>If an error occurs during the final step above, review the path of the home directory for the \r
563                                         <systemitem class="username">postgres</systemitem> user. It may be <literal>/var/lib/postresql</literal> instead of <literal>/home/postres</literal>.</para>\r
564                                 </note>\r
565                         </step>\r
566                 </procedure>\r
567         </section>\r
568         <section xml:id="configuringPostgreSQL">\r
569                 <title>Configuring PostgreSQL</title>\r
570                 <indexterm><primary>databases</primary><secondary>PostgreSQL</secondary></indexterm>\r
571                 <para>The values of several PostreSQL configuration parameters may be changed for enhanced performance. The following table lists the default values \r
572                 and some suggested updates for several useful parameters:</para>\r
573                 <table>\r
574                         <title>Suggested configuration values</title>\r
575                         <tgroup align="left" cols="3" colsep="1" rowsep="1">\r
576                                 <colspec colnum="1" colwidth="1.0*"/>\r
577                                 <colspec colnum="2" colwidth="1.0*"/>\r
578                                 <colspec colnum="3" colwidth="1.0*"/>\r
579                                 <thead>\r
580                                         <row>\r
581                                                 <entry>Parameter</entry>\r
582                                                 <entry>Default</entry>\r
583                                                 <entry>Suggested</entry>\r
584                                         </row>\r
585                                 </thead>\r
586                                 <tbody>\r
587                                         <row>\r
588                                                 <entry>default_statistics_target</entry>\r
589                                                 <entry>10</entry>\r
590                                                 <entry>100</entry>\r
591                                         </row>\r
592                                         <row>\r
593                                                 <entry>work_mem</entry>\r
594                                                 <entry>4Mb</entry>\r
595                                                 <entry>128Mb</entry>\r
596                                         </row>\r
597                                         <row>\r
598                                                 <entry>shared_buffers</entry>\r
599                                                 <entry>8Mb</entry>\r
600                                                 <entry>512Mb</entry>\r
601                                         </row>\r
602                                         <row>\r
603                                                 <entry>effective_cache_size</entry>\r
604                                                 <entry>128Mb</entry>\r
605                                                 <entry>4Gb</entry>\r
606                                         </row>\r
607                                 </tbody>\r
608                         </tgroup>\r
609                 </table>\r
610         </section>\r
611 </chapter>\r