How to properly reconnect via SSH after screen detached - python

I'm working on a Django project that is hosted in a remote server, and in my work we connect through a computer which has Mobaxterm. The thing is, I'm not at all experienced, and the connection broke (or I broke it, I don't know), and then I wrote screen -r -d which is what I used to use to make the git pull and then the supervisorctl restart just to apply the changes I did on my local project.
After the disconnection, it said there were no screens to detach, so after searching online, I managed to get into a screen, and then made my way to the correct path so that I could do python manage.py etc..., and I activated the virtualenv.
The thing is, I'm having errors I didn't have, so I don't know if I have to do something else. For example, when I try to do python manage.py showmigrations , I get an error saying:
FileNotFoundError: [Errno 2] No such file or directory: '/webapps/project_name/app_name/logs/dialogflow.log'
And different errors occur when I do python manage.py makemigrations , python manage.py migrate, etc. What could the last screen I was working on had and not this one? My ex-coworker, who set everything up before I arrived, hasn't answered, or I'd like at least a clue about how to troubleshoot this, because I'm lost.
Any help would be amazing.

A co-worker helped me via remote, and we got the problem. I had to also run postactivate from the virtualenv, after the activate.

Related

What is the terminal script to run CoAP server

Im trying to run this CoAP server from https://github.com/Tanganelli/CoAPthon on a raspberry pi. i cant seem to find much instructions. This was one of the CoAP that my instructor wanted us to use, my instructor pretty much left us hanging with no help at all but this link.
i followed the install instructions on the github page, the only thing that wouldnt install is the section
Install instructions for CoRE Resource Directory. Mongod wouldnt install for this section so i gave up. so i dont know if this section is important or not
What are the commands for the terminal to get it running and doing something.
it says to type in to run the server coapserver.py.
cd CoAPthon
python coapserver.py
and from what it looks like its running
but nothing happens, so im not sure if its just not working or if theres just nothing there for it to do, or if there is another file i need to run with the coapserver.py.
Im very new to using CoAP and will eventually need to add a sensor to it do record temp but i want to make sure i know the server is running properly before i add that part in
any input would be great
For future individuals that might need help with this, use aioCoAP, its much easier then CoAPthon
get it from here https://aiocoap.readthedocs.io/en/latest/installation.htmlg
all you need to do is mess with three files labeled server.py, clientPUT.py and clientGET.py
Add resources and classes for sensors and what not to server.py
ClientPUT.py is where you would add your code for the sensors or whatever you need.
ClinetGET.py you alter the uri
run it by type in the command in the terminal (go to directory first that has the server) type in python server.py
in another terminal do the same thing but instead run python clientPUT.py
and the server should be running
then all you need is a client for the get request. If you were like me and needed to use Copper go here to install it for chrome https://github.com/mkovatsc/Copper4Cr

Git bash "Watching for file changes with StatReloader" stuck and never loads

I have setup a Django project on a virtual environment on my PC. When using the command
python manage.py runserver 0.0.0.0:8000
Bit Bash stops doing anything and I have to end the program to start over. I have waited several minutes and when I end the session, a dialogue says:
Processes are running in session:
WPID PID COMMAND
14904 1534 c:\Users\mine\AppData\Loca
Close anyway?
I have looked at every related question to this and tried every solution but I cannot get this to work, on or off the virtual environment.
Not sure if this applies, but I also noticed that in my task manager, python3.9.exe appears twice when trying to start the server. The status says running, and the PIDs are different numbers.
This is because something already running on port 8000. You can run the Django server by hosting on another port like 8080 but, you can also kill the already running task on the port. Follow the link to know how exactly you can kill any running process.
It is highly likely that another application is running using the port 8000. Try running the server using another port, say 8088 and share if the same issue persists.
To run on specific port kill all pids which is showing you on Git bash
(ps -ef)... kill them using (kill -9 pid_no)... then run your runserver command.
Ex:
ps -ef
kill -9 123
I ended up paying someone to fix this. Here is the conversation I had with the person who found the issue. Hope this helps someone out there.
Also, I noticed sometimes it still does freeze up on the watching for file changes with StateReloader until I go the browser and type in http://localhost:8000/. Once I do that the rest of the text loads and my browser shows The install worked successfully! Congratulations!
it works, what did you do?
- We have existing processes on port 8000.I think, you had the server running and kept trying over and over. So, I killed process using 8000 port.
- Next, I run Django project again.
- So, now it's working well.
ok. Can you tell me what you did at the start to make it work? Or was it always working?
- I started git bash session again when I started. Maybe git bash session had problems.
But this was going on for a day, I restarted the computer several times and restarted git bash. Same issue.
You must have done something.
- Sorry, I didn't do anything except restart git bash
how did you restart it?
- right click top of window, select NEW
How do I turn server off?
- press Ctrl + C
- And you didn't quit the server exactly before. Maybe you closed git bash directly and server was still live
- So, we had many 8000 ports.
Ok. How can I see what is on that port now?
- You can use this cli
- netstat -ano | findstr :<PORT>
- We don't have running 8000 port now.
I have never found solutions to this problem even with killing ports, changing port etc.
It never display the following part:
Starting development server at http://127.0.0.1:8000/
However, when I use the Git Bash terminal include into vscode, it displays the url.
Terminal > New Terminal > then:
Result :
python manage.py runserver 127.0.0.1:8080

How do I allow permissions so that i can run my python server?

I was trying to practice using django,
when I executed python3 manage.py runserver, I received a permission denied when trying and I'm not sure what that means.
I have seen this before, but I am not sure how I would be able to allow permissions. I thought I enabled everything in start up but I feel I am missing something.
I will post a picture here from when I went into the folder I started and tried to run the server.
have you tried using sudo before the "python3 ..." command?
(I can't add this to comments due to my low reputation)

Django runserver under Jenkins does not work

I have created a script to build my Django project which is called by my Jenkins CI, every time a push is made.
The script runs just fine if I run it manually, but fails to start the web server when it is ran automatically.
No errors are thrown, but the last line of the script:
nohup python manage.py runserver 0:9000 > /dev/null 2>&1 &
has absolutely no effect.
I am 100% sure that the script is ran as jenkins user, under my virtualenv, so that's not the problem. Also, permissions are not a problem, I have checked. Like I said, no error is thrown, so I don't really know what is happening.
Any ideas ?
So, thanks to tomrom95 I found the solution : adding BUILD_ID=dontKillMe in front of the command fixed everything. It's kind of funny.
Here is the link to a more complete answer to why this didn't work and why it works now.

How do I run Django as a service?

I am having difficulty running Django on my Ubuntu server. I am able to run Django but I don't know how to run it as a service.
Distributor ID: Ubuntu
Description: Ubuntu 10.10
Release: 10.10
Codename: maverick
Here is what I am doing:
I log onto my Ubuntu server
Start my Django process: sudo ./manage.py runserver 0.0.0.0:80 &
Test: Traffic passes and the app displays the right page.
Now I close my terminal window and it all stops. I think I need to run it as a service somehow, but I can't figure out how to do that.
How do I keep my Django process running on port 80 even when I'm not logged in?
Also, I get that I should be linking it through Apache, but I'm not ready for that yet.
Don't use manage.py runserver to run your server on port 80. Not even for development. If you need that for your development environment, it's still better to redirect traffic from 8000 to 80 through iptables than running your django application as root.
In django documentation (or in other answers to this post) you can find out how to run it with a real webserver.
If, for any other reason you need a process to keep running in background after you close your terminal, you can't just run the process with & because it will be run in background but keep your session's session id, and will be closed when the session leader (your terminal) is terminated.
You can circunvent this behaviour by running the process through the setsid utility. See your manpage for setsid for more details.
Anyway, if after reading other comments, you still want to use the process with manage.py, just add "nohup" before your command line:
sudo nohup /home/ubuntu/django_projects/myproject/manage.py runserver 0.0.0.0:80 &
For this kind of job, since you're on Ubuntu, you should use the awesome Ubuntu upstart.
Just specify a file, e.g. django-fcgi, in case you're going to deploy Django with FastCGI:
/etc/init/django-fcgi.conf
and put the required upstart syntax instructions.
Then you can you would be able to start and stop your runserver command simply with:
start runserver
and
stop runserver
Examples of managing the deployment of Django processes with Upstart: here and here. I found those two links helpful when setting up this deployment structure myself.
The problem is that & runs a program in the background but does not separate it from the spawning process. However, an additional issue is that you are running the development server, which is only for testing purposes and should not be used for a production environment.
Use gunicorn or apache with mod_wsgi. Documentation for django and these projects should make it explicit how to serve it properly.
If you just want a really quick-and-dirty way to run your django dev server on port 80 and leave it there -- which is not something I recommend -- you could potentially run it in a screen. screen will create a terminal that will not close even if you close your connection. You can even run it in the foreground of a screen terminal and disconnect, leaving it to run until reboot.
If you are using virtualenv,the sudo command will execute the manage.py runserver command outside of the virtual enviorment context, and you'll get all kind of errors.
To fix that, I did the following:
while working on the virtual env type:
which python
outputs: /home/oleg/.virtualenvs/openmuni/bin/python
then type:
sudo !!
outputs: /usr/bin/python
Then all what's left to do is create a symbolic link between the global python and the python at the virtualenv that you currently use, and would like to run on 0.0.0.0:80
first move the global python folder to a backup location:
mv /usr/bin/python /usr/bin/python.old
/usr/bin/python
that should do it:
ln -s /usr/bin/python /home/oleg/.virtualenvs/openmuni/bin/python
that's it! now you can run sudo python manage.py runserver 0.0.0.0:80 in virtaulenv context!
Keep in mind that if you are using postgres DB on your developement local setup, you'll probably need a root role.
Credit to #ydaniv

Categories

Resources