Re: Running application using cherryd
Cherrypy-noob <[email protected]> Mon, 20 Mar 2017 05:00:24 -0700 (PDT)
| Newsgroups | gmane.comp.python.cherrypy |
|---|---|
| Message-ID | <[email protected]> |
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 cherrypy-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
To post to this group, send email to cherrypy-users-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.