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