a python web application on an Unbuntu server using apache2
Discussion
Hi,
We are using Digital Ocean to deploy our software which is connected to our GitHub. However, when we shut the terminal after we have deployed it the server shuts and doesn't allow for users to sign up or login - strange because other parts work.
We have tried using daemon to keep the server running in the background when the terminal has been shut, however, this causes a problem with the login and messes with our username and password system.
Does anyone have experience with this sort of thing?
Regards
EDIT: Ubuntu not Unbuntu.
We are using Digital Ocean to deploy our software which is connected to our GitHub. However, when we shut the terminal after we have deployed it the server shuts and doesn't allow for users to sign up or login - strange because other parts work.
We have tried using daemon to keep the server running in the background when the terminal has been shut, however, this causes a problem with the login and messes with our username and password system.
Does anyone have experience with this sort of thing?
Regards
EDIT: Ubuntu not Unbuntu.
Apache2 should be running as a service and being SSH'd in shouldn't affect it.
SSH in and run systemctl status apache2. Is it running OK?
Have for some reason you're devs have set the Apache2 application to run upon a user login or something mental?
ETA: If everything else works it is unlikely apache2, what is your DB running as?
Run ps aux| grep mysql / postgres / mongodb or whatever your DB engine is. Then check out the conf files for it - is it registered as a service / daemon?
SSH in and run systemctl status apache2. Is it running OK?
Have for some reason you're devs have set the Apache2 application to run upon a user login or something mental?
ETA: If everything else works it is unlikely apache2, what is your DB running as?
Run ps aux| grep mysql / postgres / mongodb or whatever your DB engine is. Then check out the conf files for it - is it registered as a service / daemon?
No idea about your explicit case, but ISTR that on unixy systems, in order to get a program to stay running after you log off, the program needs to close down stdin and stdout.
Perl has a "daemonize" function to do this.
What you could try doing is redirecting input and output to /dev/null. Something like:
./program > /dev/null < /del/null &
Then you can close the terminal, and it shpuld run.
Not done this for a while though!
Perl has a "daemonize" function to do this.
What you could try doing is redirecting input and output to /dev/null. Something like:
./program > /dev/null < /del/null &
Then you can close the terminal, and it shpuld run.
Not done this for a while though!
Taita said:
Apache2 should be running as a service and being SSH'd in shouldn't affect it.
SSH in and run systemctl status apache2. Is it running OK?
Have for some reason you're devs have set the Apache2 application to run upon a user login or something mental?
ETA: If everything else works it is unlikely apache2, what is your DB running as?
Run ps aux| grep mysql / postgres / mongodb or whatever your DB engine is. Then check out the conf files for it - is it registered as a service / daemon?
SSH in and run systemctl status apache2. Is it running OK?
Have for some reason you're devs have set the Apache2 application to run upon a user login or something mental?
ETA: If everything else works it is unlikely apache2, what is your DB running as?
Run ps aux| grep mysql / postgres / mongodb or whatever your DB engine is. Then check out the conf files for it - is it registered as a service / daemon?
Good point about the databases, but the thing is, sometimes the user can log in and sometimes they can't. Its not a constant issue, it goes and comes when it likes - which makes it a pain to track.
But we use SQLite for our DBs and I can't find it when I do ps aux.
If I understand correctly - you have a Python app that you start, and then when logging out / disconnecting from the server, the app stops?
If so, any foreground app will simply exit as soon as you terminate the shell it was started in.
Try starting your app with 'nohup'
e.g. nohup python_app.py > /dev/null 2>&1 &
You could also try: python_app.py > /dev/null 2>&1 & (this should put it in the background)
Alternately, install screen (screen will provide you with a shell process that doesn't terminate when logging out / disconnecting form the server).
If so, any foreground app will simply exit as soon as you terminate the shell it was started in.
Try starting your app with 'nohup'
e.g. nohup python_app.py > /dev/null 2>&1 &
You could also try: python_app.py > /dev/null 2>&1 & (this should put it in the background)
Alternately, install screen (screen will provide you with a shell process that doesn't terminate when logging out / disconnecting form the server).
TonyRPH said:
If I understand correctly - you have a Python app that you start, and then when logging out / disconnecting from the server, the app stops?
If so, any foreground app will simply exit as soon as you terminate the shell it was started in.
Try starting your app with 'nohup'
e.g. nohup python_app.py > /dev/null 2>&1 &
You could also try: python_app.py > /dev/null 2>&1 & (this should put it in the background)
Alternately, install screen (screen will provide you with a shell process that doesn't terminate when logging out / disconnecting form the server).
Ohhhh mate, where can we meet? I want to buy you a pint If so, any foreground app will simply exit as soon as you terminate the shell it was started in.
Try starting your app with 'nohup'
e.g. nohup python_app.py > /dev/null 2>&1 &
You could also try: python_app.py > /dev/null 2>&1 & (this should put it in the background)
Alternately, install screen (screen will provide you with a shell process that doesn't terminate when logging out / disconnecting form the server).


python app.py > /dev/null 2>&1 &
That worked!
Massive thanks to everyone for the responses.
Happy to help.
If this Python app is web facing, you might want to consider running it as a non privileged user, if not doing so already.
According to this page on Stackoverflow, you can also launch Python apps as daemons using systemd.
If this Python app is web facing, you might want to consider running it as a non privileged user, if not doing so already.
According to this page on Stackoverflow, you can also launch Python apps as daemons using systemd.
Stackoverflow said:
[Unit]
Description=Python daemon
After=syslog.target
After=network.target
[Service]
Type=simple
User=<run as user>
Group=<run as group group>
ExecStart=/usr/bin/python <python script home>/script.py
# Give the script some time to startup
TimeoutSec=300
[Install]
WantedBy=multi-user.target
Description=Python daemon
After=syslog.target
After=network.target
[Service]
Type=simple
User=<run as user>
Group=<run as group group>
ExecStart=/usr/bin/python <python script home>/script.py
# Give the script some time to startup
TimeoutSec=300
[Install]
WantedBy=multi-user.target
Thanks for the replies.
I am definitely looking into this, we're just working on a few features then I'll sit down to make it a service.
I am running the Linux through Git Bash right now, so going forward I should probably install Ubuntu before I go ahead further. The amount of Linux I still need to learn is huge though.
I've learned all this in 1 day just to deploy our software, but I am looking into this more and more in my spare time.
I am definitely looking into this, we're just working on a few features then I'll sit down to make it a service.
I am running the Linux through Git Bash right now, so going forward I should probably install Ubuntu before I go ahead further. The amount of Linux I still need to learn is huge though.
I've learned all this in 1 day just to deploy our software, but I am looking into this more and more in my spare time.
CasioPasio said:
Thanks for the replies.
I am definitely looking into this, we're just working on a few features then I'll sit down to make it a service.
I am running the Linux through Git Bash right now, so going forward I should probably install Ubuntu before I go ahead further. The amount of Linux I still need to learn is huge though.
I've learned all this in 1 day just to deploy our software, but I am looking into this more and more in my spare time.
Sounds like an odd position whereby you've got people adding features to something but the deployment mechanism is down to you.I am definitely looking into this, we're just working on a few features then I'll sit down to make it a service.
I am running the Linux through Git Bash right now, so going forward I should probably install Ubuntu before I go ahead further. The amount of Linux I still need to learn is huge though.
I've learned all this in 1 day just to deploy our software, but I am looking into this more and more in my spare time.
Aren't your developers involved in how their software is deployed?
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff


