How to Push crontab to Production Server (Nginx) - django

Django Project: I have a crontab task which sends email notification to all users. Here are the set of procedures which I would like to deploy it to production server using fabfile.
$ sudo crontab -e
1 * * * * pathtovirtualenv/python pathto/manage.py run_notifications
$ sudo service cron restart
I would like to deploy the above steps to production server which sends weekly email notifications to all users. but sad thing I'm unable to test it on my working machine which is sending constant postfix/sendmail errors. I'm hoping if I could deploy it to production server which doesn't raise any issues like my working machine.

This isn't exactly what you asked about, but it's not difficult to set up a mail server for development/debugging:
python -m smtpd -c DebuggingServer -n
Connect to that on 8025 and it will print email to stdout. You can also run this programmatically from your test suite if you prefer: https://docs.python.org/2/library/smtpd.html
Ultimately, the answer to a testing problem is to figure out the testing, not to push to production and hope for the best. :)

Related

How to keep django rest API server running automatically on AWS?

So I uploaded my Django API with Rest framework on AWS EC2 instance. However, I have to manually go to Putty and connect to my EC2 instance and turn API on whenever I want to use it by inputting python manage.py runserver 0.0.0.0:8000.
When I turn off my PC, putty closes and API cannot be accessed anymore on the ip address.
How do I keep my API on forever? Does turning it into https help? Or what can be done?
You can make it live always by following means,
connect your ec2 instance using ssh.
Then deploy your backend (django) on that instance and run it at any port.
Once run on your desired port, you can close the terminal, please don't press ctrl+c so that your django server does not stop. you can just cross the terminal. it will be now running.
You can also run the django server on tmux (its terminal inside terminal). here is tutorial on tmux.
https://linuxize.com/post/getting-started-with-tmux/
One other approach is, you can deploy the django using docker container.
I hope you will come over your problem.
Thanks.
Ok I finally solved this. So when you close putty or a ssh client session, the session goes offline. However, if you run the session via daemon, the session continues in the background even when you close your clients. The code is
$ nohup python ./manage.py runserver 0.0.0.0:8000 &
Of course you can use tmux or docker, as suggested by madi, but I think running this one code is much simpler.
You can use pm2.
Please install pm2.
And make a server.json file in the root directory of your django app to run your app.
{
apps:
[{
name: "appname",
script: "manage.py",
args: ["runserver", "0.0.0.0:8888"],
exec_mode: "fork",
instances: "1",
wait_ready: true,
autorestart: false,
max_restarts: 5,
interpreter : "python3"
}]
}
Then you can run this app with pm2 start server.json.
Your app will run on port 8888 .

How to do a transaction in a Private Stellar Blockchain Network?

So using docker I started a private Stellar Network by typing in the below command:
docker run --rm -it -p "8000:8000" --name stellar stellar/quickstart --standalone
Then I opened another terminal and ran the below command to interact with the private network:
docker exec -it stellar /bin/bash
Then I ran the below command to generate a keypair:
stellar-core --genseed
All commands went well. How do I do a transaction now?
My objective is to get 333 coins in one of the accounts.
Stellar has a dedicated stackexchange where questions on Stellar will get more attention.
After you have executed the steps in your question, stellar will be open to receiving transactions at localhost:8000/tx?blob=Base64 (See commands). You can confirm stellar is running with curl localhost:8000.
The base64 blob is the the XDR encoded form of a transaction. In your case you will want that transaction to contain a CreateAccount operation.
It is possible to build this XDR for custom networks with some of the SDKs. It's possible in the Scala SDK (I'm the maintainer) and probably very easy to do in the JavaScript SDK too. But to start with, I suggest building XDR by hand by going to the lab's transaction builder, selecting "custom" network at the top right and building your transaction from there.
You want to populate the network passphrase with Standalone Network ; February 2017. This is the value in the container's file stellar-core.cfg.

Cloudfoundry (Bosh-lite) app push is timeout

I trying CF on day 1. Deployed local cloud foundry on Mac with Bosh lite. No issues in doing so. Also added mysql build pack without any issue. But when i try to push the app it is taking forever and fails. After few tries it succeeded once, but the app is failing to start with time out. So to increate timeout i did re-push the app with command;
cf push pong_matcher_spring -t 180 -p /DEV/github/cloudfoundry-samples/pong_matcher_spring/target/pong-matcher-spring-1.0.0.BUILD-SNAPSHOT.jar -m 256M -i 1 -n app1
The app never getting pushed. Pleas see below log;
————————————————————————————————————————————
cf push pong_matcher_spring -t 180 -p /DEV/github/cloudfoundry-samples/pong_matcher_spring/target/pong-matcher-spring-1.0.0.BUILD-SNAPSHOT.jar -m 256M -i 1 -n app1
Using manifest file /DEV/github/cloudfoundry-samples/pong_matcher_spring/manifest.yml
Creating app pong_matcher_spring in org scientia / space development as admin...
OK
Creating route app1.bosh-lite.com...
OK
Binding app1.bosh-lite.com to pong_matcher_spring...
OK
Uploading pong_matcher_spring...
Uploading app files from: /DEV/github/cloudfoundry-samples/pong_matcher_spring/target/pong-matcher-spring-1.0.0.BUILD-SNAPSHOT.jar
Uploading 798.3K, 116 files
Done uploading
OK
Binding service mysql to app pong_matcher_spring in org scientia / space development as admin...
OK
Starting app pong_matcher_spring in org scientia / space development as admin...
-----> Downloaded app package (23M)
FAILED
StagingError
TIP: use 'cf logs pong_matcher_spring --recent' for more information
————————————————————————————————————————————
I could not find anything in job logs apart from these messages.
I suspect there is something with the network. Any help is appreciated.
Restart the Vagrant VM solved the issue.

InfluxDB Cannot see databases from localhost:8083 + Cannot access Command Line Interface

Please feel free to redirect me to any other place if this isn't the right one for this question.
Problem: When I log to the administration panel : "localhost:8083" with "root" "root" I cannot see the existing databases nor the data in it. Also, I have no way to access InfluxDB from the command line.
Also the line sudo /etc/init.d/influxdb start does not work for my setup. I have to go into /etc/init.d/ and run sudo ./influxdb start -config=config.toml in order to get the server running.
I've installed influxDB v0.8 from https://influxdb.com/docs/v0.8/introduction/installation.html for Ubuntu 14.04.
I've been developing a Clojure program using the Capacitor API just to get started and interact with InfluxDB. It runs well, I can create delete, insert and query a database without problems.
netstat -anp | grep LISTEN confirms me that ports 8083 8086 8090 and 8099 are listening.
I've been Googling all around but cannot manage to get a solution.
Thanks for the support and enjoy building things !
Problem solved: the database weren't visible in firefox but everything is visible in Chromium!
Why couldn't I access the CLI ? I was expecting the v0.8 to behave exactly like the v0.9.
You help was appreciated anyway !
For InfluxDB 0.9 the CLI could be started with:
/opt/influxdb/influx
then you can display available databases:
Connected to http://localhost:8086 version 0.9.1
InfluxDB shell 0.9.1
> show databases
name: databases
---------------
name
collectd
graphite
> use collectd
Using database collectd
> show series limit 5
You can try creating new database from CLI:
> CREATE DATABASE mydb
or with curl command:
curl -G 'http://localhost:8086/query' --data-urlencode "q=CREATE DATABASE mydb"
Web UI should be available on http://localhost:8083

xcodebuild running tests headless?

As we all know by now, the only way to run tests on iOS is by using the simulator. My problem is that we are running jenkins and the iOS builds are running on a slave (via SSH), as a result running xcodebuild can't start the simulator (as it runs headless). I've read somewhere that it should be possible to get this to work with SimLauncher (gem sim_launcher). But I can't find any info on how to set this up with xcodebuild. Any pointers are welcome.
Headless and xcodebuild do not mix well. Please consider this alternative:
You can configure the slave node to launch via jnlp (webstart). I use a bash script with the .command extension as a login item (System Preferences -> Users -> Login Items) with the following contents:
#!/bin/bash
slave_url="https://gardner.company.com/jenkins/jnlpJars/slave.jar"
max_attempts=40 # ten minutes
echo "Waiting to try again. curl returneed $rc"
curl -fO "${slave_url}" >>slave.log
rc=$?
if [ $rc -ne 0 -a $max_attempts -gt 0 ]; then
echo "Waiting to try again. curl returneed $rc"
sleep 5
curl -fO "${slave_url}" >>slave.log
rc=$?
if [ $rc -eq 0 ]; then
zip -T slave.jar
rc=$?
fi
let max_attempts-=1
fi
# Simulator
java -jar slave.jar -jnlpUrl https://gardner.company.com/jenkins/computer/buildmachine/slave-agent.jnlp -secret YOUR_SECRET_KEY
The build user is set to automatically login. You can see the arguments to the slave.jar app by executing:
gardner:~ buildmachine$ java -jar slave.jar --help
"--help" is not a valid option
java -jar slave.jar [options...]
-auth user:pass : If your Jenkins is security-enabled, specify
a valid user name and password.
-connectTo HOST:PORT : make a TCP connection to the given host and
port, then start communication.
-cp (-classpath) PATH : add the given classpath elements to the
system classloader.
-jar-cache DIR : Cache directory that stores jar files sent
from the master
-jnlpCredentials USER:PASSWORD : HTTP BASIC AUTH header to pass in for making
HTTP requests.
-jnlpUrl URL : instead of talking to the master via
stdin/stdout, emulate a JNLP client by
making a TCP connection to the master.
Connection parameters are obtained by
parsing the JNLP file.
-noReconnect : Doesn't try to reconnect when a communication
fail, and exit instead
-proxyCredentials USER:PASSWORD : HTTP BASIC AUTH header to pass in for making
HTTP authenticated proxy requests.
-secret HEX_SECRET : Slave connection secret to use instead of
-jnlpCredentials.
-slaveLog FILE : create local slave error log
-tcp FILE : instead of talking to the master via
stdin/stdout, listens to a random local
port, write that port number to the given
file, then wait for the master to connect to
that port.
-text : encode communication with the master with
base64. Useful for running slave over 8-bit
unsafe protocol like telnet
gardner:~ buildmachine$
For a discussion about OSX slaves and how the master is launched please see this Jenkins bug: https://issues.jenkins-ci.org/browse/JENKINS-21237
Erik - I ended up doing the items documented here:
Essentially:
The first problem, is that you do have to have the user that runs the builds also logged in to the console on that Mac build machine. It needs to be able to pop up the simulator, and will fail if you don’t have a user logged in — as it can’t do this entirely headless without a display.
Secondly, the XCode Developer tools requires elevated privileges in order to execute all of the tasks on the Unit tests. Sometimes you may miss seeing it, but without these, the Simulator will give you an authentication prompt that never clears.
A first solution to this (on Mavericks) is to run:
sudo security authorizationdb write system.privilege.taskport allow
This will eliminate one class of these authentication popups. You’ll also need to run:
sudo DevToolsSecurity --enable
Per Apple’s man page on this tool:
On normal user systems, the first time in a given login session that
any such Apple-code-signed debugger or performance analysis tools are
used to examine one of the user’s processes, the user is queried for
an administator password for authorization. DevToolsSecurity tool to
change the authorization policies, such that a user who is a member of
either the admin group or the _developer group does not need to enter
an additional password to use the Apple-code-signed debugger or
performance analysis tools.
Only issue is that these same things seem to be broken once I upgraded to Xcode 6. Back to the drawing board....