I'm struggling to get a subversion post commit hook to work.
When I commit, I get the error:
Failed to start '/svn/web/hooks/post-commit' hook
I read around a bit with people that had similar problems, and they all related to the lack of environment, or incorrect file permissions, so I ran this:
sudo -u www-data env - ./post-commit /svn/web 70
But it worked fine! I added logging to the file, which works when I run it with the above command, but not when I commit to the repo.
Any ideas? I gave everyone execute permission (chmod a+x post-commit).
It was a problem with my line endings.
fromdos post-commit
Did the trick.
Related
Trying to provide the minimal amount of information necessary here, so I've left a lot out. Lots of similar questions around, but the most common answer (use chmod +x) isn't working for me.
I have a Python script and a shell script that sit next to each in a GitHub Enterprise repository:
Next, in Jenkins I check the code in this repository out. The two key steps in my Jenkinsfile are like so:
dir ("$WORK/python")
{
sh "chmod +x test.sh"
sh "python3 foo.py -t '${AUTH}'"
}
Here, $WORK is the location on the Jenkins node that the code checks out to, and python (yes, poorly named) is the folder in the repository that the Python and shell script live in. Now, foo.py calls the shell script in this way:
try:
cmd = f'test.sh {repo_name}'
subprocess.Popen(cmd.split())
except Exception as e:
print(f'Error during repository scan: {e}')
Here, repo_name is just an argument that I define above this snippet, that I'm asking the shell script to do something with. When I run the job in Jenkins, it technically executes without error, but the exception branch above does run:
11:37:24 Error during repository scan - [Errno 13] Permission denied: 'test.sh'
I wanted to be sure that the chmod in the Jenkinsfile was running, so I opened a terminal to the machine that the code checked out to and found that the execute permissions were indeed correctly set:
-rw-r--r-- 1 adm domain users 4106 Feb 6 14:24 foo.py
-rwxr-xr-x 1 adm domain users 619 Feb 6 14:37 test.sh
I've gone around on this most of the day. What the heck is going on?
Doing this fixed it:
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
cmd = f'{BASE_DIR}/test.sh {repo_name}'
Popen(cmd.split())
Why? In my ignorance associated with picking up someone else's code, I neglected to see, buried further up before the call to the shell script, that we change to a folder one level down:
os.chdir('repo_content')
The shell script does not, of course, live there. So calling it without specifying the path won't work. I'm not sure why this results in [Errno 13] Permission denied: 'test.sh', as that would imply that the shell script was found, but fully qualifying the path as above is doing exactly what I had hoped.
I tried to deploy this botto koyeb but I got this error
bash: worker:: command not found
ERROR: failed to determine the run command to launch your application: add a run command in your Service configuration or create a procfile in your git repository.
procfile in bot repo
worker: python -m bot
I have no idea what to do . need detailed help plz !
bash: worker:: command not found
The double : colon suggests that
you intended to run e.g. /usr/bin/worker
but bash attempted to execute /usr/bin/worker:
and found no file by that name.
Revise your command so it has fewer colons.
I am running a python command that generates some code and checks out some commits using git. However an exception is raised when it tries to create the file .git/index.lock. Root owns the directory so I can't create any file without sudo.
I have tried running the command with sudo (sudo ./run.py ). This also didn't work because then it can't find my ssh key. Can I get around this without changing the ownership of .git, and without creating a root ssh key? Both of these things I do not want. I have seen similar questions like these but none of those answers works here.
fatal: Unable to create '/path/.git/index.lock': Permission denied
Traceback (most recent call last):
File "./run.py", line 155 in <module>
...
...
File "/usr/lib/python3.6/subprocess.py", line 418 in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['git', 'reset', '--hard', <hash>]' returned non-zero exist status 128.
You won't be able to perform any Git checkouts without permissions to write to the repository. However, if you want to use your SSH key, you can try running with sudo -E instead of plain sudo. That will ask sudo to preserve your home directory and any agent variables, which will let you use your SSH key.
Note that on some systems, the ability to preserve the environment is disabled or restricted, and consequently this won't work in those cases. In such an environment, you'd need to edit /etc/sudoers or use some other technique for credentials (such as a root-owned credential store and HTTPS).
Your have to clone git repository using http or https.
And execute below command:
git config —global credential.helper wincred
git fetch
First time it will ask for password and save it.
Next execution of git fetch it will not ask password.
Note: In case of password change you have to do same thing.
I had to push an .exe file to heroku to be able to create invoice pdfs. It works localy without any problems but on heroku I get an error:
OSError: [Errno 13] Permission denied
Probably because I am not allowed to execute .exe files. So I need somehow to create a rule that this file is allowed to execute.
I pushed wkhtmltopdf.exe to heroku and I access this file in my method to create a pdf:
MYDIR = os.path.dirname(__file__)
path_wkthmltopdf = os.path.join(MYDIR + "/static/executables/", "wkhtmltopdf.exe")
config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf)
Was not able to find a solution yet.
EDIT:
Tryed giving permission with chmod through heroku bash and also adding a linux executable but still the same error:
~/static/executables $ chmod a+x wkhtmltopdf-linux.exe
~ $ chmod a+x static/executables/wkhtmltopdf-linux.exe
Using sudo gave me:
bash: sudo: command not found
I'm not very familiar with heroku, but if you can somehow get access to terminal of environment of your application (for example ssh to your server), you need to change permissions of that file so it can be executed. To do that, you need to run in that terminal:
sudo chmod a+x /path/to/file/FILENAME
Also,i'm pretty sure your app on Heroku runs on Linux, specifically on Ubuntu, since it's the default (link)
It means there might be difficulties with running Windows executables.
Okay I managed to fix this with a buildpack. In addition wkhtmltopdf-pack must be installed and added to the requirements.txt.
Then you have to set a config var in heroku for the wkhtmltopdf executable which will be generated from the files provided in the buildpack. Do not search for an .exe file.
heroku config:set WKHTMLTOPDF_BINARY=wkhtmltopdf-pack
You can see all your config vars also in the heroku dashboard under settings, you can also create it there and not use the CLI.
Then you have to tell the pdfkit configuration where to find the WKHTMLTOPDF_BINARY:
In my config.py:
import subprocess
WKHTMLTOPDF_CMD = subprocess.Popen(
['which', os.environ.get('WKHTMLTOPDF_BINARY', 'wkhtmltopdf')], # Note we default to 'wkhtmltopdf' as the binary name
stdout=subprocess.PIPE).communicate()[0].strip()
For the pdfkit configuration:
config = pdfkit.configuration(wkhtmltopdf=app.config['WKHTMLTOPDF_CMD'])
Now you should be able to create the pdf, example:
the_pdf = pdfkit.from_string("something", False, configuration=config)
Credit to this tutorial:
https://artandlogic.com/2016/12/generating-pdfs-wkhtmltopdf-heroku/
When I run the fabric.py to deploy my site ton Ubuntu.
I met the error:
[192.168.15.143] run: rm -rf /home/user/project/weather_station/
[192.168.15.143] out: rm: cannot remove '/home/user/project/weather_station/logs/gunicorn.log': Permission denied
[192.168.15.143] out:
Fatal error: run() received nonzero return code 1 while executing!
Requested: rm -rf /home/user/project/weather_station/
Executed: /bin/bash -l -c "rm -rf /home/user/project/weather_station/"
Aborting.
Disconnecting from 192.168.15.143... done.
My think is that the error is about the permission denied.
I referenced this
So I changed run('rm -rf {}'.format(PROJECT_DIR))into sudo('rm -rf {}'.format(PROJECT_DIR))
but still error.Is there any approach?
Is the /home/user/project/weather_station/logs/gunicorn.log file in use by an active process? If gunicorn is running and using this file as a log file, then "Permission denied." is exactly what should happen. If this is the case, then you need to re-consider what you're trying to do, as you shouldn't be deleting a file that's being used.
In the case of a log file, the obvious solution would be to configure gunicorn to use a different location, like /home/user/logs/weather_station, so that it's outside of the path that you're trying to delete.
That point aside, if you stop the gunicorn process before executing this rm command, then your command should run successfully.
The broad issue, however, is that (I think) you're trying to delete a log file that's in use. You either need to configure gunicorn to use a different location for its log file, or else you need to end gunicorn before you attempt to delete it.
I finally use sudo chmod 777 /home/user/project/weather_station/logs/gunicorn.log
Then it does work.