when i run 'dotcloud push traing'... running postinstall script take a long time and get error below.
I created a new account.
cd to project and run command: 'dotcloud create training' and 'dotcloud push training' but nothing change.
anyone can help me?plz
Running postinstall script...
ERROR: deployment aborted due to unexpected command result: "./postinstall" failed with return code [Timeout]
postinstall
#!/bin/sh
#python createdb.py
python training/manage.py syncdb --noinput
python mkadmin.py
mkdir -p /home/dotcloud/data/media /home/dotcloud/volatile/static
python training/manage.py collectstatic --noinput
requirements.txt
Django==1.4
PIL==1.1.7
Try this as your postinstall. It may help with locating the error (expanding on Ken's advice):
#!/bin/bash
# set -e makes the script exit on the first error
set -e
# set -x will add debug trace information to all of your commands
set -x
echo "$0 starting"
#python createdb.py
python training/manage.py syncdb --noinput
python mkadmin.py
mkdir -p /home/dotcloud/data/media /home/dotcloud/volatile/static
python training/manage.py collectstatic --noinput
echo "$0 complete"
More debugging info available at http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html
Any error messages like "./postinstall failed with return code" means that there is a problem with your postinstall script.
In order to debug postinstall executions easily on dotCloud, you can do the following:
Let's assume that your app is "ramen" and your service is "www".
$ dotcloud -A ramen run www
> ~/current/postinstall
It'll re-execute the postinstall but from your session this time, so you'll be able to easily update the postinstall code and re-run it without having to push again and again.
Once you found the root cause, fix it locally and repush your application.
Related
As my first batch script, I want to run my backend and frontend with just one script. My backend is in python with Django and my frontend is in react. I, therefore, have to processes I need to run. But I don't know how to run them in parallel as I need to start a virtual environment in python first.
I don't understand how it would log the server logs. Is there an option to make two terminal windows or a new terminal tab? Or would it log in to one terminal together?
#!/bin/bash
DJANGODIR=/Users/usr/Desktop/programming/app/django
REACTDIR=/Users/urs/Desktop/programming/app/react
# START REACT FRONTEND
echo Starting React Server
# Option 1
# cd $REACTDIR
# npm start
# Option 2
# start app from any directory without cd into it
# npm --prefix $REACTDIR run start
# START DJANGO BACKEND
echo Starting Django Server
# cd $DJANGODIR
# Start virtual environment
# source venv/bin/activate
# Start Server
# python3 manage.py runserver
# Activating and running in one command
# source venv/bin/activate python3 manage.py runserver
# Here is where I'm not knowing how to run them in parallel
source venv/bin/activate python3 manage.py runserver & npm --prefix $REACTDIR run start
Have you tried with the pipe operator? Pipe operator explained
I need to run a bash script periodically on a Jetson Nano (so, Ubuntu 18.04). The script should run system updates, pull some Python code from a repository, and run it as a specified user.
So, I created this script:
#! /bin/bash
## system updates
sudo apt update
sudo apt upgrade
## stop previous instances of the Python code
pkill python3
## move to python script folder
cd /home/user_name/projects/my_folder
## pull updates from repo
git stash
git pull
## create dummy folder to check bash script execution to this point
sudo -u user_name mkdir /home/user_name/projects/dummy_folder_00
## launch python script
sudo -u user_name /usr/bin/python3 python_script.py --arg01 --arg02
## create dummy folder to check bash script execution to this point
sudo -u user_name mkdir /home/user_name/projects/dummy_folder_01
I created a cron job running this script as root, by using
sudo crontab -e
and adding the entry
00 13 * * * /home/user_name/projects/my_folder/script.sh
Now, I can see that at the configured time, both the dummy folders are created, and they actually belong to user_name. However, the Python script isn't launched.
I tried creating the cron job as non root user (crontab -e), but at this point even if the Python script gets exectured, I guess I wouldn't be able to run apt update/upgrade.
How can I fix this?
Well, if the dummy folders did get created, that means the sudo statements work, so i'd say theres a 99%+ chance that python was infact started.
I'm guessing the problem is that you havent specified the path for the python file, and your working directory likely isn't what you're expecting it to be.
change:
sudo -u user_name /usr/bin/python3 python_script.py --arg01 --arg02
to something like
sudo -u user_name /usr/bin/python3 /path/to/your/python_script.py --arg01 --arg02
then test.
If that didn't solve the problem , then enable some logging, change the line to:
sudo -u user_name /usr/bin/python3 /path/to/your/python_script.py --arg01 --arg02 \
1> /home/user_name/projects/dummy_folder_00/log.txt 2>&1 ;
and test again, it should log STDOUT and STDERR to that file then.
I am editing my .ebextensions .config file to run some initialisation commands before deployment. I thought this commands would be run in the same folder of the extracted .zip containing my app. But that's not the case. manage.py is in the root directory of my zip and if I do the commands:
01_collectstatic:
command: "source /opt/python/run/venv/bin/activate && python manage.py collectstatic --noinput"
I get a ERROR: [Instance: i-085e84b9d1df851c9] Command failed on instance. Return code: 2 Output: python: can't open file 'manage.py': [Errno 2] No such file or directory.
I could do command: "python /opt/python/current/app/manage.py collectstatic --noinput" but that would run the manage.py that successfully was deployed previously instead of running the one that is being deployed atm.
I tried to check what was the working directory of the commands ran by the .config by doing command: "pwd" and it seems that pwd is /opt/elasticbeanstalk/eb_infra which doesn't contain my app.
So I probably need to change $PYTHONPATH to contain the right path, but I don't know which path is it.
In this comment the user added the following to his .config file:
option_settings:
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: myapp.settings
PYTHONPATH: "./src"
Because his manage.py lives inside the src folder within the root of his zip. In my case I would do PYTHONPATH: "." but it's not working.
AWS support solved the problem. Here's their answer:
When Beanstalk is deploying an application, it keeps your application files in a "staging" directory while the EB Extensions and Hook Scripts are being processed. Once the pre-deploy scripts have finished, the application is then moved to the "production" directory. The issue you are having is related to the "manage.py" file not being in the expected location when your "01_collectstatic" command is being executed.
The staging location for your environment (Python 3.4, Amazon Linux 2017.03) is "/opt/python/ondeck/app".
The EB Extension "commands" section is executed before the staging directory is actually created. To run your script once the staging directory has been created, you should use "container_commands". This section is meant for modifying your application after the application has been extracted, but before it has been deployed to the production directory. It will automatically run your command in your staging directory.
Can you please try implementing the container_command section and see if it helps resolve your problem? The syntax will look similar to this (but please test it before deploying to production):
container_commands:
01_collectstatic:
command: "source /opt/python/run/venv/bin/activate && python manage.py collectstatic --noinput"
So, the thing to remember about beanstalk is that each of the commands are independent, and you do not maintain state between them. You have two options in this case, put your commands into a shell script that is uploaded in the files section of ebextensions. Or, you can write one line commands that do all stateful activities prefixed to your command of interest.
e.g.,
00_collectstatic:
command: "pushd /path/to/django && source /opt/python/run/venv/bin/activate && python manage.py collectstatic --noinput && popd"
I have a simple python script which I want to start a daemon-service in background in docker container
/sbin/start-stop-daemon --start --user root --make-pidfile --pidfile /var/lock/subsys/my-application.pid --exec 'python /opt/app/uc/monitor/bin/my-application.py'
when I execute this command in a shell I get
/sbin/start-stop-daemon: unable to stat //python /opt/app/uc/monitor/bin/my-application.py (No such file or directory)
However when execute just the below command in shell it works
python /opt/app/uc/monitor/bin/my-application.py
I'm sure the python is installed and all the links have been setup.
Thanks for the help
That error message implies that start-stop-daemon is looking for a file to open (the stat operation is a check before it opens the file) and treating your 'python ... ' argument as if it was a file.
See this example which confirms this. You may need to read the man page for start-stop-daemon, for your Ubuntu version, to check what a valid command would be for your setup.
Simplest solution is probably to create a shell script (say /opt/app/uc/monitor/bin/run-my-application.sh), and put this into it:
#!/bin/bash
python /opt/app/uc/monitor/bin/my-application.py
Be sure to do chmod +x on this file. If python is not found, use which python to find the path to python and use that in the script.
Now try:
/sbin/start-stop-daemon --start --user root --make-pidfile --pidfile /var/lock/subsys/my-application.pid --exec '/opt/app/uc/monitor/bin/run-my-application.sh'
I'm using fabric to launch a command on a remote server.
I'd like to launch this command as a different user (neither the one connected nor root).
def colstat():
run('python manage.py collectstatic --noinput')
Trying
def colstat():
sudo('-u www-data python manage.py collectstatic --noinput')
Oviously this won't work because -u will be considered as a command and not an option of sudo
out: /bin/bash: -u : command not found
(www-data is the user which should run the command)
How can I use www-data to run my command from Fabric ?
Judging from the documentation:
sudo('python manage.py collectstatic --noinput', user='www-data')