How do you launch fabric tasks without stdin - fabric

I have bunch of tasks that I need to launch using another shell script.
I want to run the shell script using nohup mode, but the fabric refuses continue as there is no stdin
Traceback (most recent call last):
File "/home/user/local/lib/python2.7/site-packages/Fabric-1.8.0-py2.7.egg/fabric/main.py", line 743, in main
*args, **kwargs
File "/home/user/local/lib/python2.7/site-packages/Fabric-1.8.0-py2.7.egg/fabric/tasks.py", line 368, in execute
multiprocessing
File "/home/user/local/lib/python2.7/site-packages/Fabric-1.8.0-py2.7.egg/fabric/tasks.py", line 264, in _execute
return task.run(*args, **kwargs)
File "/home/user/local/lib/python2.7/site-packages/Fabric-1.8.0-py2.7.egg/fabric/tasks.py", line 171, in run
return self.wrapped(*args, **kwargs)
File "/home/ubuntu/utils/deploy_to_ubuntu/deploy_worker.py", line 84, in deploy_existing
run('sudo sh ~/existing_setup.sh')
File "/home/user/local/lib/python2.7/site-packages/Fabric-1.8.0-py2.7.egg/fabric/network.py", line 578, in host_prompting_wrapper
return func(*args, **kwargs)
File "/home/user/local/lib/python2.7/site-packages/Fabric-1.8.0-py2.7.egg/fabric/operations.py", line 1042, in run
shell_escape=shell_escape)
File "/home/user/local/lib/python2.7/site-packages/Fabric-1.8.0-py2.7.egg/fabric/operations.py", line 911, in _run_command
stderr=stderr, timeout=timeout)
File "/home/user/local/lib/python2.7/site-packages/Fabric-1.8.0-py2.7.egg/fabric/operations.py", line 795, in _execute
worker.raise_if_needed()
File "/home/user/local/lib/python2.7/site-packages/Fabric-1.8.0-py2.7.egg/fabric/thread_handling.py", line 12, in wrapper
callable(*args, **kwargs)
File "/home/user/local/lib/python2.7/site-packages/Fabric-1.8.0-py2.7.egg/fabric/io.py", line 215, in input_loop
byte = msvcrt.getch() if win32 else sys.stdin.read(1)
IOError: [Errno 9] Bad file descriptor
I do not need stdin to be present for any of the terminals.
I am running fabric in the shellscript using --no-pty option but it is not helping at all
It is simply not possible to not run this nohup mode because it will take about 10 hours I do not want a terminal to be open for so long.
shellscript looks something like this:
fab --no-pty deploy.add_new_server
python runtests.py
python add_another_server_to_config.py
fab --no-pty deploy.add_new_server
python runtests.py
.
.
.
and I run nohup deploy_and_test.sh &

It was simple.
nohup deploy_and_test.sh </dev/null &

Related

Docker cannot port forward to a container, returns socket error 99

I am trying to run a container from a dockerfile image for a project I am working on. I am able to build the image from the dockerfile, but every time I try making the containers it runs into a consistent socket problem.
System Info
OS: Windows 10 Home Edition, v 2004 build 19041
Docker: 2.4.0.0
Python: 2.7
Docker Toolbox: 19.0.3.1
Git: 2.28.0
VirtualBox: 6.0.24
What I Expect to Happen
The container to be built and run after inputting the commands.
What Happens Instead
The container is created but cannot run and returns a socket error.
What I am doing
After navigating to the directory, I perform the following. Powershell is being run in admin mode. After trying to do the same for Docker, I've run into problems where it can only run if I let it start up when I sign in. I'm not sure if I can run it as an admin.
docker build . -t image_name
After confirming that the image is built, I try
docker run --publish 8000:8888 --detach --name container_name image_name
At this point the container is built but cannot run, and returns the following the logs.
Missing privilege separation directory: /var/run/sshd
[I 14:53:32.778 NotebookApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret
Traceback (most recent call last):
File "/usr/local/bin/jupyter-notebook", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python2.7/dist-packages/jupyter_core/application.py", line 270, in launch_instance
return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/traitlets/config/application.py", line 663, in launch_instance
app.initialize(argv)
File "<decorator-gen-7>", line 2, in initialize
File "/usr/local/lib/python2.7/dist-packages/traitlets/config/application.py", line 87, in catch_config_error
return method(app, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/notebook/notebookapp.py", line 1630, in initialize
self.init_webapp()
File "/usr/local/lib/python2.7/dist-packages/notebook/notebookapp.py", line 1407, in init_webapp
self.http_server.listen(port, self.ip)
File "/usr/local/lib/python2.7/dist-packages/tornado/tcpserver.py", line 143, in listen
sockets = bind_sockets(port, address=address)
File "/usr/local/lib/python2.7/dist-packages/tornado/netutil.py", line 168, in bind_sockets
sock.bind(sockaddr)
File "/usr/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 99] Cannot assign requested address
Missing privilege separation directory: /var/run/sshd
Traceback (most recent call last):
File "/usr/local/bin/jupyter-notebook", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python2.7/dist-packages/jupyter_core/application.py", line 270, in launch_instance
return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/traitlets/config/application.py", line 663, in launch_instance
app.initialize(argv)
File "<decorator-gen-7>", line 2, in initialize
File "/usr/local/lib/python2.7/dist-packages/traitlets/config/application.py", line 87, in catch_config_error
return method(app, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/notebook/notebookapp.py", line 1630, in initialize
self.init_webapp()
File "/usr/local/lib/python2.7/dist-packages/notebook/notebookapp.py", line 1407, in init_webapp
self.http_server.listen(port, self.ip)
File "/usr/local/lib/python2.7/dist-packages/tornado/tcpserver.py", line 143, in listen
sockets = bind_sockets(port, address=address)
File "/usr/local/lib/python2.7/dist-packages/tornado/netutil.py", line 168, in bind_sockets
sock.bind(sockaddr)
File "/usr/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 99] Cannot assign requested address
Missing privilege separation directory: /var/run/sshd
Traceback (most recent call last):
File "/usr/local/bin/jupyter-notebook", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python2.7/dist-packages/jupyter_core/application.py", line 270, in launch_instance
return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/traitlets/config/application.py", line 663, in launch_instance
app.initialize(argv)
File "<decorator-gen-7>", line 2, in initialize
File "/usr/local/lib/python2.7/dist-packages/traitlets/config/application.py", line 87, in catch_config_error
return method(app, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/notebook/notebookapp.py", line 1630, in initialize
self.init_webapp()
File "/usr/local/lib/python2.7/dist-packages/notebook/notebookapp.py", line 1407, in init_webapp
self.http_server.listen(port, self.ip)
File "/usr/local/lib/python2.7/dist-packages/tornado/tcpserver.py", line 143, in listen
sockets = bind_sockets(port, address=address)
File "/usr/local/lib/python2.7/dist-packages/tornado/netutil.py", line 168, in bind_sockets
sock.bind(sockaddr)
File "/usr/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 99] Cannot assign requested address
I have confirmed that port 8888 is exposed in the dockerfile, and tried mapping it to 8080 as well with the same results. I have confirmed that ports 8000, 8888, and 8080 are open on my computer, and also tried mapping them to the IP address that I found associated with docker (127.0.0.1). I have also tried to use the create and run commands in Docker but these do not work either.
Here is the link to the dockerfile. I have not edited it outside of trying different ports.
Sorry for the wall of text!

Uninstall and re-install of Anaconda 2.7 won't fix kernel problem in Jupyter

I am in a VM environment (Win 7 VirtualBox) and had gotten the Anaconda 2.7 suite to work.
Being new to Python, I was working on some code that instructed me to install PythonWin to do some connection with Crystal Reports. Seemed to install OK but then started getting some errors about the kernel in Jupyter not starting.
Uninstalled everything and I think got rid of any bad links and such from the previous installs.
Did the fresh install of Anaconda 2.7 and did NOT install PythonWin. Now stuck with a broken/unable to load kernel in Jupyter. Here's the error below. All help much appreciated from this newbie. Thanks!
Traceback (most recent call last):
File "C:\Users\Victor\Anaconda2\lib\site-packages\tornado\web.py", line 1592, in _execute
result = yield result
File "C:\Users\Victor\Anaconda2\lib\site-packages\tornado\gen.py", line 1133, in run
value = future.result()
File "C:\Users\Victor\Anaconda2\lib\site-packages\tornado\concurrent.py", line 261, in result
raise_exc_info(self._exc_info)
File "C:\Users\Victor\Anaconda2\lib\site-packages\tornado\gen.py", line 1141, in run
yielded = self.gen.throw(*exc_info)
File "C:\Users\Victor\Anaconda2\lib\site-packages\notebook\services\sessions\handlers.py", line 73, in post
type=mtype))
File "C:\Users\Victor\Anaconda2\lib\site-packages\tornado\gen.py", line 1133, in run
value = future.result()
File "C:\Users\Victor\Anaconda2\lib\site-packages\tornado\concurrent.py", line 261, in result
raise_exc_info(self._exc_info)
File "C:\Users\Victor\Anaconda2\lib\site-packages\tornado\gen.py", line 1141, in run
yielded = self.gen.throw(*exc_info)
File "C:\Users\Victor\Anaconda2\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 79, in create_session
kernel_id = yield self.start_kernel_for_session(session_id, path, name, type, kernel_name)
File "C:\Users\Victor\Anaconda2\lib\site-packages\tornado\gen.py", line 1133, in run
value = future.result()
File "C:\Users\Victor\Anaconda2\lib\site-packages\tornado\concurrent.py", line 261, in result
raise_exc_info(self._exc_info)
File "C:\Users\Victor\Anaconda2\lib\site-packages\tornado\gen.py", line 1141, in run
yielded = self.gen.throw(*exc_info)
File "C:\Users\Victor\Anaconda2\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 92, in start_kernel_for_session
self.kernel_manager.start_kernel(path=kernel_path, kernel_name=kernel_name)
File "C:\Users\Victor\Anaconda2\lib\site-packages\tornado\gen.py", line 1133, in run
value = future.result()
File "C:\Users\Victor\Anaconda2\lib\site-packages\tornado\concurrent.py", line 261, in result
raise_exc_info(self._exc_info)
File "C:\Users\Victor\Anaconda2\lib\site-packages\tornado\gen.py", line 326, in wrapper
yielded = next(result)
File "C:\Users\Victor\Anaconda2\lib\site-packages\notebook\services\kernels\kernelmanager.py", line 160, in start_kernel
super(MappingKernelManager, self).start_kernel(**kwargs)
File "C:\Users\Victor\Anaconda2\lib\site-packages\jupyter_client\multikernelmanager.py", line 110, in start_kernel
km.start_kernel(**kwargs)
File "C:\Users\Victor\Anaconda2\lib\site-packages\jupyter_client\manager.py", line 259, in start_kernel
**kw)
File "C:\Users\Victor\Anaconda2\lib\site-packages\jupyter_client\manager.py", line 204, in _launch_kernel
return launch_kernel(kernel_cmd, **kw)
File "C:\Users\Victor\Anaconda2\lib\site-packages\jupyter_client\launcher.py", line 138, in launch_kernel
proc = Popen(cmd, **kwargs)
File "C:\Users\Victor\Anaconda2\lib\subprocess.py", line 394, in __init__
errread, errwrite)
File "C:\Users\Victor\Anaconda2\lib\subprocess.py", line 644, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
Figure I'll close the loop since I've found a solution - after uninstalling everything related to Anaconda and going through the file system and deleting all Anaconda related folders I re-installed Anaconda 2.7 as admin. Also during the setup I selected the choice to make the program available to all users.
Install finished and Anaconda 2.7 and all the modules worked as expected.

trying to use cookiecutter-django, getting errors and does not create anything

trying to get a Django project started using cookiecutter-django and can't seem to get it to generate anything.
using Python 3.6, Django 2.0.5, cookiecutter 1.6.0 (then created a virtualenv and entered a new, blank directory)
so I enter this command:
cookiecutter https://github.com/pydanny/cookiecutter-django
and get this error traceback:
Traceback (most recent call last):
File "c:\python\python36\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\python\python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\Python\python36\Scripts\cookiecutter.exe\__main__.py", line 9, in
<module>
File "c:\python\python36\lib\site-packages\click\core.py", line 722, in
__call__
return self.main(*args, **kwargs)
File "c:\python\python36\lib\site-packages\click\core.py", line 697, in main
rv = self.invoke(ctx)
File "c:\python\python36\lib\site-packages\click\core.py", line 895, in
invoke
return ctx.invoke(self.callback, **ctx.params)
File "c:\python\python36\lib\site-packages\click\core.py", line 535, in
invoke
return callback(*args, **kwargs)
File "c:\python\python36\lib\site-packages\cookiecutter\cli.py", line 120,
in main
password=os.environ.get('COOKIECUTTER_REPO_PASSWORD')
File "c:\python\python36\lib\site-packages\cookiecutter\main.py", line 63,
in cookiecutter
password=password
File "c:\python\python36\lib\site-packages\cookiecutter\repository.py", line
103, in determine_repo_dir
no_input=no_input,
File "c:\python\python36\lib\site-packages\cookiecutter\vcs.py", line 99, in
clone
stderr=subprocess.STDOUT,
File "c:\python\python36\lib\subprocess.py", line 336, in check_output
**kwargs).stdout
File "c:\python\python36\lib\subprocess.py", line 418, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['git', 'clone',
'https://github.com/pydanny/cookiecutter-django']' returned non-zero exit
status 128.
OK - figured out how to get this to work.
used Github desktop
from cookiecutter-django repository, right click
open it Git Shell
this opens a Powershell window.
CD to directory where project will be placed in.
cookiecutter https://github.com/pydanny/cookiecutter-django
and it works.
not sure exactly why this works when regular CMD and elevated CMD do not, but this was the only way I could get it to work.
This is a permission issue with github due to the need to setup ssh keys. By the way I'm using ubuntu 12.
https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/ - create a key first in your machine using the instructions in the link. Once you have your ssh key, proceed to step 2. (Step 2 is indicated in the first link as last step)
https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account - add the generated ssh key to your github account.

Error in runserver with Django on windows 10

I am using python 3.5 and windows 10, but had the same issue using windows 8, and that is the traceback i get while trying to runserver:
Traceback (most recent call last):
File "C:\Users\noabendor87\documents\otree\manage.py", line 10, in
execute_from_command_line(sys.argv, script_file=file)
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\otree\management\cli.py", line
177, in execute_from_command_line
utility.execute()
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\django\core\management__init__
.py", line 346, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\django\core\management\base.py"
, line 394, in run_from_argv
self.execute(*args, **cmd_options)
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\django\core\management\commands
\runserver.py", line 49, in execute
super(Command, self).execute(*args, **options)
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\django\core\management\base.py"
, line 445, in execute
output = self.handle(*args, **options)
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\django\core\management\commands
\runserver.py", line 88, in handle
self.run(**options)
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\django\core\management\commands
\runserver.py", line 97, in run
autoreload.main(self.inner_run, None, options)
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\django\utils\autoreload.py", li
ne 336, in main
reloader(wrapped_main_func, args, kwargs)
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\django\utils\autoreload.py", li
ne 307, in python_reloader
exit_code = restart_with_reloader()
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\django\utils\autoreload.py", li
ne 293, in restart_with_reloader
exit_code = os.spawnve(os.P_WAIT, sys.executable, args, new_environ)
UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1: invalid character
I have already tried following the instructions in the following link:
http://stackoverflow.com/questions/25714826/error-in-manage-py-runserver-with-django-on-windows-8-1
but it did not help.
This is how the lines of code look like:
enter image description here
(Since Im a new user I cannot paste the image to the original post)
Anyone have encountered something similar and have a solution?
I used to have similar problems because of the difficulties with the virtual environment in windows 10. Try running the powershell as an administrator and do "Set-ExecutionPolicy RemoteSigned" or "Set-ExecutionPolicy Unrestricted" if remotesigned does not work. Do this before activating the virtualenv.
first I will like you check the django version you are working with my "type python -m django --version" or "pip freeze". check weather its compatible with the python version on your pc. if it's not install compatible python version. then check weather "init.py" is within your project directory, if not add it to your project directory. then run "Set-ExecutionPolicy -Scope CurrentUser Unrestricted" on your terminal. then run activate your virtualenv, then run "python manage.py runserver"

custom django-admin command: problems with use models and crontab

I created custom django-admin command. I use this tutorial Writing custom django-admin commands
For example, my command:
import os
from home.models import BuildTask
class Command(BaseCommand):
def handle(self, *args, **options):
tasks = BuildTask.objects.all()
os.system("touch /Users/macbook/Desktop/Start.txt")
if tasks:
os.system("touch /Users/macbook/Desktop/TasksExist.txt")
else:
os.system("touch /Users/macbook/Desktop/TasksNotExist.txt")
os.system("touch /Users/macbook/Desktop/End.txt")
when i run this command by use terminal:
python manage.py build_task
everything is OK, i get 3 files on Destop.
But when i use crontab,
* * * * * /usr/bin/python /Users/macbook/builder/manage.py build_task
i just get 1 file on Desktop("Start.txt"). Apparently the script stops job on the line.
if tasks:
Please help me. What's the problem?
Update: /var/mail/macbook:
File "/Users/macbook/workspace/acodebuilder/home/management/commands/build_apk.py",
line 26, in handle
if tasks:
File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 113, in
__nonzero__
iter(self).next()
File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 107, in
_result_iter
self._fill_cache()
File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 772, in
_fill_cache
self._result_cache.append(self._iter.next())
File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 273, in
iterator
for row in compiler.results_iter():
File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py", line 680, in
results_iter
for rows in self.execute_sql(MULTI):
File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py", line 735, in
execute_sql
cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/backends/util.py", line 34, in
execute
return self.cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/backends/sqlite3/base.py", line 234,
in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.DatabaseError: no such table: home_buildtask
Why "no such table" ?
You should be able to see the error output of the command (if there was any) by running the mail command. Alternatively, you can append &> ~/Desktop/django-command-error.log to the crontab entry and the error output of the cron job will be saved to django-command-error.log on your desktop.
it's issue caused by SQLite db, We must use MySQL or PGSQL!