New relic + gunicorn + https issues - https

I am currently using new relic to monitor my web app. In my deploy script i have the following
sudo NEW_RELIC_CONFIG_FILE=/<path to app>/app/config/newrelic.ini newrelic-admin run-program gunicorn 'run:run_app' -b 0.0.0.0:8000 -w3 --certfile=/<path to app>/app/config/server.crt --keyfile=/<path to app>/app/config/server.key --access-logfile log/gunicorn.log
The idea here is to allow for https. When testing locally I can get the https working with
sudo gunicorn 'run:run_app' -b 0.0.0.0:5000 -w3 --certfile=app/config/server.crt --keyfile=app/config/server.key --access-logfile gunicorn.log
And the debugger shows
[INFO] Listening at: https://0.0.0.0:5000 (4691)
in the local case, and
[INFO] Listening at: http://0.0.0.0:8000 (9094)
on the server.
I've tried everything I could think of and think that this must be a problem in New Relic overriding something?

This isn't quite enough information to go on. You might want to open a ticket at https://support.newrelic.com so that New Relic can investigate this at length.

Related

Shiny server not working . Gives ERR_CONNECTION_TIMED_OUT

I had issues installing shiny-server in ubuntu 20.04 running on an AWS EC2. Finally i figured out a way to install it from the source. Seems to have installed ok but when i go to https://<xxx>.amazonaws.com:3838/<appname>, it doesn't load up the page. Instead, it gives this error
This site can't be reached.
<xxx>.amazonaws.com took too long to respond.
ERR_CONNECTION_TIMED_OUT
I gave sudo shiny-server and got this
[2021-02-02T17:30:37.418] [INFO] shiny-server - Shiny Server v1.5.16.0 (Node.js v12.20.1)
[2021-02-02T17:30:37.420] [INFO] shiny-server - Using config file "/etc/shiny-server/shiny-server.conf"
[2021-02-02T17:30:37.459] [WARN] shiny-server - Running as root unnecessarily is a security risk! You could be running more securely as non-root.
[2021-02-02T17:30:37.462] [INFO] shiny-server - Starting listener on http://[::]:3838
So that seems to be working fine.
I checked the security groups on EC2 and made sure it allows all inbound connections to port 3838.

How to look Gunicorn logs when it running?

I deployed a Flask application to a VPS, and using Gunicorn as a web server.
And I running the Gunicorn server using this command:
gunicorn --bind=0.0.0.0 run:app --access-logfile '-'
With the command I can see the log running. But after I closed my terminal session, I want to see the running logs again.
In Heroku I can use heroku logs -t to do that, any similar way to see it on Gunicorn..?
You need to set up the supervisor. Supervisor keeps your server running mode and saves your log. setup the supervisor file below and then you can see the logs:
[program:your_project_name]
command=/home/your_virualenv/bin/gunicorn --log-level debug
run_apiengine:main_app --bind 0.0.0.0:5007 --workers 2 --worker-class gevent
directory=your_project_directory
stdout_logfile= your_log_folder_path/supervisor_stdout.log
stderr_logfile= your_log_folder_path/supervisor_stderr.log
user=your_user
autostart=true
PYTHONPATH="$PYTHONPATH:your_python_path";OAUTHLIB_INSECURE_TRANSPORT='1';

configure sinatra as a server

I have written an app in ruby using sinatra. the app works fine and I am testing the post/get request using postman.
Right now I start the app using the command rackup but it starts the server locally on the port 9292. using postman, I send the POST on localhost:9292
I would like to test the app when access from another computer. I expect something using POSTMAN sending a POST on http://182.12.34.1:9292 but I didn't find how to do this.
config.ru
load './app/init.rb'
run Sinatra::Application
Procfile
web: bundle exec unicorn -p $PORT -E $RACK_ENV -c ./config/unicorn.rb
Any idea, how to switch from local test to a server ?
Thansks
The easiest way is to use an existing tool like ngrok or localtunnel.
If you have npm installed, then you can do this in a new terminal:
sudo npm install -g localtunnel
lt --port 9292
It will then give you a URL that you can share. Keep in mind these two things:
The URL is only valid as long as the localtunnel process is running
You still need to have your server running on localhost:9292 for it to work.
Did you perhaps listen to localhost only in the config?
You need to bind the host to 0.0.0.0 otherwise it will only only be available locally...

Hooking up into running heroku phoenix application

Previous night I was tinkering with Elixir running code on my both machines at home, but when I woke up, I asked myself Can I actually do the same using heroku run command?
I think theoretically it should be entirely possible if setup properly. Obviously heroku run iex --sname name executes and gives me access to shell (without functioning backspace which is irritating) but i haven't accessed my app yet.
Each time I executed the command it gave me different machine. I guess it's how Heroku achieve sandbox. I also was trying to find a way to determine address of my app's machine but haven't got any luck yet.
Can I actually connect with the dyno running the code to evaluate expressions on it like you would do iex -S mix phoenix.server locally ?
Unfortunately it's not possible.
To interconnect Erlang VM nodes you'd need EPMD port (4369) to be open.
Heroku doesn't allow opening custom ports so it's not possible.
In case You'd want to establish a connection between your Phoenix server and Elixir node You'd have to:
Two nodes on the same machine:
Start Phoenix using iex --name phoenix#127.0.0.1 -S mix phoenix.server
Start iex --name other_node#127.0.0.1
Establish a connection using Node.ping from other_node:
iex(other_node#127.0.0.1)1> Node.ping(:'phoenix#127.0.0.1')
(should return :pong not :pang)
Two nodes on different machines
Start Phoenix using some external address
iex --name phoenix#195.20.2.2 --cookie someword -S mix phoenix.server
Start second node
iex --name other_node#195.20.2.10 --cookie someword
Establish a connection using Node.ping from other_node:
iex(other_node#195.20.2.10)1> Node.ping(:'phoenix#195.20.2.2')
(should return :pong not :pang)
Both nodes should contact each other on the addresses they usually see each other on the network. (Full external IP when different networks, 192.168.X.X when in the same local network, 127.0.0.1 when on the same machine)
If they're on different machines they also must have set the same cookie value, because by default it takes automatically generated cookie in your home directory. You can check it out by running:
cat ~/.erlang.cookie
What's last you've got to make sure that your EPMD port 4369 is open, because Erlang VM uses it for internode data exchange.
As a sidenote if you will leave it open make sure to make your cookie as private as possible, because if someone knows it, he can have absolute power over your machine.
When you execute heroku run it will start a new one-off dyno which is a temporary instance that is deprovisioned when you finish the heroku run session. This dyno is not a web dyno and cannot receive inbound HTTP requests through Heroku's routing layer.
From the docs:
One-off dynos can never receive HTTP traffic, since the routers only route traffic to dynos named web.N.
https://devcenter.heroku.com/articles/one-off-dynos#formation-dynos-vs-one-off-dynos
If you want your phoenix application to receive HTTP requests you will have to set it up to run on a web dyno.
It has been a while since you've asked the question, but someone might find this answer valuable, though.
As of 2021 Heroku allows forwarding multiple ports, which allows to remsh into a running ErlangVM node. It depends on how you deploy your application, but in general, you will need to:
Give your node a name and a cookie (i.e. --name "myapp#127.0.0.1" --cookie "secret")
Tell exactly which port a node should bind to, so you know which pot to forward (i.e. --erl "-kernel inet_dist_listen_min 9000 -kernel inet_dist_listen_max 9000")
Forward EPMD and Node ports by running heroku ps:forward 9001:4369,9000
Remsh into your node: ERL_EPMD_PORT=9001 iex --cookie "secret" --name console#127.0.0.1 --remsh "myapp#127.0.0.1"
Eventually you should start your server with something like this (if you are still using Mix tool): MIX_ENV=prod elixir --name "myapp#127.0.0.1" --cookie "secret" --erl "-kernel inet_dist_listen_min 9000 -kernel inet_dist_listen_max 9000" -S mix phx.server --no-halt
If you are using Releases, most of the setup has already been done for you by the Elixir team.
To verify that EPMD port has been forwarded correctly, try running epmd -port 9001 -names. The output should be:
epmd: up and running on port 4369 with data:
name myapp#127.0.0.1 at port 9000
You may follow my notes on how I do it for Dockerized releases (there is a bit more hustle): https://paveltyk.medium.com/elixir-remote-shell-to-a-dockerized-release-on-heroku-cc6b1196c6ad

debugging a sinatra app with rubmine

I'm trying to debug a sinatra app using RubyMine. I am using rackup to run the app on localhost and unicorn to run it on remote host. My ruby version is 1.9.3.
I should also note that the "run debug mode icon" is grayed out. I don't know what is missing from the configuration.
What gems do I need? What else do I need to do?
update:
I have run the server process on localhost using rackup -p 9000. In order to start debugging -run rdebug-ide --port 1234 -- rackup and got this message :
Fast Debugger (ruby-debug-ide 0.4.17.beta16, ruby-debug-base 0.10.5.rc1) listens on 127.0.0.1:1234
I still don't understand how to debug using Rubymine. I have opened the browser in http://0.0.0.0:1234 and I don't get any response (it keeps loading)
I run the remote host using unicorn like so :
unicorn -c etc/fin_srv_unicorn.conf -E staging
how shold I set up remote debugging? I have tried also rack and ruby remote.
Tried connection to the remote host and running the service (using the command listed above), and then running the rdebug like so :
rdebug-ide --port 1911 -- $SCRIPT$
where for $SCRIPT$ I have tried app/main.rb staging , unicorn -E staging, unicorn -c etc/fin_srv_unicorn.conf -E staging

Resources