Running application using cherryd

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Running application using cherryd

Cherrypy-noob
Hi all,

so as my username says I'm new to cherrypy and also in general linux and linux administration.

I have created my simple cherrypy application which is is simple and consists of 1 python file. It needs to run in a specific virtualenv and is running behind apache using mod_proxy. This work but I have to start cherrypy app manually.

The goal is now automating the start/stop of cherrypy application. I wanted to play with cherryd but I'm not getting how I can tell it to load my specific application (eg. python file).

Is this the imports option? If yes how do I need to configure my app? Use quickstart or tree.mount? Do I put that at start of module or leave it in  if __name__ == '__main__':?




--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Running application using cherryd

Cherrypy-noob
After a lot of trial and error and some research I came to following most simple solution.

I use Ubuntu 16.04 which by default uses systemd. So the solution is to create a systemd service. Advantage being that you do not need any daemonizing or forking.

In

/lib/systemd/system

create a file called cherrypy.service (or whatever you want to call it). Add to that file following info:

    [Unit]
    Description=Cherrypy Web Server

    [Service]
    Type=simple
    WorkingDirectory=/path/to/cwd
    ExecStart=/path/to/cherrpy/script.py

    [Install]
    WantedBy=multi-user.target

Run commands:

sudo systemctl daemon-reload
sudo systemctl enable cherrypy.service

If you now reboot your cherrypy application should start automatically at boot.

You can manually start/stop the service with

sudo systemctl start cherrypy
sudo systemctl stop cherrypy

You do not need to add any daemonzing code to your application.
An interesting "trick" is to add

#!/path/to/virtualenv/bin/python

to the top of your script/application file. This way your desired virtualenv is used for running the script

Hope this helps other people new to this to get this up and running quick and simple.


On Thursday, March 16, 2017 at 2:29:36 PM UTC+1, Cherrypy-noob wrote:
Hi all,

so as my username says I'm new to cherrypy and also in general linux and linux administration.

I have created my simple cherrypy application which is is simple and consists of 1 python file. It needs to run in a specific virtualenv and is running behind apache using mod_proxy. This work but I have to start cherrypy app manually.

The goal is now automating the start/stop of cherrypy application. I wanted to play with cherryd but I'm not getting how I can tell it to load my specific application (eg. python file).

Is this the imports option? If yes how do I need to configure my app? Use quickstart or tree.mount? Do I put that at start of module or leave it in  if __name__ == '__main__':?




--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Running application using cherryd

Michiel Overtoom
Hi Joos,

> On 2017-03-20, at 13:00, Cherrypy-noob <[hidden email]> wrote:
>
> After a lot of trial and error and some research I came to following most simple solution. [...]

Thanks for sharing.

If you configure your webapp this way, is it run using test-develop or production environment settings?

Greetings,

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Running application using cherryd

Cherrypy-noob
Hi Michiel,

you got me there. I don't know. Whatever is default unless you specific differently in your app:

cherrypy.config.update({'environment' : 'production'}))
As far as I understood it, environment only changes some defaults for the config like no traceback on webpage in production. Setting it in the app is not ideal but the app/script could read in the config file and have it as a input parameter so you can define the config by config file and not within the app (makes more sense).

Another option is to use cherryd and then set that to autostart on boot with systemd or other tool. For systemd you for sure need to adjust settings (type=forking) and maybe more and adjust your script (quickstart won't work).





On Monday, March 20, 2017 at 5:34:03 PM UTC+1, Michiel Overtoom wrote:
Hi Joos,

> On 2017-03-20, at 13:00, Cherrypy-noob <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="UYQrGFSkEgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">joos....@...> wrote:
>
> After a lot of trial and error and some research I came to following most simple solution. [...]

Thanks for sharing.

If you configure your webapp this way, is it run using test-develop or production environment settings?

Greetings,

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.
Loading...