<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog Modulaweb &#187; bash</title>
	<atom:link href="http://www.modulaweb.fr/blog/tags/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.modulaweb.fr/blog</link>
	<description>Le blog des technologies modulables orientées web</description>
	<lastBuildDate>Thu, 16 Dec 2010 03:02:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Créer un fichier PID pour Funambol sous GNU/Linux</title>
		<link>http://www.modulaweb.fr/blog/2009/08/creer-un-fichier-pid-pour-funambol-sous-gnu-linux/</link>
		<comments>http://www.modulaweb.fr/blog/2009/08/creer-un-fichier-pid-pour-funambol-sous-gnu-linux/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 05:47:19 +0000</pubDate>
		<dc:creator>Jean-François VIAL</dc:creator>
				<category><![CDATA[Choses utiles]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[funambol]]></category>
		<category><![CDATA[gnu/linux]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[head]]></category>
		<category><![CDATA[Monit]]></category>
		<category><![CDATA[PID]]></category>
		<category><![CDATA[ps]]></category>

		<guid isPermaLink="false">http://www.modulaweb.fr/blog/?p=397</guid>
		<description><![CDATA[Lorsqu'il est lancé, le serveur Funambol ne crée pas de fichier PID rendant difficile son monitoring à l'aide d'outils comme Monit qui, à l'aide d'un PID, monitorent les ressources consommées par un process donné. À l'aide d'un script bash, nous allons permettre cette création de fichier PID. Fonctionnement du script Rien de bien sorcier, juste [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-340" src="http://www.modulaweb.fr/blog/wp-content/uploads/2009/02/funambol1.png" alt="" width="128" height="128" />Lorsqu'il est lancé, le serveur Funambol ne crée pas de fichier PID rendant difficile son monitoring à l'aide d'outils comme <a href="http://fr.wikipedia.org/wiki/Monit">Monit</a> qui, à l'aide d'un PID, monitorent les ressources consommées par un process donné.</p>
<p>À l'aide d'un script bash, nous allons permettre cette création de fichier PID.<br />
<span id="more-397"></span></p>
<h2>Fonctionnement du script</h2>
<p>Rien de bien sorcier, juste une recherche des PID des différents composants du serveur Funambol à l'aide d'un bon vieux <a href="http://www.linux-kheops.com/doc/man/manfr/man-html-0.9/man1/ps.1.html">ps</a> couplé à une paire de <a href="http://www.linux-kheops.com/doc/man/manfr/man-html-0.9/man1/grep.1.html">grep</a> associés à un petit <a href="http://fr.wikipedia.org/wiki/Awk">awk</a> suivi d'un <a href="http://pwet.fr/man/linux/commandes/head">head</a>... autrement dit "on recherche les processus des composants de funambol dans la liste des processus, et on récupère leurs PID".</p>
<h2>Le script</h2>
<p>Il y a certainement plus élégant mais l'essentiel c'est qu'il fasse ce qu'on lui demande et qu'il remplisse sa fonction didactique.</p>
<pre class="bash"><span style="color: #808080; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Check the script is being run by root, or die.</span>
<span style="color: #007800;">ROOT_UID=</span><span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$UID&quot;</span> -ne <span style="color: #ff0000;">&quot;$ROOT_UID&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Run script as &quot;</span>root<span style="color: #ff0000;">&quot;.&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #007800;">DS_SERVER=</span>`<span style="color: #c20cb9; font-weight: bold;">ps</span> -ef | <span style="color: #c20cb9; font-weight: bold;">grep</span> ds-server | <span style="color: #c20cb9; font-weight: bold;">grep</span> -v <span style="color: #c20cb9; font-weight: bold;">grep</span>`
&nbsp;
<span style="color: #007800;">HYPERSONIC=</span>`<span style="color: #c20cb9; font-weight: bold;">ps</span> -ef | <span style="color: #c20cb9; font-weight: bold;">grep</span> hypersonic | <span style="color: #c20cb9; font-weight: bold;">grep</span> -v <span style="color: #c20cb9; font-weight: bold;">grep</span>`
&nbsp;
<span style="color: #007800;">CTP_SERVER=</span>`<span style="color: #c20cb9; font-weight: bold;">ps</span> -ef | <span style="color: #c20cb9; font-weight: bold;">grep</span> com.funambol.ctp.server.CTPServer | <span style="color: #c20cb9; font-weight: bold;">grep</span> -v <span style="color: #c20cb9; font-weight: bold;">grep</span>`
&nbsp;
<span style="color: #007800;">INBOX_LISTENER=</span>`<span style="color: #c20cb9; font-weight: bold;">ps</span> -ef | <span style="color: #c20cb9; font-weight: bold;">grep</span> inbox-listener | <span style="color: #c20cb9; font-weight: bold;">grep</span> -v <span style="color: #c20cb9; font-weight: bold;">grep</span>`
&nbsp;
<span style="color: #007800;">PIM_LISTENER=</span>`<span style="color: #c20cb9; font-weight: bold;">ps</span> -ef | <span style="color: #c20cb9; font-weight: bold;">grep</span> pimlistener | <span style="color: #c20cb9; font-weight: bold;">grep</span> -v <span style="color: #c20cb9; font-weight: bold;">grep</span>`
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> -z <span style="color: #ff0000;">&quot;$DS_SERVER&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> -e /opt/funambol/ds-server.pid <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #c20cb9; font-weight: bold;">rm</span> /opt/Funambol/ds-server.pid
	<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">else</span>
	<span style="color: #c20cb9; font-weight: bold;">ps</span> -ef | <span style="color: #c20cb9; font-weight: bold;">grep</span> ds-server | <span style="color: #c20cb9; font-weight: bold;">grep</span> -v <span style="color: #c20cb9; font-weight: bold;">grep</span> | <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $2}'</span> | <span style="color: #c20cb9; font-weight: bold;">head</span> -n <span style="color: #000000;">1</span> &gt; /opt/Funambol/ds-server.pid
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> -z <span style="color: #ff0000;">&quot;$HYPERSONIC&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> -e /opt/funambol/hypersonic.pid <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
                <span style="color: #c20cb9; font-weight: bold;">rm</span> /opt/Funambol/hypersonic.pid
        <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #c20cb9; font-weight: bold;">ps</span> -ef | <span style="color: #c20cb9; font-weight: bold;">grep</span> hypersonic | <span style="color: #c20cb9; font-weight: bold;">grep</span> -v <span style="color: #c20cb9; font-weight: bold;">grep</span> | <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $2}'</span> | <span style="color: #c20cb9; font-weight: bold;">head</span> -n <span style="color: #000000;">1</span> &gt; /opt/Funambol/hypersonic.pid
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> -z <span style="color: #ff0000;">&quot;$CTP_SERVER&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> -e /opt/funambol/ctp-server.pid <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
                <span style="color: #c20cb9; font-weight: bold;">rm</span> /opt/Funambol/ctp-server.pid
        <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #c20cb9; font-weight: bold;">ps</span> -ef | <span style="color: #c20cb9; font-weight: bold;">grep</span> com.funambol.ctp.server.CTPServer | <span style="color: #c20cb9; font-weight: bold;">grep</span> -v <span style="color: #c20cb9; font-weight: bold;">grep</span> | <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $2}'</span> | <span style="color: #c20cb9; font-weight: bold;">head</span> -n <span style="color: #000000;">1</span> &gt; /opt/Funambol/ctp-server.pid
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> -z <span style="color: #ff0000;">&quot;$INBOX_LISTENER&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> -e /opt/funambol/inbox-listener.pid <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
                <span style="color: #c20cb9; font-weight: bold;">rm</span> /opt/Funambol/inbox-listener.pid
        <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #c20cb9; font-weight: bold;">ps</span> -ef | <span style="color: #c20cb9; font-weight: bold;">grep</span> inbox-listener | <span style="color: #c20cb9; font-weight: bold;">grep</span> -v <span style="color: #c20cb9; font-weight: bold;">grep</span> | <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $2}'</span> | <span style="color: #c20cb9; font-weight: bold;">head</span> -n <span style="color: #000000;">1</span> &gt; /opt/Funambol/inbox-listener.pid
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> -z <span style="color: #ff0000;">&quot;$PIM_LISTENER&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> -e /opt/funambol/pim-listener.pid <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
                <span style="color: #c20cb9; font-weight: bold;">rm</span> /opt/Funambol/pim-listener.pid
        <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #c20cb9; font-weight: bold;">ps</span> -ef | <span style="color: #c20cb9; font-weight: bold;">grep</span> pimlistener | <span style="color: #c20cb9; font-weight: bold;">grep</span> -v <span style="color: #c20cb9; font-weight: bold;">grep</span> | <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $2}'</span> | <span style="color: #c20cb9; font-weight: bold;">head</span> -n <span style="color: #000000;">1</span> &gt; /opt/Funambol/pim-listener.pid
<span style="color: #000000; font-weight: bold;">fi</span></pre>
<h2>Utilisation</h2>
<p>En appelant ce script via une tache cron, par exemple, vous permettrez aux système de monitoring d'avoir un pid à jour en cas de redémarrage.</p>
<p>Il est aussi possible de créer un script de commande pour (re)lancer/arrêter Funambol afin de créer/détruire ces fichiers PID au démarrage/arrêt de Funambol. Voici un exemple d'un tel script, où le script précédent (celui qui crée les PID) est dans /opt/controls/mk-funambol-pid-file :</p>
<pre class="bash"><span style="color: #808080; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Check the script is being run by root, or die.</span>
<span style="color: #007800;">ROOT_UID=</span><span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$UID&quot;</span> -ne <span style="color: #ff0000;">&quot;$ROOT_UID&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Run script as &quot;</span>root<span style="color: #ff0000;">&quot;.&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #007800;">FUNAMBOL=</span>`<span style="color: #c20cb9; font-weight: bold;">ps</span> -ef | <span style="color: #c20cb9; font-weight: bold;">grep</span> /opt/Funambol | <span style="color: #c20cb9; font-weight: bold;">grep</span> -v <span style="color: #c20cb9; font-weight: bold;">grep</span>`
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> -z <span style="color: #ff0000;">&quot;$FUNAMBOL&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #007800;">FUNAMBOL_ON=</span><span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">else</span>
	<span style="color: #007800;">FUNAMBOL_ON=</span><span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">case</span> $<span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">in</span>
start<span style="color: #7a0874; font-weight: bold;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$FUNAMBOL_ON</span> -eq <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
	<span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Funambol is already started : use $0 restart option to restart.&quot;</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span>
		<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
	<span style="color: #000000; font-weight: bold;">else</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Starting Funambol...&quot;</span>
		/opt/Funambol/bin/funambol start
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;done.&quot;</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Creating PID files...&quot;</span>
		/opt/controls/mk-funambol-pid-<span style="color: #c20cb9; font-weight: bold;">file</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;done.&quot;</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
	;;
stop<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$FUNAMBOL_ON</span> -eq <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
	<span style="color: #000000; font-weight: bold;">then</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Funambol is already stopped.&quot;</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span>
                <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
        <span style="color: #000000; font-weight: bold;">else</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Stopping Funambol...&quot;</span>
                /opt/Funambol/bin/funambol stop
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;done.&quot;</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Deleting PID files...&quot;</span>
                /opt/controls/mk-funambol-pid-<span style="color: #c20cb9; font-weight: bold;">file</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;done.&quot;</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
	;;
restart<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$FUNAMBOL_ON</span> -eq <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
	<span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Funambol was already stopped !&quot;</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Starting Funambol...&quot;</span>
                /opt/Funambol/bin/funambol start
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;done.&quot;</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Creating PID files...&quot;</span>
                /opt/controls/mk-funambol-pid-<span style="color: #c20cb9; font-weight: bold;">file</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;done.&quot;</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span>
	<span style="color: #000000; font-weight: bold;">else</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Stopping Funambol...&quot;</span>
                /opt/Funambol/bin/funambol stop
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;done.&quot;</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Deleting PID files...&quot;</span>
                /opt/controls/mk-funambol-pid-<span style="color: #c20cb9; font-weight: bold;">file</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;done.&quot;</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Starting Funambol...&quot;</span>
                /opt/Funambol/bin/funambol start
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;done.&quot;</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Creating PID files...&quot;</span>
                /opt/controls/mk-funambol-pid-<span style="color: #c20cb9; font-weight: bold;">file</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;done.&quot;</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
	;;
status<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$FUNAMBOL_ON</span> -eq <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
        <span style="color: #000000; font-weight: bold;">then</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Funambol is curently stopped.&quot;</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span>
        <span style="color: #000000; font-weight: bold;">else</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Funambol is curently started.&quot;</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
        ;;
*<span style="color: #7a0874; font-weight: bold;">&#41;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Usage $0 [start|stop|restart|status]&quot;</span>
	;;
<span style="color: #000000; font-weight: bold;">esac</span></pre>
<p>Ce script permet, en outre, de permettre un redémarrage direct de Funambol.</p>
<h2>Exemple d'application : configuration de Monit pour Funambol</h2>
<p>Considérant que nous avons les 2 scripts précédent, l'un dans /opt/controls/mk-funambol-pid-file et l'autre dans /opt/controls/funambol, on pourra utiliser, par exemple, la configuration suivante pour Monit :</p>
<pre># Funambol
check process ds-server with pidfile /opt/Funambol/ds-server.pid
        group funambol
        start program "/opt/controls/funambol start"
        stop program "/opt/controls/funambol stop"
        if failed port 8443 for 3 times within 3 cycles then restart
        if 2 restart within 10 cycles then timeout
check process hypersonic with pidfile /opt/Funambol/hypersonic.pid
        group funambol
check process ctp-server with pidfile /opt/Funambol/ctp-server.pid
        group funambol
check process inbox-listener with pidfile /opt/Funambol/inbox-listener.pid
        group funambol
check process pim-listener with pidfile /opt/Funambol/pim-listener.pid
        group funambol</pre>
<p>Ici funambol utilise une connexion sécurisée sur le port 8443 comme indiqué dans le <a href="http://www.modulaweb.fr/blog/2009/02/installation-de-funambol-couple-a-zimbra-sur-un-serveur-gnu-linux/">tutoriel d'installation de Funambol</a>, nous monitorons donc ce port.</p>
<p>Grâce aux pid, nous pourrons voir sur l'interface web de Monit les ressources consommées par les composants de Funambol, et éventuellement créer des règles dans le cas où cette consommation deviendrait excessive.</p>
<h4 class='related-posts-header'>Articles apparentés</h4><ul class="related-posts-list"><li class="related-post"><a href="http://www.modulaweb.fr/blog/2009/05/quelques-scripts-pour-profiter-de-son-scanner-sous-gnulinux/">Quelques scripts pour profiter de son scanner sous GNU/Linux</a> </li><li class="related-post"><a href="http://www.modulaweb.fr/blog/2009/02/installation-de-funambol-couple-a-zimbra-sur-un-serveur-gnu-linux/">Installation de Funambol couplé à Zimbra sur un serveur GNU/Linux</a> </li><li class="related-post"><a href="http://www.modulaweb.fr/blog/2010/11/optimiser-apache/">Optimiser Apache – Partie 1</a> </li><li class="related-post"><a href="http://www.modulaweb.fr/blog/2009/05/configurer-vsftpd-pour-mettre-a-jour-automatiquement-wordpress/">Configurer vsftpd pour mettre à jour automatiquement Wordpress</a> </li><li class="related-post"><a href="http://www.modulaweb.fr/blog/2009/02/inclure-ses-machines-virtuelles-a-son-reseau-avec-virtualbox/">Inclure ses machines virtuelles à son réseau avec VirtualBox</a> </li><li class="related-post"><a href="http://www.modulaweb.fr/blog/2009/02/pour-des-sessions-ssh-qui-durent/">Pour des sessions SSH qui durent</a> </li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.modulaweb.fr/blog/2009/08/creer-un-fichier-pid-pour-funambol-sous-gnu-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quelques scripts pour profiter de son scanner sous GNU/Linux</title>
		<link>http://www.modulaweb.fr/blog/2009/05/quelques-scripts-pour-profiter-de-son-scanner-sous-gnulinux/</link>
		<comments>http://www.modulaweb.fr/blog/2009/05/quelques-scripts-pour-profiter-de-son-scanner-sous-gnulinux/#comments</comments>
		<pubDate>Fri, 22 May 2009 18:34:52 +0000</pubDate>
		<dc:creator>Jean-François VIAL</dc:creator>
				<category><![CDATA[Choses utiles]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[gnu/linux]]></category>
		<category><![CDATA[infographie]]></category>
		<category><![CDATA[sane]]></category>
		<category><![CDATA[zenity]]></category>

		<guid isPermaLink="false">http://www.modulaweb.fr/blog/?p=321</guid>
		<description><![CDATA[Sous GNU/Linux (et même sous BSD et autres Solaris), les scanners sont très bien gérés grâce au proget SANE. Bien que les interface graphiques pour SANE, comme XSane, soient très abouties, rien de mieux pour une utilisation "courante" de son scanner que les boutons dont il dispose. Le problème c'est qu'autant les scanners sont bien [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-322" src="http://www.modulaweb.fr/blog/wp-content/uploads/2009/05/gnome-dev-scanner.png" alt="" width="128" height="128" />Sous GNU/Linux (et même sous BSD et autres Solaris), les scanners sont très bien gérés grâce au proget SANE. Bien que les interface graphiques pour SANE, comme XSane, soient très abouties, rien de mieux pour une utilisation "courante" de son scanner que les boutons dont il dispose.</p>
<p>Le problème c'est qu'autant les scanners sont bien supportés en tant que tels, autant leurs boutons sont excessivement peu souvent supportés.</p>
<p>Certains, comme moi, seront certainement très frustrés de ne pas pouvoir utiliser les très utiles boutons de leur appareil, et je me suis dit que quelques petits scripts seraient certainement utiles à d'autres.<span id="more-321"></span><strong></strong></p>
<p><strong>Attention :</strong> j'utilise <a href="http://www.gnomefr.org/">Gnome</a>, et les scripts suivants utilisent <a href="http://library.gnome.org/users/zenity/index.html.fr">zenity</a>. Si vous êtes sous <a href="http://fr.kde.org/">KDE</a>, mieux vaut utiliser <a href="http://docs.kde.org/stable/fr/kdewebdev/kommander/kmdr-basics.html">kommander</a> (je vous laisse le soin d'adapter les scripts), mais vous pouvez très bien utiliser zenity… ça sera moins bien intégré, c'est tout.</p>
<p>Un préalable au bon fonctionnement de ces scripts est, bien entendu, qu'un scanner soit déjà connecté à la machine, et que se scanner soit reconnu et configuré… en plus, pour le premier, d'avoir une imprimante connectée, allumée, et configurée.</p>
<p>Comme d'habitude, un petit tour dans le man ne fera de mal à personne.</p>
<h2>Photocopie</h2>
<p><strong>Dépendances :</strong> tiff2ps (paquet libtiff-tools), zenity (ou kommander)<br />
<strong>Ce que fait le script :</strong> scanne vers un fichier TIFF, le convertit en PostScript et imprime le résultat.</p>
<pre class="bash"><span style="color: #808080; font-style: italic;">#!/bin/bash</span>
<span style="color: #000000; font-weight: bold;">if</span> `zenity --question --<span style="color: #007800;">text=</span><span style="color: #ff0000;">&quot;Assurez-vous d'avoir aligné le document sur le bord DROIT de la fenêtre puis cliquez sur «Valider»&quot;</span> --<span style="color: #007800;">title=</span><span style="color: #ff0000;">&quot;Photocopier un document&quot;</span>`
<span style="color: #000000; font-weight: bold;">then</span>
	scanimage --format tiff --mode Gray --resolution <span style="color: #000000;">300</span> -l <span style="color: #000000;">0</span> -t <span style="color: #000000;">0</span> -x 210mm -y 297mm -p &gt; tmp.tiff
	tiff2ps -z -<span style="color: #c20cb9; font-weight: bold;">w</span> <span style="color: #000000;">8.27</span> -h <span style="color: #000000;">11.69</span> tmp.tiff | <span style="color: #c20cb9; font-weight: bold;">lpr</span>
	<span style="color: #c20cb9; font-weight: bold;">rm</span> -f tmp.tif
<span style="color: #000000; font-weight: bold;">else</span>
	zenity --info --<span style="color: #007800;">text=</span><span style="color: #ff0000;">&quot;Photocopie annulée&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre>
<h2>Scan2PDF</h2>
<p><strong>Dépendances :</strong> tiff2pdf (paquet libtiff-tools), zenity (ou kommander), evince (kpdf sous kde)<br />
<strong>Ce que fait le scritpt :</strong> scanne vers un fichier TIFF, le convertit en PDF et l'enregistre là où l'a indiqué l'utilisateur. Si l'utilisateur le souhaite, l'affiche à l'écran.</p>
<pre class="bash"><span style="color: #808080; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> `zenity --question --<span style="color: #007800;">text=</span><span style="color: #ff0000;">&quot;Assurez-vous d'avoir aligné le document sur le bord DROIT de la fenêtre puis cliquez sur «Valider»&quot;</span> --<span style="color: #007800;">title=</span><span style="color: #ff0000;">&quot;Scanner un document vers PDF&quot;</span>`
<span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #007800;">pdf=</span>$<span style="color: #7a0874; font-weight: bold;">&#40;</span>zenity --file-selection --save --confirm-overwrite --<span style="color: #007800;">filename=</span><span style="color: #ff0000;">&quot;$HOME/Desktop/scan.pdf&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> -n <span style="color: #007800;">$pdf</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        scanimage --format tiff --mode Gray --resolution <span style="color: #000000;">300</span> -l <span style="color: #000000;">0</span> -t <span style="color: #000000;">0</span> -x 210mm -y 297mm -p &gt; tmp.tiff
        tiff2pdf -o <span style="color: #007800;">$pdf</span> -z -p A4 -r d -c scan2pdf -a $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">whoami</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> ./tmp.tiff
        <span style="color: #c20cb9; font-weight: bold;">rm</span> -f tmp.tiff
        <span style="color: #000000; font-weight: bold;">if</span> `zenity --question --<span style="color: #007800;">text=</span><span style="color: #ff0000;">&quot;Le document va s'ouvrir&quot;</span> --<span style="color: #007800;">title=</span><span style="color: #ff0000;">&quot;Scan terminé&quot;</span>`
        <span style="color: #000000; font-weight: bold;">then</span>
            evince <span style="color: #007800;">$pdf</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
    <span style="color: #000000; font-weight: bold;">else</span>
        zenity --info --<span style="color: #007800;">text=</span><span style="color: #ff0000;">&quot;Copie annulée&quot;</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">else</span>
    zenity --info --<span style="color: #007800;">text=</span><span style="color: #ff0000;">&quot;Copie annulée&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre>
<h2>Scan2Gimp</h2>
<p><strong>Dépendances :</strong> zenity (ou kommander),tempfile gimp<br />
<strong>Ce que fait le scritpt :</strong> scanne vers un fichier TIFF sauvegardé sur le bureau avec un nom unique et l'ouvre avec <a href="http://www.framasoft.net/article1054.html">Gimp</a>.</p>
<pre class="bash"><span style="color: #808080; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> `zenity --question --<span style="color: #007800;">text=</span><span style="color: #ff0000;">&quot;Assurez-vous d'avoir aligné le document sur le bord DROIT de la fenêtre puis cliquez sur «Valider»&quot;</span> --<span style="color: #007800;">title=</span><span style="color: #ff0000;">&quot;Scan vers Gimp&quot;</span>`
<span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #007800;">tmp=</span><span style="color: #ff0000;">&quot;$(tempfile -d &quot;</span><span style="color: #007800;">$HOMEDesktop</span><span style="color: #ff0000;">&quot; -p &quot;</span>scan-<span style="color: #ff0000;">&quot; -s &quot;</span>.tiff<span style="color: #ff0000;">&quot;)&quot;</span>
    scanimage --format tiff --mode Gray --resolution <span style="color: #000000;">300</span> -l <span style="color: #000000;">0</span> -t <span style="color: #000000;">0</span> -x 210mm -y 297mm -p &gt; <span style="color: #007800;">$tmp</span>
    <span style="color: #c20cb9; font-weight: bold;">gimp</span> <span style="color: #007800;">$tmp</span>
<span style="color: #000000; font-weight: bold;">else</span>
    zenity --info --<span style="color: #007800;">text=</span><span style="color: #ff0000;">&quot;Scan annulé&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre>
<h4 class='related-posts-header'>Articles apparentés</h4><ul class="related-posts-list"><li class="related-post"><a href="http://www.modulaweb.fr/blog/2009/08/creer-un-fichier-pid-pour-funambol-sous-gnu-linux/">Créer un fichier PID pour Funambol sous GNU/Linux</a> </li><li class="related-post"><a href="http://www.modulaweb.fr/blog/2010/11/optimiser-apache/">Optimiser Apache – Partie 1</a> </li><li class="related-post"><a href="http://www.modulaweb.fr/blog/2010/07/ressources-graphiques/">Ressources graphiques</a> </li><li class="related-post"><a href="http://www.modulaweb.fr/blog/2009/05/configurer-vsftpd-pour-mettre-a-jour-automatiquement-wordpress/">Configurer vsftpd pour mettre à jour automatiquement Wordpress</a> </li><li class="related-post"><a href="http://www.modulaweb.fr/blog/2009/02/inclure-ses-machines-virtuelles-a-son-reseau-avec-virtualbox/">Inclure ses machines virtuelles à son réseau avec VirtualBox</a> </li><li class="related-post"><a href="http://www.modulaweb.fr/blog/2009/02/un-nuancier-pantone%c2%ae-en-ligne/">Un nuancier Pantone® en ligne</a> </li><li class="related-post"><a href="http://www.modulaweb.fr/blog/2009/02/installation-de-funambol-couple-a-zimbra-sur-un-serveur-gnu-linux/">Installation de Funambol couplé à Zimbra sur un serveur GNU/Linux</a> </li><li class="related-post"><a href="http://www.modulaweb.fr/blog/2009/02/pour-des-sessions-ssh-qui-durent/">Pour des sessions SSH qui durent</a> </li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.modulaweb.fr/blog/2009/05/quelques-scripts-pour-profiter-de-son-scanner-sous-gnulinux/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

