tag:blogger.com,1999:blog-77603011524556290362024-03-13T09:23:27.324-07:00Mis memoriasomaryahirhttp://www.blogger.com/profile/02913617573866847918noreply@blogger.comBlogger85125tag:blogger.com,1999:blog-7760301152455629036.post-63235118551955595032022-04-06T23:39:00.002-07:002022-04-06T23:39:21.197-07:00Problemas con virtualenvwrapper en Python 3.8 +<p>Ok estuve teniendo unos problemillas tratando de instalar virtualenvwrapper con Python 3.8, si ya se que esta versión trae un manejo de ambientes incluido, pero a poco no es cómodo utilizar un simple <span style="background-color: #eeeeee;"><span style="font-family: courier;">$ workon myenv</span></span> y listo ahi esta tu ambiente sin necesidad de estar buscando la carpeta del proyecto, bueno entonces me puse manos a la obra e hice mi propio virtualenvwrapper es super sencillo y solo tiene los comandos más básicos pero funciona aquí te dejo un link para que lo pruebes:</p><p><span style="font-size: large;"><a href="https://github.com/omaryahir/virtualenvwrapper">https://github.com/omaryahir/virtualenvwrapper<br /></a><span style="font-size: small;">(echa un lente ^)</span><br /></span></p><p>Espero te sea de utilidad !<br /></p>omaryahirhttp://www.blogger.com/profile/02913617573866847918noreply@blogger.com0tag:blogger.com,1999:blog-7760301152455629036.post-50313322043862443492021-07-23T14:30:00.008-07:002021-07-23T14:33:57.009-07:00Intro al Tipado de Python<p>Listado de Tipos:</p><pre><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="p">(</span>
<span class="n">Dict</span><span class="p">,</span>
<span class="n">List</span><span class="p">,</span>
<span class="n">Tuple</span><span class="p">,</span>
<span class="n">Set</span><span class="p">,</span>
<span class="n">Deque</span><span class="p">,</span>
<span class="n">NamedTuple</span><span class="p">,</span>
<span class="n">IO</span><span class="p">,</span>
<span class="n">Pattern</span><span class="p">,</span>
<span class="n">Match</span><span class="p">,</span>
<span class="n">Text</span><span class="p">,</span>
<span class="n">Optional</span><span class="p">,</span>
<span class="n">Sequence</span><span class="p">,</span>
<span class="n">Iterable</span><span class="p">,</span>
<span class="n">Mapping</span><span class="p">,</span>
<span class="n">MutableMapping</span><span class="p">,</span>
<span class="n">Any</span><span class="p">,</span>
<span class="p">)</span></pre><p><br /></p><p>Ejemplo(s):</p><p><br /></p><p>### Clases<br /></p><pre><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">ClassVar</span><span class="p">,</span> <span class="n">Dict</span><span class="p">,</span> <span class="n">List</span>
<span class="k">class</span> <span class="nc">Foo</span><span class="p">:</span>
<span class="n">x</span><span class="p">:</span> <b><span class="nb">int</span></b> <span class="o">=</span> <span class="mi">1</span> <span class="c1"># instance variable. default = 1</span>
<span class="n">y</span><span class="p">:</span> <b><span class="n">ClassVar</span></b><span class="p">[</span><b><span class="nb">str</span></b><span class="p">]</span> <span class="o">=</span> <span class="s2">"class var"</span> <span class="c1"># class variable</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">i</span><span class="p">:</span> <b><span class="n">List</span></b><span class="p">[</span><b><span class="nb">int</span></b><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="k">def</span> <span class="nf">foo</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">a</span><span class="p">:</span> <b><span class="nb">int</span></b><span class="p">,</span> <span class="n">b</span><span class="p">:</span> <b><span class="nb">str</span></b><span class="p">)</span> <span class="o">-></span> <b><span class="n">Dict</span></b><span class="p">[</span><b><span class="nb">int</span></b><span class="p">,</span> <b><span class="nb">str</span></b><span class="p">]:</span>
<span class="k">return</span> <span class="p">{</span><span class="n">a</span><span class="p">:</span> <span class="n">b</span><span class="p">}</span>
<span class="n">foo</span> <span class="o">=</span> <span class="n">Foo</span><span class="p">()</span>
<span class="n">foo</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="mi">123</span>
</pre><p><br /></p><p>### ContextManager<br /></p><pre><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">ContextManager</span><span class="p">,</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">IO</span>
<span class="kn">from</span> <span class="nn">contextlib</span> <span class="kn">import</span> <span class="n">contextmanager</span>
<span class="nd">@contextmanager</span>
<span class="k">def</span> <span class="nf">open_file</span><span class="p">(</span><span class="n">name</span><span class="p">:</span> <b><span class="nb">str</span></b><span class="p">)</span> <span class="o">-></span> <b><span class="n">Generator</span></b><span class="p">:</span>
<span class="n">f</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
<span class="k">yield</span> <span class="n">f</span>
<span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="n">cm</span><span class="p">:</span> <span class="n">ContextManager</span><span class="p">[</span><span class="n">IO</span><span class="p">]</span> <span class="o">=</span> <span class="n">open_file</span><span class="p">(</span><span class="vm">__file__</span><span class="p">)</span>
<span class="k">with</span> <span class="n">cm</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">())</span></pre><p><br /></p><p>Referencias:<br /></p><p><a href="https://www.pythonsheets.com/notes/python-typing.html">https://www.pythonsheets.com/notes/python-typing.html</a></p><p><br /></p>omaryahirhttp://www.blogger.com/profile/02913617573866847918noreply@blogger.com0tag:blogger.com,1999:blog-7760301152455629036.post-87739197483950154552021-07-03T11:16:00.003-07:002021-07-03T11:16:24.986-07:00Git Cherry Pick / git-cherry-pick<p> Saludos Estimados !!</p><p>Hace mucho tiempo que no escribo aquí, y hoy me tope con algo que ya había realizado muchas veces en el pasado pero me enrede y ya no me salía, por lo que les compartó y/o me autocomparto por si lo vuelvo a necesitar el buen <b>git-cherry-pick</b>.</p><p>No es muy recomendable ya que un abuso de este comando puede dejarte una buena enredadera que después es difícil encontrarle forma, pero si que es útil como en el siguiente caso.</p><p>Necesitamos pasar un commit de un branch a otro, esto por que el branch original quedo muy desactualizado y por error se utilizó, es verdad que el rebase es una opción pero será un largo camino que recorrer además de que puede prestarse a errores de dedo en el camino, so el cherry pick en este caso nos resulta más económico además que no son muchos cambios que pueden revisarse fácilmente aquí los pasos:</p><p><br /></p><p>1. Nos movemos a la branch donde tenemos nuestro commit: </p><p><span style="font-family: courier;"><span> </span>git checkout MiBranchConCommit</span></p><p>2. Ahora vamos a revisar cuál es el hash de nuestro commit:</p><p><span style="font-family: courier;"> </span><span style="font-family: courier;">git log --</span><span style="font-family: courier;">one line</span></p><p> La salida de este comando será algo como:</p><p> <span style="font-family: courier; font-size: x-small;">86f82f9 (HEAD -> SSCI-101-cherry-pick, origin/SSCI-101-cherry-pick) BRANCH-01test 1</span></p><p> <span style="font-family: courier; font-size: x-small;">90805b1 (origin/master, origin/SSCI-85, origin/HEAD, master) BRANCH-02 test 2</span></p><p> <span style="font-family: courier; font-size: x-small;">c3451b8 BRANCH test 3</span></p><p> Vamos a tomar el último de este commit por lo que el número será: <span style="font-family: courier; font-size: small;"><b>86f82f9</b></span></p><p>3. Ahora vamos al branch de destino:</p><p><span style="font-family: courier;"> </span><span style="font-family: courier;">git checkout BranchDestino</span></p><p>4. Una vez que nos encontremos ahí entonces aplicaremos el siguiente comando:</p><p><span style="font-family: courier;"> </span><span style="font-family: courier;">git cherry-pick 86f82f9</span></p><p><span style="font-family: courier;"><br /></span></p><p>Con este último comando se aplicará el mismo commit a este branch. Una opción interesante (que usualmente utilizo) solo en caso de que tuviéramos la misma base (o HEAD) en las ramas seria utilizar:</p><p><span style="font-family: courier;"> </span><span style="font-family: courier;">git cherry-pick 86f82f9 --ff</span></p><p>Esta opción <span style="font-family: courier;"><b>--ff</b></span> hace referencia a fast forward existen más opciones por acá <a href="https://git-scm.com/docs/git-cherry-pick">https://git-scm.com/docs/git-cherry-pick</a> sin embargo este nos colocará el commit hacia adelante o por arriba de todos los previous commits.</p><p>¿Cómo ves?, si consideras que puede haber otros caminos, te agradezco me los compartas en los comentarios.</p><p><br /></p><p>Espero te sea de utilidad !</p><p><br /></p><p>Referencias:</p><p><a href="https://git-scm.com/docs/git-cherry-pick">https://git-scm.com/docs/git-cherry-pick</a></p><p><br /></p>omaryahirhttp://www.blogger.com/profile/02913617573866847918noreply@blogger.com0tag:blogger.com,1999:blog-7760301152455629036.post-80735569488835915702016-10-25T11:25:00.003-07:002016-10-25T13:17:47.979-07:00Detalle con Google Chrome Free 3 of 9 Extended <div style="text-align: justify;">
El día de hoy me tope con un detalle con Google Chrome y la fuente Free 3 of 9 Extended usualmente la fuente funcionaba correctamente en una aplicación me toco desarrollar alguna vez pero derepente empezó a fallar, buscando en línea me encontre con que había al parecer un detalle con la forma en que renderiza las fuentes, y bueno finalmente con el link que agrego a las referencias una forma de como solucionarlo, lo que me funciono a mí fue en el código html colocar la fuente directamente en el tag usando el atributo style y sin colocar la palabra Extended en la fuente de la siguiente forma:</div>
<br />
<font style="font-family:'Free 3 of 9'">*123*</font><br />
<br />
NOTA: Observen las comillas simples ' para la fuente.<br />
<br />
De esta forma el problema se soluciono.<br />
<br />
<br />
Espero te sea de utilidad !<br />
<br />
<br />
Referencias<br />
<a href="https://productforums.google.com/forum/#!topic/chrome/_KLiTgccPLA">https://productforums.google.com/forum/#!topic/chrome/_KLiTgccPLA</a><br />
<a href="https://productforums.google.com/forum/#!topic/chrome/Vd5abMVzKFI">https://productforums.google.com/forum/#!topic/chrome/Vd5abMVzKFI</a>omaryahirhttp://www.blogger.com/profile/02913617573866847918noreply@blogger.com0tag:blogger.com,1999:blog-7760301152455629036.post-64453955570925929922016-10-25T11:25:00.001-07:002016-10-25T11:25:53.308-07:00Detalle con Google Chrome Free 3 of 9 Extended El día de hoy me tope con un detalle con Google Chrome y la fuente Free 3 of 9 Extended usualmente la fuente funcionaba correctamente en una aplicación me toco desarrollar alguna vez pero derepente empezó a fallar, buscando en línea me encontre con que había al parecer un detalle con la forma en que renderiza las fuentes, y bueno finalmente con el link que agrego a las referencias una forma de como solucionarlo, lo que me funciono a mí fue en el código html colocar la fuente directamente en el tag usando el atributo style y sin colocar la palabra Extended en la fuente de la siguiente forma:<br />
<br />
<font style="font-family:'Free 3 of 9'">*123*</font><br />
<br />
NOTA: Observen las comillas simples ' para la fuente.<br />
<br />
De esta forma el problema se soluciono.<br />
<br />
<br />
Espero te sea de utilidad !<br />
<br />
<br />
Referencias<br />
<a href="https://productforums.google.com/forum/#!topic/chrome/_KLiTgccPLA">https://productforums.google.com/forum/#!topic/chrome/_KLiTgccPLA</a><br />
<a href="https://productforums.google.com/forum/#!topic/chrome/Vd5abMVzKFI">https://productforums.google.com/forum/#!topic/chrome/Vd5abMVzKFI</a>omaryahirhttp://www.blogger.com/profile/02913617573866847918noreply@blogger.com0tag:blogger.com,1999:blog-7760301152455629036.post-6332974992490814252015-09-16T09:06:00.002-07:002015-09-16T09:07:02.631-07:00Colocar un mensaje prelogin en Linux Ubuntu ServerEste es un tema que cada vez que lo tengo que hacer olvido cuál es exactamente el archivo, debido a que puede hacerse de diferentes formas pero la que mejor me ha funcionado es la siguiente:<br />
<br />
<div class="p1">
<span class="s1"><b>$ sudo vi /etc/issue</b></span></div>
<div class="p1">
<span class="s1"><br /></span></div>
<div class="p1">
<span class="s1">NOTA: Con \n obtienes el nombre de la maquina, y con \l la terminal que se esta utilizando.</span></div>
<div class="p1">
<span class="s1"><br /></span></div>
<div class="p1">
<span class="s1"><br /></span></div>
<div class="p1">
<span class="s1">Espero te sea de utilidad !</span></div>
<div class="p1">
<br /></div>
<div class="p1">
<span class="s1"><br /></span></div>
<div class="p1">
<span class="s1">Referencias:</span></div>
<div class="p1">
<span class="s1"><a href="http://ubuntuforums.org/showthread.php?t=942972">http://ubuntuforums.org/showthread.php?t=942972</a></span></div>
<div class="p1">
<span class="s1"><br /></span></div>
<div class="p1">
<span class="s1"><br /></span></div>
omaryahirhttp://www.blogger.com/profile/02913617573866847918noreply@blogger.com0tag:blogger.com,1999:blog-7760301152455629036.post-21594709317043407602015-09-01T14:46:00.000-07:002015-09-01T14:46:09.870-07:00Conectarse a una base de datos remota de firebird con isqlRealmente es muy simple pero necesito dejar la nota por que de manera recurrente lo he necesitado:<br />
<br />
$ isql<br />
SQL> CONNECT "[IP_SERVER]/[PUERTO]:[DATABASE_PATH]" user 'USER' password 'PASS';<br />
<br />
Ejemplo:<br />
<br />
<br />
<div class="p1">
<span class="s1">CONNECT "10.10.1.2/3050:C:\bds\mibase.gdb" user 'SYSDBA' password '1234';</span></div>
<br />
<br />
Espero te sea de utilidad !<br />
<br />
<br />
<br />
Referencias:<br />
http://wiki.metawerx.net/wiki/HowToSetUpARemoteFireBirdConnectionomaryahirhttp://www.blogger.com/profile/02913617573866847918noreply@blogger.com0tag:blogger.com,1999:blog-7760301152455629036.post-88644240451947773242015-08-28T18:38:00.008-07:002015-10-20T15:12:25.774-07:00Ubuntu crontab: agregando una tarea para purgar django_sessionComo de costumbre necesito agregar un cronjob para limpiar la tabla de sesiones de django y aquí dejaré documentado el proceso, un proceso cron es aquel que puede repetirse dependiendo de la configuración.<br />
<br />
Dentro del sistema operativo podemos ejecutar<br />
<br />
$ sudo crontab -e<br />
<br />
Posteriormente el sistema preguntará por el editor en mi caso muy particular me gusta utilizar vim (opción 3), sin embargo da opciones a varios editores.<br />
<br />
Ahora bien nos vamos al final del archivo la forma es estructurar el contenido de acuerdo a como se nos explica en la siguiente imagen:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-WuFsGWDf-cU/VeDvy__S-6I/AAAAAAAAEI8/AUizCddhKME/s1600/diagram.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="149" src="http://4.bp.blogspot.com/-WuFsGWDf-cU/VeDvy__S-6I/AAAAAAAAEI8/AUizCddhKME/s320/diagram.png" width="320" /></a></div>
<br />
Cada línea del archivo crontab esta compuesta por estos componentes, aquí un ejemplo:<br />
<br />
#crontab<br />
#------------<br />
<br />
<b>1 * * * * touch /webapps/hola.txt</b><br />
<br />
#------------<br />
<br />
OJO: Si estas editando con vim necesitas dar ESC y luego :wq! así es con el signo de exclamación para que así instale el crontab.<br />
<br />
En el crontab anterior estamos configurando que cada vez que el minutero del reloj marque 1, se va crear un archivo que dice hola.txt.<br />
<br />
Ahora bien para el motivo que necesito hice un archivo con extensión .sh y lo coloque en mi directorio de <b>/home/my_user/cron_django_session.sh</b> con el siguiente contenido:<br />
<br />
/webapps/mi_proyecto/venv/bin/python /webapps/mi_proyecto/django_app/manage.py clearsessions<br />
strFecha=$(date)<br />
echo $strFecha > /home/administrador/cron_django_session.log<br />
<br />
NOTA: Revisar rutas de archivos<br />
<br />
Posteriormente le damos permisos usando el comando:<br />
$ chmod +x cron_django_session.sh<br />
<br />
Posteriormente vamos al crontab para añadir la ejecución de este archivo:<br />
<br />
<b>0 1 * * * /home/my_user/cron_django_session.sh >/dev/null 2>&1</b><br />
<br />
De esta forma el script se va ejecutar todos los días a la 1 a.m. al final se agrega <b>>/dev/null 2>&1 </b>para que no todo el tiempo el sistema operativo intente enviar un correo al usuario root, en caso de que se necesite se debe quitar esa parte.<br />
<br />
<br />
Espero te sea de utilidad !<br />
<br />
Referencias:<br />
<a href="http://www.debian-tutorials.com/crontab-tutorial-cron-howto">http://www.debian-tutorials.com/crontab-tutorial-cron-howto</a><br />
<a href="http://www.guatewireless.org/os/linux/como-agregar-tareas-al-cron-de-linux.html">http://www.guatewireless.org/os/linux/como-agregar-tareas-al-cron-de-linux.html</a><br />
<a href="https://docs.djangoproject.com/en/1.8/topics/http/sessions/#clearing-the-session-store">https://docs.djangoproject.com/en/1.8/topics/http/sessions/#clearing-the-session-store</a><br />
<a href="http://www.opencsw.org/community/questions/289/how-to-clear-the-django-session-cache">http://www.opencsw.org/community/questions/289/how-to-clear-the-django-session-cache</a><br />
<a href="https://vinta.ws/code/clear-session-in-django.html">https://vinta.ws/code/clear-session-in-django.html</a><br />
<a href="http://stackoverflow.com/questions/10289970/add-10-minute-cron-job-to-ubuntu-package">http://stackoverflow.com/questions/10289970/add-10-minute-cron-job-to-ubuntu-package</a><br />
<br />
<br />
<b>ACTUALIZACIÓN 2015-10-20</b><br />
<br />
Si quieres verificar como se ejecuta el cronjob puedes ver varios archivos a mi me funciono:<br />
$ sudo vi /var/log/syslog<br />
<br />
Referencias:<br />
<a href="http://unix.stackexchange.com/questions/207/where-are-cron-errors-logged">http://unix.stackexchange.com/questions/207/where-are-cron-errors-logged</a><br />
<br />
<br />
<br />
<br />omaryahirhttp://www.blogger.com/profile/02913617573866847918noreply@blogger.com0tag:blogger.com,1999:blog-7760301152455629036.post-45091449410483203392015-07-29T11:35:00.001-07:002015-07-29T11:35:44.744-07:00git: mostrar la lista de archivos de un commitPara mostrar la lista de archivos de un commit necesitamos primero utilizar el comando:<br />
<br />
$ git log<br />
<br />
Se abrirá pantalla con less y de ahí copiaremos el commit id y una vez que se copie, ejecutamos el siguiente comando pegandolo al final:<br />
<br />
$ git diff-tree --name-only -r dfaja8asas5dasasas440asasas93213af4053da07b7f8<br />
<br />
<br />
Espero te sea de utilidad !<br />
<br />
<br />
<br />
Referencias:<br />
<a href="http://stackoverflow.com/questions/424071/list-all-the-files-for-a-commit-in-git">http://stackoverflow.com/questions/424071/list-all-the-files-for-a-commit-in-git</a>omaryahirhttp://www.blogger.com/profile/02913617573866847918noreply@blogger.com2tag:blogger.com,1999:blog-7760301152455629036.post-70505611135033805912015-07-13T17:02:00.003-07:002015-07-13T17:09:22.367-07:00Include como php en Python + DjangoEn uno de los proyectos que estoy trabajando me tope con este detalle después de buscar en varios foros y demás encontre la siguiente forma, nada más cuidado por que baja el rendimiento, y hay que revisar las cuestiones de seguridad (<a href="http://lucumr.pocoo.org/2011/2/1/exec-in-python/">http://lucumr.pocoo.org/2011/2/1/exec-in-python/</a>); pero eso si funciona perfectamente y puede servir dependiendo de la aplicación; esto se lográ utilizando la instrucción exec.<br />
<br />
El proyecto completo lo pueden descargar de: <a href="https://github.com/omaryahir/django_doing_includes">https://github.com/omaryahir/django_doing_includes</a><br />
<br />
Aquí comento la parte importante dentro del archivo models.py estoy agregando un fragmento de código que manda llamar el archivo prueba.py :<br />
<br />
<br />
<b>db/models.py</b>:<br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">from django.db import models</span><br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">class Person(models.Model):</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> first_name = models.CharField(verbose_name=u'Nombre', max_length=50)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> last_name = models.CharField(verbose_name=u'Apellido', max_length=50)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> initials = models.CharField(verbose_name=u'Iniciales', max_length=10)</span><br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> def save(self, *args, **kwargs):</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><b> prueba_py = open('db/prueba.py','r')</b></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> super(Person, self).save(*args, **kwargs)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><b> exec(prueba_py)</b></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> print self.initials</span><br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> def __unicode__(self):</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> return "%s %s" % (self.first_name, self.last_name)</span><br />
<br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">class Otro(models.Model):</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> otrocampo = models.CharField("otro campo", max_length=50)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> person = models.ForeignKey(Person)</span><br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> class Meta:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> verbose_name = "Otro"</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> verbose_name_plural = "Otros"</span><br />
<br />
<b>db/prueba.py</b>:<br />
<div>
<br /></div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">self.initials = "Esta es la prueba"</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">x = Otro()</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">x.otrocampo = "Prueba otro campo"</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">x.person = self</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">x.save()</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">print "Saliendo"</span><br />
<br />
Como pueden observar en el código la línea - <b style="font-family: 'Courier New', Courier, monospace; font-size: small;">prueba_py = open('db/prueba.py','r')</b>- de la clase Person se abre el archivo prueba.py y posteriormente en la línea - <b style="font-family: 'Courier New', Courier, monospace; font-size: small;">exec(prueba_py)</b> - ejecutamos su contenido; lo interesante aquí de python es que carga todo el contexto, algo similar a lo que se hacia con php haciendo un include.<br />
<br />
Podemos observar en el archivo prueba.py que dentro del archivo usamos las variables como si estas se encontrarán ahí, bien sin embargo en python una de las cualidades que tenemos el rendimiento, por lo que este tipo de usos puede afectarlo, se debe analizar en donde se requerirá su uso.<br />
<br />
Si encuentras otra forma no dudes en compartirla ...<br />
<br />
Saludos espero te sea de utilidad !
<br />
<br />
<br />
Referencias:<br />
<a href="https://docs.python.org/3/library/functions.html?highlight=exec#exec">https://docs.python.org/3/library/functions.html?highlight=exec#exec</a><br />
<a href="http://lucumr.pocoo.org/2011/2/1/exec-in-python/">http://lucumr.pocoo.org/2011/2/1/exec-in-python/</a><br />
<a href="https://github.com/omaryahir/django_doing_includes">https://github.com/omaryahir/django_doing_includes</a><br />
<br />omaryahirhttp://www.blogger.com/profile/02913617573866847918noreply@blogger.com0tag:blogger.com,1999:blog-7760301152455629036.post-25844440228829050532015-07-12T13:53:00.006-07:002015-07-12T13:56:26.365-07:00Nginx bloquear el acceso a un directorio estáticoEn uno de los sitios que me toco configurar necesite bloquear el acceso a un subdirectorio de un directorio de contenido estático, mientras que el acceso al contenido de los demás subdirectorios debe permanecer disponible, encontre la siguiente forma de hacerlo:<br />
<br />
En el archivo de configuración del sitio agregue las líneas en negritas:<br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">server {</span><br />
<span style="font-family: Courier New, Courier, monospace;">
listen 80;</span><br />
<span style="font-family: Courier New, Courier, monospace;">
...</span><br />
<b><span style="font-family: Courier New, Courier, monospace;"> location ~/static/carpetabloquear/ {</span></b><br />
<b><span style="font-family: Courier New, Courier, monospace;"> alias /webapps/ruta/al/contenido/static/carpetabloquear/;</span></b><br />
<b><span style="font-family: Courier New, Courier, monospace;"> }</span></b><br />
<span style="font-family: Courier New, Courier, monospace;"><b><br /></b>
<b> location /static/ {</b></span><br />
<b><span style="font-family: Courier New, Courier, monospace;"> alias /webapps/ruta/al/contenido/static/;</span></b><br />
<b><span style="font-family: Courier New, Courier, monospace;"> }</span></b><br />
<span style="font-family: Courier New, Courier, monospace;">
...</span><br />
<span style="font-family: Courier New, Courier, monospace;">
}</span><br />
<br />
<br />
De esta forma aunque el usuario tiene acceso para algunos archivos del media dentro del directorio de la carpeta a bloquear no tiene acceso. Fue la forma como encontre hacerlo si has encontrado otra, te agradezco compartirlo.<br />
<br />
<br />
Espero te sea de utilidad !<br />
<br />
<br />
Referencias:<br />
<a href="http://www.nginxtips.com/nginx-location-directive/">http://www.nginxtips.com/nginx-location-directive/</a><br />
<br />omaryahirhttp://www.blogger.com/profile/02913617573866847918noreply@blogger.com0tag:blogger.com,1999:blog-7760301152455629036.post-22051480861723664482015-07-12T13:30:00.006-07:002016-10-24T12:42:37.098-07:00Django: ubuntu + nginx + gunicorn + supervisor + mysqlTengo que instalar en una maquina virtual con virtualbox un deployment de un proyecto que debo entregar dejaré aqui los pasos que me funcionaron, ya tenía un post de deployment con uwsgi, pero ha quedado un poco desactualizado.<br />
<br />
Bien voy colocando cada uno de los comandos:<br />
<br />
$ sudo apt-get install python-virtualenv<br />
<br />
Hay algunas otras herramientas que necesitamos instalar para el uso de django en ubuntu:<br />
<br />
$ sudo apt-get install mysql-server<br />
$ sudo apt-get install libmysql++-dev<br />
$ sudo apt-get install python-dev<br />
$ sudo apt-get install python-mysqldb<br />
$ sudo apt-get install build-essential python<br />
<div>
<br /></div>
Crear una carpeta donde tendremos nuestras aplicaciones web:<br />
<br />
$ sudo mkdir -p /webapps/carpeta_proyecto<br />
$ sudo chown administrador /webapps/carpeta_proyecto<br />
<br />
Creamos nuestro directorio virtual:<br />
<br />
$ cd /webapps/carpeta_proyecto<br />
$ virtualenv venv<br />
$ source venv/bin/activate<br />
<br />
Cargamos en ese directorio una carpeta con el código de nuestro proyecto, en mi caso lo tengo en bitbucket por lo que usando este comando descargo el código.<br />
<br />
(venv)$ git clone http://bitbucket.org/tu_usuario/miproyecto.git<br />
<br />
De esta forma tendremos dos directorios uno con el nombre de nuestro proyecto <<b>miproyecto</b>> y por otro lado tendremos un directorio con el entorno virtual <<b>venv</b>>.<br />
<br />
Ahora instalamos el entorno en mi proyecto tengo un archivo requirements.txt, pero igual mínimo necesitamos instalar django y la librería de mysql, lo instalamos usando pip.<br />
<br />
(venv)$ pip install django<br />
(venv)$ pip install python-mysql<br />
<br />
Es probable que para el proyecto tengan que correr un python manage.py syncdb o migrate para que puedan cargar la base de datos del proyecto, hasta este punto debemos poder probar el proyecto y ver que se encuentre funcionando correctamente usando un runserver.<br />
<br />
Una vez que lo anterior se encuentre funcionando vamos ahora a realizar directamente el deployment.<br />
<br />
Primero iniciamos instalando gunicorn, para eso utilizamos:<br />
<br />
(venv)$ pip install gunicorn<br />
<br />
Podemos probar el funcionamiento de gunicorn utilizando:<br />
<br />
(venv)$ cd miproyecto<br />
(venv)$ gunicorn miproyecto.wsgi:application --bind 0.0.0.0:8080<br />
<br />
NOTA: La carpeta miproyecto, es el directorio que django crea cuando ejecutamos un startproject.<br />
<br />
Al ejecutar el comando anterior gunicorn inicia un servidor en el puerto 8080 para ejecutar nuestro proyecto, <i>sin embargo puede ser que el contenido estático no funcione correctamente</i>.<br />
<br />
Ahora para hacerlo más dinámico realizamos lo siguiente, creamos un archivo en mi caso yo lo deje en carpeta_proyecto/deployment/<b>gunicorn_run</b> y le copiamos dentro el siguiente contenido:<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">#!/bin/bash</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">NAME="<b>miproyecto_app</b>" # Nombre de la app</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">DJANGODIR=<b>/webapps/carpeta_proyecto/miproyecto</b> # directorio del proyecto de Django</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">SOCKFILE=<b>/webapps/carpeta_proyecto/deployment/gunicorn.sock</b> # Nos comunicaremos utilizando este unix socket</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">USER=<b>miusuario</b> # Correr con el usuario</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">GROUP=<b>grupousuario</b> # Correr como el grupo </span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">NUM_WORKERS=<b>3</b> # Cuantos - worker processes - de Gunicorn </span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">DJANGO_SETTINGS_MODULE=<b>miproyecto</b>.settings # Archivo settings de Django</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">DJANGO_WSGI_MODULE=<b>miproyecto</b>.wsgi # Archivo WSGI del proyecto</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">echo "Starting $NAME as `whoami`"</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"># Activando el entorno</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">cd $DJANGODIR</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">source ../venv/bin/activate</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">export PYTHONPATH=$DJANGODIR:$PYTHONPATH</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"># Crear el directorio para correrlo en caso de no existir</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">RUNDIR=$(dirname $SOCKFILE)</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">test -d $RUNDIR || mkdir -p $RUNDIR</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"># Iniciando Django Gunicorn</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">exec ../venv/bin/gunicorn ${DJANGO_WSGI_MODULE}:application \</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> --name $NAME \</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> --workers $NUM_WORKERS \</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> --user=$USER --group=$GROUP \</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> --bind=unix:$SOCKFILE \</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> --log-level=debug \</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> --log-file=-</span><br />
<br />
<br />
Posteriormente convertimos el archivo como ejecutable usando el comando:<br />
<br />
(venv)$ sudo chmod u+x gunicorn_run<br />
<br />
Para probar el gunicorn podemos ejecutar el archivo de esta forma hacemos lo siguiente:<br />
<br />
(venv)$ ./gunicorn_run<br />
<br />
Una vez que se haya logrado ejecutar sin problemas, ahora, instalamos supervisor.<br />
<br />
(venv)$ sudo apt-get install supervisor<br />
<br />
Después de instalar supervisor vamos a crear el archivo <b>/etc/supervisor/conf.d/miproyecto.conf</b> con el siguiente contenido:<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">[program:miproyecto]</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">command = /webapps/</span><b style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">carpeta_proyecto</b><span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">/deployment/gunicorn_run ; Comando para iniciar la app</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">user = <b>miusuario </b> ; Usuario que lo va ejecutar</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">stdout_logfile = /webapps/</span><b style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">carpeta_proyecto</b><span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">/logs/gunicorn_supervisor.log ; Ruta del archivo log</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">redirect_stderr = true ; Alamcenar stderr en el mismo log</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">environment=LANG=en_US.UTF-8,LC_ALL=en_US.UTF-8 ; Establecer UTF-8 por default</span><br />
<br />
Creamos el directorio logs y el archivo para almacenar el gunicorn_supervisor.log dentro del directorio de carpeta_proyecto.<br />
<br />
(venv)$ mkdir /webapps/carpeta_proyecto/logs<br />
(venv)$ touch /webapps/carpeta_proyecto/logs/gunicorn_supervisor.log<br />
<br />
Posteriormente utilizamos para cargar el supervisor:<br />
<br />
(venv)$ sudo supervisorctl reread<br />
miproyecto: available<br />
(venv)$ sudo supervisorctl update<br />
miproyecto: added process group<br />
<br />
Ahora para revisar el estatus del proyecto podemos utilizar:<br />
<br />
(venv)$ sudo supervisorctl status miproyecto<br />
miproyecto RUNNING pid 2277, uptime 0:01:40<br />
<br />
Podemos iniciar, parar o reiniciar el proyecto utilizando:<br />
<br />
(venv)$ sudo supervisorctl stop miproyecto<br />
miproyecto: stopped<br />
(venv)$ sudo supervisorctl start miproyecto<br />
miproyecto: started<br />
(venv)$ sudo supervisorctl restart miproyecto<br />
miproyecto: stopped<br />
miproyecto: started<br />
<br />
Ahora vamos con Nginx, para instalarlo utilizamos:<br />
(venv)$ sudo apt-get install nginx<br />
<br />
Para iniciar el servicio podemos utilizar:<br />
$ sudo service nginx start<br />
<br />
Con esto el servidor de nginx se activará, puede probarse, por omisión el puerto es el 80. Ahora bien lo que haremos es crear el archivo <b>/etc/nginx/sites-available/miproyecto</b> con el siguiente contenido:<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">upstream <b>miproyecto_app_server</b> {</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> # fail_timeout=0 means we always retry an upstream even if it failed</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> # to return a good HTTP response (in case the Unicorn master nukes a</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> # single worker for timing out).</span><br />
<br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> server unix:<b>/webapps/carpeta_proyecto/deployment/gunicorn.sock</b> fail_timeout=0;</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">}</span><br />
<br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">server {</span><br />
<br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> listen 80;</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> server_name example.com;</span><br />
<br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> client_max_body_size 4G;</span><br />
<br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> access_log <b>/webapps/carpeta_proyecto/logs/nginx-access.log;</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> error_log <b>/webapps/</b></span><b><span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">carpeta_proyecto</span><span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">/logs/nginx-error.log;</span></b><br />
<br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> location /static/ {</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> # path to static folder</span>
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> alias <b>/webapps/</b></span><b><span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">carpeta_proyecto</span></b><span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><b>/miproyecto/static/</b>; </span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> }</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> </span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> location /media/ {</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> # path to media folder</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> alias </span><span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><b>/webapps/</b></span><b><span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">carpeta_proyecto</span></b><span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><b>/miproyecto/media/</b></span><span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">;</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> }</span><br />
<br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> location / {</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> # an HTTP header important enough to have its own Wikipedia entry:</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> # http://en.wikipedia.org/wiki/X-Forwarded-For</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;</span><br />
<br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> # enable this if and only if you use HTTPS, this helps Rack</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> # set the proper protocol for doing redirects:</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> # proxy_set_header X-Forwarded-Proto https;</span><br />
<br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> # pass the Host: header from the client right along so redirects</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> # can be set properly within the Rack application</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> proxy_set_header Host $http_host;</span><br />
<br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> # we don't want nginx trying to do something clever with</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> # redirects, we set the Host: header above already.</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> proxy_redirect off;</span><br />
<br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> # set "proxy_buffering off" *only* for Rainbows! when doing</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> # Comet/long-poll stuff. It's also safe to set if you're</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> # using only serving fast clients with Unicorn + nginx.</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> # Otherwise you _want_ nginx to buffer responses to slow</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> # clients, really.</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> # proxy_buffering off;</span><br />
<br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> # Try to serve static files from nginx, no point in making an</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> # *application* server like Unicorn/Rainbows! serve static files.</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if (!-f $request_filename) {</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> proxy_pass http://</span><b style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">miproyecto_app_server</b><span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">;</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> break;</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> }</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> }</span><br />
<br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> # Error pages</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> error_page 500 502 503 504 /500.html;</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> location = /500.html {</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> root <b>/webapps/carpeta_proyecto/miproyecto/static/</b>;</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> }</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">}</span><br />
<br />
De la misma manera que en los archivos anteriores personalizamos el contenido donde el color esta en negritas.<br />
<br />
Ahora creamos el symbolic link en la carpeta sites-enabled (Esta carpeta nos permite indicar a nginx cuales sitios están habilitados).<br />
<br />
$ sudo ln -s /etc/nginx/sites-available/<b>miproyecto</b> /etc/nginx/sites-enabled/<b>miproyecto</b><br />
<br />
Posteriormente reiniciamos nuestro servidor nginx:<br />
<br />
$ sudo service nginx restart<br />
<br />
Si hay algún error hay que revisar los directorios de los archivos, por otro lado en caso de que aparezca la pantalla de <b>bienvenida de nginx</b> al momento de volver a probar <b>es debido al archivo default</b>, en caso de que no vayamos a utilizar podemos eliminar su archivo símbolico desde el directorio de sites-enabled, una vez realizado lo anterior reiniciamos de nuevo el servidor de nginx.<br />
<br />
$ sudo service nginx restart<br />
<br />
Posterior a esto deberá funcionar correctamente el sitio.<br />
<br />
<br />
Espero te sea de utilidad !<br />
<br />
<br />
<br />
Referencias:<br />
<a href="http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/">http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/</a><br />
<a href="http://michal.karzynski.pl/blog/2013/10/29/serving-multiple-django-applications-with-nginx-gunicorn-supervisor/">http://michal.karzynski.pl/blog/2013/10/29/serving-multiple-django-applications-with-nginx-gunicorn-supervisor/</a>omaryahirhttp://www.blogger.com/profile/02913617573866847918noreply@blogger.com1tag:blogger.com,1999:blog-7760301152455629036.post-16416701767638972282015-01-11T12:03:00.001-08:002015-01-11T12:03:38.974-08:00virtualenvwrapper en mac osxPara instalar virtualenvwrapper se debe hacer con pip, siguiendo estos comandos:<br />
<br />
$ sudo easy_install pip<br />
$ sudo pip install virtualenv<br />
$ sudo pip install virtualenvwrapper<br />
<br />
Es posible que pip o virtualenv ya los tengas instalados así que si es así puedes omitir esos pasos, ahora bien, aquí viene por que no me funcionaba a mi, debes editar el archivo ~/.bashrc o ~/.zshrc (si estas usando oh my zsh, altamente recomendable) y colocar la siguiente línea:<br />
<br />
<br />
<div class="p1">
<span class="s1">source /usr/local/bin/virtualenvwrapper.sh</span></div>
<div class="p1">
<span class="s1"><br /></span></div>
<div class="p1">
<span class="s1">Con lo anterior estará funcionando el virtualenvwrapper, al parecer todo el asunto esta que lo cargue antes, fue una forma que encontre de resolverlo, si encontraste alguna otra no dudes en compartirla.</span></div>
<div class="p1">
<span class="s1"><br /></span></div>
<div class="p1">
<span class="s1">Espero te sea de utilidad !</span></div>
<div class="p1">
<span class="s1"><br /></span></div>
<div class="p1">
<span class="s1"><br /></span></div>
<div class="p1">
<span class="s1">Referencias:</span></div>
<div class="p1">
<a href="http://jamie.curle.io/blog/installing-pip-virtualenv-and-virtualenvwrapper-on-os-x/">http://jamie.curle.io/blog/installing-pip-virtualenv-and-virtualenvwrapper-on-os-x/</a></div>
<div class="p1">
<a href="http://stackoverflow.com/questions/24504231/whats-causing-this-error-when-i-try-and-install-virtualenv-ioerror-errno-13">http://stackoverflow.com/questions/24504231/whats-causing-this-error-when-i-try-and-install-virtualenv-ioerror-errno-13</a></div>
omaryahirhttp://www.blogger.com/profile/02913617573866847918noreply@blogger.com0tag:blogger.com,1999:blog-7760301152455629036.post-8709211446518870482015-01-08T10:31:00.001-08:002015-01-08T10:31:05.061-08:00unix: var run supervisor.sock or tmp.sock no such file o no encontradoDespués de haber cargado un servidor en suse con un deploy con Django sobre nginx, supervisor y gunicorn (<a href="http://omaryahir.blogspot.mx/2014/12/django-suse-nginx-gunicorn-y-supervisor.html">Aquí la guía que seguí</a>) tuvimos un proceso de reinicio de servidor y posteriormente al querer correr el nginx con el supervisor marcaba el error:<br />
<br />
unix:///var/run/tmp.sock no such file<br />
<br />
Buscando en internet encontré que también podría marcar el error de la siguientes formas:<br />
<br />
unix:///var/run/supervisor.sock archivo no encontrado<br />
unix:///var/run/supervisor.sock no such file<br />
<br />
El detalle es que el supervisor tiene que ser reiniciado de forma manual de acuerdo a la referencia entonces se necesita realizar nuevamente el comando:<br />
<br />
<b>$ sudo supervisord</b><br />
<br />
De esta forma se reiniciará y cargará nuevamente el supervisor, es importante recordar que se tiene que estar en el directorio del archivo <i>supervisord.conf</i><br />
<br />
Gracias a la referencia fue que encontré la solución.<br />
<br />
<br />
Espero te sea de utilidad ! <br />
<br />
<br />
Referencias:<br />
<a href="https://github.com/Supervisor/supervisor/issues/121">https://github.com/Supervisor/supervisor/issues/121</a><br />
<br />
<br />
omaryahirhttp://www.blogger.com/profile/02913617573866847918noreply@blogger.com0tag:blogger.com,1999:blog-7760301152455629036.post-87670162944491806592014-12-11T22:17:00.004-08:002014-12-11T22:17:52.454-08:00Error occurred during initialization of VM Could not allocate metaspace: 1073741824 bytes SUSE Amazon AWSInstalando Java en un servidor suse tuve el siguiente problema:<br />
<br />
#java --version<br />
Error occurred during initialization of VM<br />Could not allocate metaspace: 1073741824 bytes<br />
<br />
Empezando para instalarlo descargue el <i>rpm</i> y seguí el procedimiento del siguiente sitio:<br />
<a href="http://docs.oracle.com/javase/8/docs/technotes/guides/install/linux_jre.html#CFHIEGAA">http://docs.oracle.com/javase/8/docs/technotes/guides/install/linux_jre.html#CFHIEGAA</a><br />
<br />
Después de buscar en varios sitios, ejecutando el siguiente comando:<br />
<br />
# java -XX:-UseCompressedClassPointers -XX:+PrintFlagsFinal LongSleep<br />
<br />
Se ve un detallado del uso de memoria por flag, y me encontre que justo la línea:<br />
uintx <b>CompressedClassSpaceSize</b> = 1073741824 {product}<br />
<br />
Entonces siguiente los sitios de refencias, ejecutando la siguiente instrucción si opera correctamente java:<br />
<br />
# java -XX:CompressedClassSpaceSize=10m -version<br />
java version "1.8.0_25"<br />Java(TM) SE Runtime Environment (build 1.8.0_25-b17)<br />Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)<br />
<br />
De esa manera le estoy indicando que solo use 10 megas para ejecutarlo, o también usando:<br />
<br />
# java -XX:-UseCompressedClassPointers -version<br />java version "1.8.0_25"<br />Java(TM) SE Runtime Environment (build 1.8.0_25-b17)<br />Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)<br />
<br />
<br />
Referencias:<br />
<a href="http://mail.openjdk.java.net/pipermail/hotspot-runtime-dev/2014-April/011319.html">http://mail.openjdk.java.net/pipermail/hotspot-runtime-dev/2014-April/011319.html</a><br />
<a href="http://arabhardware.net/forum/showthread.php?t=391068">http://arabhardware.net/forum/showthread.php?t=391068</a><br />
<a href="http://docs.oracle.com/javase/8/docs/technotes/guides/install/linux_jre.html#CFHIEGAA">http://docs.oracle.com/javase/8/docs/technotes/guides/install/linux_jre.html#CFHIEGAA</a><br />
<br />omaryahirhttp://www.blogger.com/profile/02913617573866847918noreply@blogger.com1tag:blogger.com,1999:blog-7760301152455629036.post-82048483567011931612014-12-02T15:41:00.001-08:002015-01-20T10:55:34.029-08:00Django, suse, nginx, Gunicorn y supervisorComo siempre, por necesidad me veo en la tarea de implementar dentro de un servidor suse montado en un AWS EC2, el servicio de ngix para un proyecto en django usando gunicorn y supervisor.<br />
<br />
<i>Esta guía esta basada al 100% del video:<a href="https://www.youtube.com/watch?v=VDVNgivbvYk"> https://www.youtube.com/watch?v=VDVNgivbvYk</a> la diferencia es que en esta guía se está usando SUSE resolviendo el tema de instalación de nginx fuera de yast.</i><br />
<div>
<br /></div>
<div>
Lo primero que debemos considerar es que este funcionando python, django y virtual-env que se escapan a este post. Por lo que el proyecto debe estar funcionando si ejecutamos:</div>
<div>
<br /></div>
<div>
# python manage.py runserver 0.0.0.0:8000 </div>
<div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-05ft0zHFaoE/VHZogWpZjaI/AAAAAAAAEBI/mC69ipE8QdI/s1600/gunicorn.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-05ft0zHFaoE/VHZogWpZjaI/AAAAAAAAEBI/mC69ipE8QdI/s1600/gunicorn.jpg" /></a></div>
Para instalar gunicorn que puede ser usando la instrucción:</div>
<div>
<br /></div>
<div>
# pip install gunicorn</div>
<div>
<br /></div>
<div>
<br />
Posteriormente podemos probar si esta funcionando, entrando al directorio de nuestro proyecto de django y haciendo lo siguiente:<br />
<br />
# gunicorn miproyecto.wsgi:application --bind 0.0.0.0:8080<br />
<br />
<blockquote class="tr_bq">
________________________________<br />
Nota:<br />
Si lo queremos poner como servicio:<br />
$ gunicorn miproyecto.wsgi:application --bind 0.0.0.0:8080 --pid /tmp/gunicorn.pid --workers=3 --daemon<br />
Para detenerlo debemos verificar su id de proceso:<br />
$ cat /tmp/gunicorn.pid<br />
####<br />
$ kill -9 ####<br />
________________________________</blockquote>
<br /></div>
<div>
Si entramos al navegador y usamos la ip del equipo deberiamos ser capacez de ver el proyecto en ejecución: http://IP-del-servidor:8080/<br />
<br />
Ahora instalaremos supervisor para mantener todo el tiempo nuestro servidor activo.<br />
<br />
El proceso para instalarlo es el siguiente:<br />
<br />
# pip install supervisor<br />
<br />
Una vez instalado usaremos el archivo supervisord.conf de referencia para obtenerlo usamos el siguiente comando:<br />
<br />
# echo_supervisord_conf > ./supervisord.conf<br />
<br />
Una vez obtenido lo editaremos usando el siguiente comando:<br />
<br />
# vi supervisord.conf<br />
<br />
Al final del archivo agregamos las siguientes líneas:<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">;CONFIGURACION BASICA GUNICORN</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">[program:gunicorn]</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">;ruta donde se encuentra el directorio virtual que ejecutara gunicorn</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">command=/home/<span style="color: #444444;">ruta-a-virtualenv/virtualmachine</span>/bin/gunicorn <span style="color: #444444;">miproyecto</span>.wsgi:application --bind 0.0.0.0:8080 --workers=3 --pid /tmp/gunicorn.pid</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">;Ahora indicamos el directorio donde se almacena el proyecto ...</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">directory=/home/<span style="color: #444444;">ruta-al-pryecto/miproyecto</span>/</span><br />
<br />
Una vez teniendo el archivo configurado, podemos ejecutar el servicio usando:<br />
<br />
# supervisord<br />
<br />
Con eso el servicio esta en ejecución una forma de revisar que se encuentre en ejecución, es revisando que el archivo /tmp/gunicorn.pid se haya generado y tenga el número de proceso del servicio.<br />
<br />
Otra forma de ver el servicio es usando el siguiente comando:<br />
<br />
# supervisorctl<br />
<br />
Para parar el servicio de supervisor:<br />
<br />
# supervisorctrl stop gunicorn<br />
<blockquote class="tr_bq">
________________________________<br />
Nota: En caso de que necesites recargar el archivo de configuración (a mi me paso jeje), puedes entrar con el comando:<br />
$ supervisorctl<br />
Y posteriormente teclear reload:<br />
supervisor> reload<br />
Pedirá confirmar y posteriormente se recargará la configuración<br />
________________________________</blockquote>
<br />
Hasta este momento siguiendo los link de referencias logre montar el servidor gunicorn con supervisor.<br />
<br />
Ahora vamos a crear un archivo bash de nombre <b>gunicorn_run</b> en la raíz del proyecto django; con el siguiente contenido:<br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#!/bin/bash</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">NAME="miproyecto_app" # Nombre del proyecto</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">DJANGODIR=/home/ruta-al-proyecto/miproyecto #Directorio del proyecto</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">SOCKFILE=/home/rutal-al-proyecto/run/gunicorn.sock #Ruta del SockFile para nginx</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">USER=django # Usuario que ejecute las instancias </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">GROUP=django # Grupo del usuario que ejecute las instancias</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">NUM_WORKERS=3 # 2 * CPUs + 1</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">DJANGO_SETTINGS_MODULE=miproyecto.settings # Modulo settings del proyecto</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">DJANGO_WSGI_MODULE=miproyecto.wsgi # Nombre de la aplicacion para WSGI</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">echo "Iniciando $NAME como `whoami`"</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"># Activando el ambiente virtual</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">cd $DJANGODIR</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">source /home/</span><span style="color: #444444; font-family: 'Courier New', Courier, monospace; font-size: x-small;">ruta-a-virtualenv/virtualmachine</span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">/bin/activate</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE</span><br />
<span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">export PYTHONPATH=$DJANGODIR:$PYTHONPATH</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"># Creando el directorio del archivo gunicorn.sock por si no existe</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">RUNDIR=$(dirname $SOCKFILE)</span><br />
<span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">test -d $RUNDIR || mkdir -p $RUNDIR</span><br />
<span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"># Comando que ejecuta supervisor para correr el servidor gunicorn</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">exec </span><span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">/home/</span><span style="color: #444444; font-family: 'Courier New', Courier, monospace; font-size: x-small;">ruta-a-virtualenv/virtualmachine</span><span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">/bin/gunicorn</span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> ${DJANGO_WSGI_MODULE}:application \</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">--name $NAME \</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">--workers $NUM_WORKERS \</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">--user=$USER --group=$GROUP \</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">--bind=unix:$SOCKFILE \</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">--log-level=debug \</span><br />
<span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">--log-file=-</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<br />
<div>
Una vez que completemos el archivo y llenemos las secciones que debemos personalizar aplicaremos los persmisos:</div>
<div>
<br /></div>
<div>
# chmod u+x gunicorn_run</div>
<div>
<br /></div>
<div>
Detenemos el gunicorn en caso de tenerlo activo con supervisor, (supervisorctl stop gunicorn) y actualizaremos el supervisord.conf, sustituyendo las líneas que habíamos agregado por:</div>
<div>
<br />
<br /></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">;CONFIGURACION AVANZADA GUNICORN (Activa)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">[program:gunicorn]</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">;ruta donde se encuentra el archivo bash</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">command=/home/ruta-al-proyecto/miproyecto/gunicorn_run</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">;usuario que ejecuta el bash y el comando</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">username=root</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">;log de eventos para la gestion de errores</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">stdout_logfiles=/home/ruta-al-proyecto/logs/gunicorn_supervisor.log</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">redirect_stderr=true</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">environment=<span style="color: #444444;">LANG=en_US.UTF-8,LC_ALL=en_US.UTF-8</span></span><br />
<div>
<br /></div>
Una vez realizado lo anterior generaremos la carpeta de logs:<br />
<br />
# mkdir <span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">/home/ruta-al-proyecto/logs/</span><br />
<br />
Ahora iniciamos con la instalación de nginx en suse. Para realizarlo ejecutamos, los siguientes comandos:<br />
<br />
# wget http://nginx.org/download/nginx-1.6.0.tar.gz<br />
<div>
# tar xvf nginx-1.6.0.tar.gz</div>
# ./configure<br />
# make<br />
# make install<br />
<br />
<br />
----<br />
Para hacerlo servicio se debe crear el siguiente archivo:<br />
<br />
# vi /etc/init.d/nginx<br />
<br />
Con el siguiente contenido:<br />
<br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;">#! /bin/sh</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;">PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/nginx/sbin</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;">DAEMON=/usr/local/nginx/sbin/nginx</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;">NAME=nginx</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;">DESC=nginx</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;">PIDFILE=/usr/local/nginx/logs/$NAME.pid</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;">DAEMON_CONFIG=/usr/local/nginx/conf/nginx.conf</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;">test -x $DAEMON || exit 0</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;">set -e</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;">case "$1" in</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> start)</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> echo -n "Starting $DESC: "</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> start-stop-daemon --start --quiet --pidfile $PIDFILE \</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> --exec $DAEMON</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> echo " started"</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> ;;</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> stop)</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> echo -n "Stopping $DESC: "</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> if [ -f $PIDFILE ]; then</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> kill -15 `cat $PIDFILE 2>/dev/null`</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> fi</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> echo " stopped"</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> ;;</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> restart|force-reload)</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> echo -n "Restarting $DESC: "</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> if [ -f $PIDFILE ]; then</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> kill -15 `cat $PIDFILE 2>/dev/null`</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> fi</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> sleep 1</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> start-stop-daemon --start --quiet --pidfile $PIDFILE \</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> --exec $DAEMON</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> echo " restarted"</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> ;;</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> status)</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> echo "Status $DESC: "</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> ps aux | grep -v grep | grep -v /bin/sh | grep $NAME</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> ;;</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> *)</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> N=/etc/init.d/$NAME</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> echo "Usage: $N {start|stop|status|restart}" >&2</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> exit 1</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> ;;</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;">esac</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;">exit 0</span><br />
<br />
Le damos permisos de ejecución al archivo nginx:<br />
<br />
# cd /etc/init.d/<br />
# chmod +x nginx<br />
<br />
Ahora lo que vamos hacer es modificar el archivo de configuración:<br />
<br />
# vi /usr/local/nginx/conf/nginx.conf<br />
<br />
Localizar la línea: # user nobody<br />
<br />
De esa línea eliminar el caracter '#'.<br />
<br />
Una vez realizado lo anterior usaremos la instrucción para agregar la configuración:<br />
<br />
# chkconfig -a nginx<br />
# chkconfig --level 345 nginx on<br />
<br />
Con lo anterior queda configurado el servicio y podemos iniciarlo o pararlo con las instrucciones:<br />
<br />
# service nginx start <br />
# service nginx stop<br />
<br />
Ahora lo que realizaremos será configurar el archivo del sitio:<br />
<br />
# vi /usr/local/nginx/conf/nginx.conf</div>
<br />
Dentro del archivo colocaremos lo siguiente sustituyendo la sección del servidor 80 o bien dejando el actual con 8080:<br />
<br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;">upstream miproyecto_app {</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> # Este es el que conecta con gunicorn con nginx</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> server unix:</span><span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">/home/rutal-al-proyecto/run/gunicorn.sock</span><span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> fail_timeout=0;</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;">server {</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> # Puerto de escucha</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> listen 80;</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> # Dominios que responden a esta configuracion</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> server_name example.com</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> # Configuracion customizada para la subida de statics</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> client_body_in_file_only clean;</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> client_body_buffer_size 32K;</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> client_max_body_size 300M;</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> sendfile on;</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> send_timeout 300s;</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> # Logs de eventos</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> access_log </span><span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">/home/rutal-al-proyecto/</span><span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;">logs/nginx-access.log;</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> error_log </span><span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">/home/rutal-al-proyecto/</span><span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;">logs/nginx-error.log;</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> # Archivos estaticos</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> location /static/ {</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> alias </span><span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">/home/rutal-al-proyecto/</span><span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;">static/;</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> # Archivos media</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> location /media/ {</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> alias </span><span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">/home/rutal-al-proyecto</span><span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;">/media/;</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span><br />
<br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> # Procesando django</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> location / {</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> proxy_set_header Host $http_host;</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> proxy_redirect off;</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (!-f $request_filename) {</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> proxy_pass http://miproyecto_app;</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> # Error pages</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> error_page 500 502 503 504 /500.html;</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> location = /500.html {</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> root </span><span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">/home/rutal-al-proyecto</span><span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;">/</span><span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;">;</span><br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span><br />
<div>
<br /></div>
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<br />
<span style="color: #444444; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span><br />
<div>
<br /></div>
</div>
<div>
Necesitaremos levantar el servicio del gunicorn debemos recordar el proceso o levantarlo nuevamente es posible que necesiten entrar a la maquina virtual para entrar a supervisorctl start gunicorn, o bien es necesario también usar <i>reload</i> para que actualice el servicio con el archivo de configuración de supervisord.conf.<br />
<br />
<span style="font-family: inherit;">Nota: También es posible que necesitemos crear el archivo 500.html</span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">Una vez levantado el supervisor con gunicorn, ahora levantaremos el servicio de nginx usando:</span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"># service nginx restart</span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">Ha sido toda una odisea en el camino casi me decido por dejarlo, pero igual funcionó, les agradezco si encuentran alguna mejora se agradece ya que hay varias cosas que seguramente puedan mejorarse.</span><br />
<br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><b>Apuntes adicionales:</b></span><br />
<br />
<u>Apunte 1: Para ver servicios en ejecución en suse puedes utilizar:</u><br />
<br />
$ ps aux | grep<br />
<br />
Ejemplo:<br />
<br />
$ ps aux | grep gunicorn<br />
<br />
Con lo anterior puedes ver el id en la segunda columna y si es necesario puedes detenerlo:<br />
<br />
$ kill -9 ####<br />
<br />
<u>Apunte 2: (Añadido 2014-12-11):</u><br />
<br />
Si se necesita actualizar el código del proyecto de django puede hacerse realizando lo siguiente, se debe entrar al virtualenv y con eso parar el servidor con:<br />
<br />
# supervisorctrl stop gunicorn<br />
<br />
# supervisorctrl start gunicorn</div>
<div>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><br /><u>Apunte 3: (Añadido 2015-01-20):</u></span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">En esta ocasión nos paso que no podíamos configurar en el puerto 80 el servicio, por lo que lo que tuvimos que hacer fue: revisar en si en la configuración de ngnix se estén cargando otros archivos de configuración generalmente antes del server {} si es así comentar las siguientes instrucciones agregando #, esto es:</span><br />
<span style="font-family: inherit;"><br /></span>
<b># include /etc/nginx/conf.d/*.conf;</b><br />
<b># incude /etc/nginx/sites-enabled/*;</b><br />
<br />
O bien revisar si estos archivos no estén causando algún conflicto con el puerto 80.<br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><br /></span>
Espero te sea de utilidad !<br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><br /></span></div>
<div>
<span style="font-family: inherit;">Referencias:</span><br />
<a href="https://www.youtube.com/watch?v=VDVNgivbvYk"><span style="font-family: inherit;">https://www.youtube.com/watch?v=VDVNgivbvYk</span></a></div>
<div>
<a href="http://goodcode.io/blog/django-nginx-gunicorn/"><span style="font-family: inherit;">http://goodcode.io/blog/django-nginx-gunicorn/</span></a></div>
<div>
<a href="http://docs.gunicorn.org/en/latest/install.html"><span style="font-family: inherit;">http://docs.gunicorn.org/en/latest/install.html</span></a></div>
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: 'Times New Roman'; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">
<div style="margin: 0px;">
<a href="https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/gunicorn/"><span style="font-family: inherit;">https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/gunicorn/</span></a><br />
<a href="http://adityo.blog.binusian.org/?tag=php-fpm-nginx-on-opensuse-110"><span style="font-family: inherit;">http://adityo.blog.binusian.org/?tag=php-fpm-nginx-on-opensuse-110</span></a><br />
<a href="http://docs.gunicorn.org/en/latest/deploy.html"><span style="font-family: inherit;">http://docs.gunicorn.org/en/latest/deploy.html</span></a><br />
<a href="http://goodcode.io/blog/django-nginx-gunicorn/"><span style="font-family: inherit;">http://goodcode.io/blog/django-nginx-gunicorn/</span></a><br />
<a href="http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/"><span style="font-family: inherit;">http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/</span></a><br />
<a href="http://adityo.blog.binusian.org/?tag=php-fpm-nginx-on-opensuse-110"><span style="font-family: inherit;">http://adityo.blog.binusian.org/?tag=php-fpm-nginx-on-opensuse-110</span></a><br />
<a href="http://wiki.nginx.org/Install"><span style="font-family: inherit;">http://wiki.nginx.org/Install</span></a><br />
<span style="font-family: inherit;"><a href="http://stackoverflow.com/questions/19916016/gunicorn-nginx-server-via-socket-or-proxy">http://stackoverflow.com/questions/19916016/gunicorn-nginx-server-via-socket-or-proxy</a></span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><br /></span>
</div>
</div>
omaryahirhttp://www.blogger.com/profile/02913617573866847918noreply@blogger.com0tag:blogger.com,1999:blog-7760301152455629036.post-46624950617039772812014-11-19T21:00:00.003-08:002015-10-06T11:02:57.301-07:00Errores al iniciar gvim : (gvim:10659): Gtk-WARNING - ElementaryOS<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-9_d1BEb4eko/VG11D52rygI/AAAAAAAAEA0/ZiQeC0kt63k/s1600/vim.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="http://1.bp.blogspot.com/-9_d1BEb4eko/VG11D52rygI/AAAAAAAAEA0/ZiQeC0kt63k/s1600/vim.png" /></a></div>
<br />
<br />
Como ya tenia un tiempo que cada vez que abría gvim desde el terminal en ElementaryOS marca varias veces el mismo error:<br />
<br />
Errores al iniciar gvim : (gvim:10659): Gtk-WARNING **: Imposible encontrar el motor de temas en la ruta al _modulo: «pixmap»<br />
<br />
Para este error en particular realizar lo siguiente:<br />
<br />
$ sudo apt-get install synaptic<br />
$ sudo apt-get install gtk2-engines-pixbuf<br />
<br />
Una vez aplicado los comandos los errores desaparecieron.<br />
<br />
<br />
Espero te sea de utilidad !<br />
<br />
<br />
<br />
Referencias:<br />
<a href="http://tuksik.ru/gtk-warning-error-pixmap/">http://tuksik.ru/gtk-warning-error-pixmap/</a><br />
<br />
<br />
____________________________________<br />
Actualización: 06/Oct/2015<br />
<br />
En Ubuntu 14.04 tuve que realizar estos pasos adicionales:<br />
sudo apt-get remove vim-gnome<br />
sudo apt-get install vim-gtk<br />
<br />
Otra opción es agregar esta línea al .bashrc o .zshrc:<br />
alias gvim="gvim 2>/dev/null"<br />
<br />
<br />
Referencias:<br />
<a href="http://askubuntu.com/questions/361180/gvim-glib-gobject-warning-in-ubuntu-13-10">http://askubuntu.com/questions/361180/gvim-glib-gobject-warning-in-ubuntu-13-10</a><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />omaryahirhttp://www.blogger.com/profile/02913617573866847918noreply@blogger.com1tag:blogger.com,1999:blog-7760301152455629036.post-80868463929610078062014-11-15T16:17:00.001-08:002014-11-15T16:22:47.245-08:00Instalar ninja-ide en mac os x<div class="separator" style="clear: both; text-align: center;">
<a href="http://ninja-ide.org/"><img border="0" src="http://4.bp.blogspot.com/-ElH9veD2h8w/VGfWxeWLaCI/AAAAAAAAEAE/_q-aXGe2NoQ/s1600/Captura%2Bde%2Bpantalla%2B2014-11-15%2Ba%2Blas%2B16.41.39.png" height="76" width="320" /></a></div>
<br />
Bien para continuar con un proyecto que estoy desarrollando en python-django, he probado varias herramientas de desarrollo y me ha gustado el rendimiento de este entorno; sin embargo me dio varios problemas para instalarlo en mac.<br />
<br />
Para algunas herramientas utilice <a href="http://brew.sh/">homebrew</a>, y wget, si no los tienes instalados usa los siguientes comandos:<br />
<br />
<div class="p1">
<span class="s1"><b>$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"</b></span></div>
<div class="p1">
<b>$ brew install wget</b></div>
<br />
Para instalar la herramienta entonces iniciamos con los siguientes comandos:<br />
<br />
<b>$ sudo pip install macfsevents</b><br />
<br />
Por alguna razón, y puede ser por tener múltiples instancias de python (las cuáles no puedo mover mucho debido a otros proyectos de trabajo), las siguientes herramientas no me permitió instalarlas con pip por lo que las descargue directamente desde los sitios usando wget.<br />
<br />
<b>$ mkdir ninja-ide_app</b><br />
<b>$ cd ninja-ide_app</b><br />
<b>$ mkdir install</b><br />
<b>$ cd install</b><br />
<b>$ wget http://sourceforge.net/projects/pyqt/files/sip/sip-4.16.4/sip-4.16.4.tar.gz</b><br />
<b>$ tar -xzvf sip-4.16.4.tar.gz</b><br />
<b>$ cd sip-4.16.4 </b><br />
<b>$<span class="s1"> </span><span class="s2">python configure.py </span></b><br />
<span class="s2"><b>$ make </b></span><br />
<span class="s2"><b>$ make install </b></span><br />
<span class="s2"><br /></span>
<b><span class="s2">$ </span>wget http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.11.3/PyQt-mac-gpl-4.11.3.tar.gz</b><br />
<b><span class="s2">$ </span>tar -xzvf PyQt-mac-gpl-4.11.3.tar.gz </b><br />
<b>$ <span class="s2">cd PyQt-mac-gpl-4.11.3 </span></b><br />
<b><span class="s2">$ </span>python configure-ng.py </b> <br />
<span style="color: #999999;">(escribe yes para aceptar la licencia)</span><br />
<b>$ make </b> <br />
<span style="color: #999999;">(puede tardar unos minutos)</span><br />
<b>$ make install</b><br />
<br />
<div class="p1">
<b><br /></b></div>
<div class="p1">
</div>
<div class="p1">
<span class="s1"><b>$ wget https://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.11.6.tar.gz </b></span></div>
<div class="p1">
<b><span class="s1">$ </span><span class="s2">tar -xzvf virtualenv-1.11.6.tar.gz </span></b></div>
<div class="p1">
<b>$ cd virtualenv-1.11.6</b></div>
<div class="p1">
<b>$ <span class="s2">python setup.py install</span></b></div>
<div class="p1">
<b><span class="s2"><br /></span></b></div>
<div class="p1">
<b><span class="s2">$ wget </span>http://sourceforge.net/projects/pyqt/files/QScintilla2/QScintilla-2.8.4/QScintilla-gpl-2.8.4.tar.gz</b></div>
<div class="p1">
<b>$ <span class="s1"> </span><span class="s2">tar -xzvf QScintilla-gpl-2.8.4.tar.gz </span></b></div>
<div class="p1">
<b><span class="s2">$ </span>cd QScintilla-gpl-2.8.4</b></div>
<div class="p1">
<b>$ cd Qt4Qt5 </b></div>
<div class="p1">
<b>$ qmake qscintilla.pro </b></div>
<div class="p1">
<b>$ make</b></div>
<div class="p1">
<b>$ make install</b></div>
<div class="p1">
<b>$ cd ..</b></div>
<div class="p1">
<br /></div>
<div class="p1">
<b>$ cd Python </b></div>
<div class="p1">
<span style="color: #999999;">(Python Bindings)</span></div>
<div class="p1">
<b>$ python configure.py </b></div>
<div class="p1">
<b>$ make</b></div>
<div class="p1">
<b>$ make install </b></div>
<div class="p1">
<br /></div>
<div class="p1">
<b>$ cd ..</b></div>
<div class="p1">
<b>$ cd ..</b></div>
<div class="p1">
<b>$ cd ..</b></div>
<div class="p1">
<br /></div>
<div class="p1">
<b>$ git clone https://github.com/ninja-ide/ninja-ide.git ninja-ide</b></div>
<b>$ cd ninja-ide </b><br />
<b>$ python ninja-ide.py </b><br />
<b><br /></b>
Si todo sale bien ya tienes el entorno instalado puedes agregar al bash_profile un alias para que desde la terminal puedas llamarlo.<br />
<br />
<br />
Espero te sea de utilidad !<br />
<b><br /></b>
<br />
<br />
Referencias:<br />
<a href="http://ninja-ide.org/">http://ninja-ide.org/</a><br />
<a href="https://github.com/ninja-ide/ninja-ide-documentation/blob/master/docs/installing.rst">https://github.com/ninja-ide/ninja-ide-documentation/blob/master/docs/installing.rst</a><br />
<a href="http://scoobygalletas.blogspot.mx/2011/09/como-instalar-ninja-ide-en-mac-os-x.html">http://scoobygalletas.blogspot.mx/2011/09/como-instalar-ninja-ide-en-mac-os-x.html</a><br />
<a href="http://pyqt.sourceforge.net/Docs/PyQt4/installation.html">http://pyqt.sourceforge.net/Docs/PyQt4/installation.html</a><br />
<a href="http://www.riverbankcomputing.com/software/sip/download">http://www.riverbankcomputing.com/software/sip/download</a><br />
<a href="http://pyqt.sourceforge.net/Docs/QScintilla2/">http://pyqt.sourceforge.net/Docs/QScintilla2/</a><br />
<a href="https://github.com/ninja-ide/ninja-ide/blob/705b6d005ab4db7844f7805d1b10a24732045adf/README.md#requirements">https://github.com/ninja-ide/ninja-ide/blob/705b6d005ab4db7844f7805d1b10a24732045adf/README.md#requirements</a><br />
<a href="https://github.com/ninja-ide/ninja-ide/issues/1833">https://github.com/ninja-ide/ninja-ide/issues/1833</a><br />
<br />omaryahirhttp://www.blogger.com/profile/02913617573866847918noreply@blogger.com0tag:blogger.com,1999:blog-7760301152455629036.post-20371248049203709472014-07-06T11:06:00.001-07:002014-07-06T11:06:20.262-07:00Empaquetar aplicación con VirtualBox o redirección de puertos en NAT<div class="separator" style="clear: both; text-align: center;">
</div>
Como es de costumbre tenía una situación y me pareció muy interesante como para registrarlo y que no se me vaya a olvidar; bien el detalle, es que, necesito entregar un par de aplicaciones web que he desarrollado.<br />
<br />
La primera idea fue entregar un manual para que puedan montar su servidor web con MAMP, WAMP o XAMPP, sin embargo muchos usuarios no podían hacerlo siendo personas que no son de informática les causaba muchas dudas. Además que la implementación del código en este caso en php tenía errores de funcionamiento simplemente por las variaciones de MAMP, WAMP y XAMPP.<br />
<br />
Pues bien ahora voy a intentar utilizando una maquina de VirtualBox, pero se me presentaba el problema de como acceder si tenía la configuración NAT.<br />
<br />
VirtualBox tiene una opción de redirección de puertos:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-iXWWznwAggg/U7mPXJE6-zI/AAAAAAAADzM/gZCDU2WslH0/s1600/Captura+de+pantalla+2014-07-06+a+la(s)+12.53.33.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-iXWWznwAggg/U7mPXJE6-zI/AAAAAAAADzM/gZCDU2WslH0/s1600/Captura+de+pantalla+2014-07-06+a+la(s)+12.53.33.png" height="211" width="320" /></a></div>
<br />
<br />
Desde ahí puede configurarse la redirección de puertos:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-lCOX4WOTeaA/U7mPcGMrxvI/AAAAAAAADzU/jbBIaHftR4I/s1600/Captura+de+pantalla+2014-07-06+a+la(s)+12.55.38.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-lCOX4WOTeaA/U7mPcGMrxvI/AAAAAAAADzU/jbBIaHftR4I/s1600/Captura+de+pantalla+2014-07-06+a+la(s)+12.55.38.png" height="212" width="320" /></a></div>
<br />
<br />
O también puede utilizarse la línea de comandos desde tu equipo, cuando tienes virtualbox instalado tienes un comando de nombre VBoxManage, de esta forma puedes correr:<br />
<br />
<b>$ VBoxManage modifyvm "nombre de tu maquina" --natpf1 "guesthttp,tcp,,2080,,80"</b><br />
<br />
Todo lo expuesto en las imágenes y en el comando anterior, lo que estamos haciendo es que cuando en nuestra maquina busquemos en el navegador 127.0.0.1:2080, el equipo va ir a la maquina virtual al puerto 80, mientras que en tu equipo el puerto 2080 es el que esta a la escucha.<br />
<br />
Espero te sea de utilidad !<br />
<br />
<br />
<br />
Referencias:<br />
<a href="http://cjenkins.wordpress.com/2010/08/12/redireccion-de-puertos-con-virtualbox/">http://cjenkins.wordpress.com/2010/08/12/redireccion-de-puertos-con-virtualbox/</a><br />
<a href="http://linuxtargz.blogspot.mx/2012/09/configurar-el-reenvio-de-puertos-con.html">http://linuxtargz.blogspot.mx/2012/09/configurar-el-reenvio-de-puertos-con.html</a><br />
<a href="http://aruljohn.com/info/virtualbox-access-guest-from-host-nat/">http://aruljohn.com/info/virtualbox-access-guest-from-host-nat/</a> omaryahirhttp://www.blogger.com/profile/02913617573866847918noreply@blogger.com0tag:blogger.com,1999:blog-7760301152455629036.post-36250992011236323012014-05-29T21:16:00.000-07:002014-05-29T21:17:02.063-07:00Secuencia de Django South MigrationUna vez instalado south, y haberlo agregado al archivo settings.py dentro de INSTALLED_APPS, la secuencia es:<br />
<br />
<ol>
<li>Crear físicamente la base de datos</li>
<li>Ejecutar comando: <b>$ manage.py schemamigration app --initial</b></li>
<li>Ejecutar comando: <b>$ manage.py syncdb </b></li>
<li>En el paso anterior no se crearon las tablas de la aplicación puesto que eso se realizará con el comando siguiente.</li>
<li>Ejecutar comando: <b>$ manage.py migrate app</b></li>
</ol>
<div>
<br /></div>
<div>
Ahora bien si hubo un cambio:</div>
<div>
<ol>
<li>Ejecutar comando: <b>$ manage.py schemamigration app --auto</b></li>
<li>Ejecutar comando:<b> $ manage.py migrate app</b></li>
</ol>
<div>
<div class="p1">
<br /></div>
</div>
</div>
<div>
¿Te fué de utilidad?</div>
omaryahirhttp://www.blogger.com/profile/02913617573866847918noreply@blogger.com0tag:blogger.com,1999:blog-7760301152455629036.post-46725945659655938452014-04-26T01:38:00.001-07:002014-04-26T01:38:05.081-07:00Ubuntu compartir una carpeta desde la terminal usando sambaPara compartir una carpeta desde Ubuntu, lo primero es tener instalado samba, en caso de no tenerlo se puede instalar utilizando:<br />
<br />
$ sudo apt-get install smbfs samba<br />
<br />
En mi caso cuando instale ubuntu desde el proceso de instalación agregue la opción de utilizar samba.<br />
<br />
Agregamos un usuario para el uso de la conexión desde otro equipo ya sea de windows, mac o desde otro equipo con ubuntu.<br />
<br />
$ sudo smbpasswd -a miusuario<br />
<br />
Al correr el comando anterior solicitará una contraseña para el usuario. Posteriormente necesitaremos agregar el usuario y su nombre en el smbusers.<br />
<br />
$ sudo vi /etc/samba/smbusers <br />
<br />
Al correr el comando se abrirá una pantalla para modificación de texto en el cuál agregaremos:<br />
<br />
<span style="color: #444444;"><span style="background-color: white;">miusuario="MiUsuario"</span></span><br />
<br />
Posteriormente daremos de alta los directorios que queremos compartir, esto lo haemos en el archivo smb.conf, editandolo con el siguiente comando:<br />
<br />
$ sudo vi /etc/samba/smb.conf <br />
<br />
Dentro del archivo se colocará:<br />
<br />
<span style="color: #666666;">[nombre_del_directorio]<br /> comment = miusuario Archivos Privados<br /> path = /ruta/al/directorio_compartido<br /> valid users = miusuario<br /> public = no<br /> writable = yes</span><br />
<br />
Posteriormente reiniciamos el servicio de samba:<br />
<br />
$ sudo /etc/init.d/samba restart<br />
<br />
Una vez realizado esto, deberá ser posible acceder al recurso compartido.<br />
<br />
<br />
Espero te sea de utilidad !<br />
<br />
<br />
<br />
<br />
Referencias:<br />
<a href="http://ubuntuforums.org/showthread.php?t=1208528">http://ubuntuforums.org/showthread.php?t=1208528</a><br />
<a href="http://www.guia-ubuntu.com/index.php?title=Samba#Para_compartir_una_carpeta">http://www.guia-ubuntu.com/index.php?title=Samba#Para_compartir_una_carpeta</a>omaryahirhttp://www.blogger.com/profile/02913617573866847918noreply@blogger.com0tag:blogger.com,1999:blog-7760301152455629036.post-41317646105109317502014-04-22T12:21:00.003-07:002014-04-22T12:21:47.156-07:00Instalación OpenSUSE 13.1 - VirtualEnv - Python - Django - MySQLComo parte de un proyecto en mi trabajo es necesario utilizar django dentro de opensuse, para lo cuál realizaremos lo siguiente:<br />
<br />
<b>1. Instalación de VirtualEnv</b><br />
Utilizando la terminal ejecutamos:<br />
<span style="background-color: black;"><span style="color: white;">> sudo zypper install python-virtualenv </span></span><br />
<div>
NOTA: Será necesario tener instalado zypper en caso de no tenerlo a travéz de Yast.</div>
<div>
<br /></div>
<div>
<b>2. Iniciar el proyecto con virtualenv</b></div>
<div>
Utilizando los siguientes comandos ...</div>
<div>
<span style="background-color: black; color: white;">> mkdir miproyecto </span></div>
<div>
<span style="background-color: black; color: white;">> virtualenv vmp </span></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<b>3. Instalar el soporte de Mysql</b></div>
<div>
Para instalar el soporte de MySQL es importante considerar tener el MySQL instalado, para instalar en OpenSUSE puede ser la siguiente guía: <a href="http://omaryahir.blogspot.mx/2014/04/opensuse-131-y-mysql.html">http://omaryahir.blogspot.mx/2014/04/opensuse-131-y-mysql.html</a></div>
<div>
<br /></div>
<div>
Una vez que el MySQL se encuentra instalado ejecutamos:</div>
<div>
<span style="background-color: black; color: white;">> sudo zypper instal</span><span style="background-color: black;"><span style="color: white;">l </span><span style="color: white;">python-devel</span><span style="color: white;"> </span></span></div>
<div>
<span style="background-color: black; color: white;">> sudo zypper install </span><span style="background-color: black; color: white;">libmysqlclient-devel</span><span style="background-color: black; color: white;"> </span></div>
<div>
<span style="background-color: black; color: white;">> sudo zypper install gcc</span><span style="background-color: black; color: white;"> </span></div>
<div>
<br /></div>
<div>
<div>
<b>4. Activamos la maquina e instalamos django</b></div>
<div>
Con el punto anterior tenemos una maquina virtualenv con nombre vmp por lo que la activaremos con los siguientes comandos para instalar la versión más reciente de django y el soporte de mysql.</div>
<div>
<div>
<span style="background-color: black; color: white;">> source vmp/bin/activate </span></div>
<div>
<span style="background-color: black; color: white;">(vmp) > pip install django </span></div>
</div>
</div>
<div>
<span style="background-color: black; color: white;">(vmp) > pip install mysql-python </span></div>
<div>
<br /></div>
<div>
Con lo anterior debe de poder funcionar correctamente django con soporte MySQL en OpenSUSE.</div>
<div>
<br /></div>
<div>
Espero te sea de utilidad !</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
Referencias:</div>
<div>
<a href="http://unix.stackexchange.com/questions/73543/gcc-not-found-when-installing-mysqldb-for-django-1-4">http://unix.stackexchange.com/questions/73543/gcc-not-found-when-installing-mysqldb-for-django-1-4</a></div>
<div>
<a href="https://www.npmjs.org/package/mysql-libmysqlclient">https://www.npmjs.org/package/mysql-libmysqlclient</a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
omaryahirhttp://www.blogger.com/profile/02913617573866847918noreply@blogger.com0tag:blogger.com,1999:blog-7760301152455629036.post-51460854334000474102014-04-17T23:47:00.001-07:002014-04-17T23:47:49.447-07:00OpenSUSE 13.1 y MySQLHaciendo pruebas con OpenSUSE 13.1 me doy cuenta de que viene precargado mariadb y no lograba activar y habilitar el MySQL, me funciono realizando lo siguiente:<br />
<br />
<b>1</b>. Instalar a traves de YaST mysql-community-server; esto implicará que el mismo YaST solicite desinstalar mariadb-server y mariadb-client; se debe autorizar la desinstalación ya que la versión mariadb que viene preinstalada en OpenSUSE 13.1 no es compatible con MySQL 5.6.<br />
<br />
<b>2</b>. Una vez instalado mysql-community-server se debe crear un archivo usando el siguiente comando:<br />
<ol><ul>
<li>sudo vi /lib/systemd/system/mysqld.service </li>
</ul>
</ol>
<ol><ul>
<li>El contenido del archivo debe ser el siguiente:</li>
</ul>
</ol>
<blockquote class="tr_bq">
<blockquote class="tr_bq">
<pre><code>[Unit]
Description=MySQL Server
After=network.target
[Service]
Type=forking
ExecStart=/etc/rc.d/mysql start
ExecStop=/etc/rc.d/mysql stop
[Install]
WantedBy=multi-user.target</code></pre>
</blockquote>
</blockquote>
<br />
<b>3</b>. Posteriormente usar el siguiente comando:<br />
<ul><ul>
<li><code>sudo systemctl daemon-reload</code> <br /><code></code><code></code></li>
</ul>
</ul>
<b>4</b>. Entrar nuevamente a YaST en la sección de System, y luego en Service Manager localizar mysqld y habilitar el servicio.<br />
<br />
<b>5</b>. Posteriormente cerrar el YaST y en la terminal teclear:<br />
<ul><ul>
<li><code>sudo mysql_secure_installation</code></li>
</ul>
</ul>
<blockquote class="tr_bq">
<blockquote class="tr_bq">
<code>Esta opción solicitará la contraseña del root, si es la primera vez que se ejecuta es en blanco; posteriormente solicitará algunos datos de la instalación.</code></blockquote>
</blockquote>
<b>6</b>. Finalmente regresar a YaST nuevamente a System y Service Manager localizar mysqld e indicar que debe iniciar el servicio.<br />
<br />
<br />
De esa forma me funciono, espero te sea de utilidad !!! <br />
<br />
<br />
Referencias:<br />
<a href="http://superuser.com/questions/384365/systemctl-enable-differs-from-systemctl-start-how">http://superuser.com/questions/384365/systemctl-enable-differs-from-systemctl-start-how</a> <br />
<a href="http://en.opensuse.org/SDB:MySQL_installation">http://en.opensuse.org/SDB:MySQL_installation</a><br />
<a href="https://bugzilla.novell.com/show_bug.cgi?id=846422">https://bugzilla.novell.com/show_bug.cgi?id=846422</a><br />
<a href="https://bugzilla.novell.com/show_bug.cgi?id=840159">https://bugzilla.novell.com/show_bug.cgi?id=840159</a><br />
<br />
<pre><code>
</code></pre>
omaryahirhttp://www.blogger.com/profile/02913617573866847918noreply@blogger.com2tag:blogger.com,1999:blog-7760301152455629036.post-32734163520690588172014-03-17T19:18:00.003-07:002014-03-17T19:18:43.238-07:00VirtualEnv + Python MySQL error: command 'cc' failed with exit status 1 Mac OSXTratando de usar Django + MySQL dentro de virtualenv, en un entorno Mac OSX Mavericks, al parecer el procedimiento previo que había seguido ya no funciona igual; al correr el comando sudo pip install mysql-python, me genera el siguiente error: <br />
<br />
<b>error: command 'cc' failed with exit status 1</b><br />
<br />
La forma en como lo solucione fue la siguiente:<br />
<br />
Instale el XCode desde la AppStore, no se si este se encuentre gratuito ya que hace ya un tiempo lo había comprado.<br />
<br />Posteriormente utiizando el comando:<br /><span style="background-color: #cccccc;">$ vi ~/.bash_profile </span><br /><br />
Agregue los siguientes parametros: <br />
<pre class="lang-py prettyprint prettyprinted"><span style="color: white;"><span style="background-color: black;"><code><span class="pln">export CFLAGS</span><span class="pun">=-</span><span class="typ">Qunused</span><span class="pun">-</span><span class="pln">arguments
export CPPFLAGS</span><span class="pun">=-</span><span class="typ">Qunused</span><span class="pun">-</span><span class="pln">arguments</span></code></span></span></pre>
<pre class="lang-py prettyprint prettyprinted"><code><span class="pln"> </span></code></pre>
Una vez realizado lo anterior ahora si utilizando el comando:<br />
<span style="background-color: #cccccc;">$ pip install mysql-python</span><br />
<br />
Quedará instalado; es probable que salgan algunos warnings, sin embargo deberá ser posible utilizarlo para desarrollar.<br />
<br />
<br />Espero te sea de utilidad !<br />
<br />
<br />
<br />
Referencias:<br />
<a href="http://stackoverflow.com/questions/19769648/cant-install-discount-with-pip-error-command-cc-failed-with-exit-status-1">http://stackoverflow.com/questions/19769648/cant-install-discount-with-pip-error-command-cc-failed-with-exit-status-1</a><br />
<a href="http://stackoverflow.com/questions/22413050/cant-install-python-mysql-library-on-mac-mavericks?lq=1">http://stackoverflow.com/questions/22413050/cant-install-python-mysql-library-on-mac-mavericks?lq=1</a>omaryahirhttp://www.blogger.com/profile/02913617573866847918noreply@blogger.com0tag:blogger.com,1999:blog-7760301152455629036.post-20433716327984399712014-01-15T09:36:00.001-08:002014-05-30T09:58:12.559-07:00Copiar archivos vía ssh (Amazon) utilizando el archivo .pem<br />
Bien este post es de solo una instrucción sin embargo considere importante dejarlo aquí para no andarlo buscando posteriormente ya que el comando no me funcionaba, se trata de copiar un archivo desde el equipo al servidor vía ssh utilizando un archivo pem especificamente lo estoy haciendo con un servidor Amazon EC2, les dejo el comando:<br />
<br />
<b><strike>$scp -i /Ruta/al/archivo.pem -P [puerto] arch_origen.txt root@[IP]:/ruta/destino/arch_destino.txt</strike></b><br />
<br />
Con esto copiará el archivo arch_origen.txt en la carpeta donde se esta corriendo el comando y lo dejará en la /ruta/destino/ con el nombre arch_destino.txt<br />
<br />
<br />
CORRECCIÓN 2014-05-30<br />
<br />
Tenía un error en el acomodo del comando:<br />
<b>$scp -i /Ruta/al/archivo.pem -P [puerto] </b><b>root@[IP]:/ruta/origen/</b><b>arch_origen.txt /ruta/destino/arch_destino.txt</b><br />
<div>
<br /></div>
<div>
Por otro lado si deseas copiar un directorio entonces:</div>
<div>
<b>$scp -i /Ruta/al/archivo.pem -P [puerto] -r </b><b>root@[IP]:/ruta/origen </b><b> /ruta/destino</b></div>
<br />
<br />
<br />
Espero te sea de utilidad !<br />
<br />
<br />
Referencias:<br />
<a href="http://www.howtogeek.com/66776/how-to-remotely-copy-files-over-ssh-without-entering-your-password/">http://www.howtogeek.com/66776/how-to-remotely-copy-files-over-ssh-without-entering-your-password/</a><br />
<a href="http://stackoverflow.com/questions/11388014/using-scp-to-copy-a-file-to-amazon-ec2-instance">http://stackoverflow.com/questions/11388014/using-scp-to-copy-a-file-to-amazon-ec2-instance</a><br />
<a href="http://www.hypexr.org/linux_scp_help.php">http://www.hypexr.org/linux_scp_help.php</a><br />
<a href="http://superuser.com/questions/188411/ssh-why-doesnt-get-command-work">http://superuser.com/questions/188411/ssh-why-doesnt-get-command-work</a>omaryahirhttp://www.blogger.com/profile/02913617573866847918noreply@blogger.com3