Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom post-receive hook fails with exec format error #5076

Closed
2 tasks done
Corben78 opened this issue Mar 6, 2018 · 8 comments
Closed
2 tasks done

Custom post-receive hook fails with exec format error #5076

Corben78 opened this issue Mar 6, 2018 · 8 comments

Comments

@Corben78
Copy link
Contributor

Corben78 commented Mar 6, 2018

  • Gogs version (or commit ref): 0.11.34.1122
  • Git version: 2.8.0
  • Operating system: openSuSE Linux
  • Database (use [x]):
    • MySQL
  • Can you reproduce the bug at https://try.gogs.io:
    • Not relevant - no rights to create git hooks
  • Log gist (usually found in log/gogs.log):

Description

Custom git hook post-receive still fails with 0.11.34.1122 as mentioned in #4774

Short recap:
When having a custom git hook, a push to gogs reports internal error and is not executing the hook:

crben@linux:~/git/todo$ git push
Zähle Objekte: 3, Fertig.
Delta compression using up to 4 threads.
Komprimiere Objekte: 100% (2/2), Fertig.
Schreibe Objekte: 100% (3/3), 281 bytes | 281.00 KiB/s, Fertig.
Total 3 (delta 1), reused 0 (delta 0)
remote: Gogs: Internal error
To https://git.server.de/corben/todo.git
   a3433c2..8687d4a  master -> master

hooks/post-receive:

2018/03/06 08:51:33 [FATAL] [...its/gogs/cmd/hook.go:274 runHookPostReceive()] Fail to execute custom post-receive hook: fork/exec /opt/gogs/gogs-repositories/corben/todo.git/custom_hooks/post-receive: exec format error

gogs.log

2018/03/06 08:51:32 [TRACE] Session ID: 741a98ce9639c14d
2018/03/06 08:51:32 [TRACE] CSRF Token: oPwysdCkUM90oku7aPbpPpWO3p86MTUyMDMyMjY5Mjg3NDA0OTE4MQ==
2018/03/06 08:51:32 [TRACE] LDAP: Dialing with security protocol '2' without verifying: false
2018/03/06 08:51:32 [TRACE] LDAP will bind directly via UserDN template: uid=%s,ou=People,dc=company,dc=de
2018/03/06 08:51:32 [TRACE] Binding with userDN: uid=corben,ou=People,dc=company,dc=de
2018/03/06 08:51:32 [TRACE] Bound successfully with userDN: uid=corben,ou=People,dc=company,dc=de
2018/03/06 08:51:32 [TRACE] Fetching attributes 'uid', 'givenName', 'sn', 'mail', '' with filter '(&(objectClass=posixAccount)(uid=corben))' and base 'uid=corben,ou=People,dc=company,dc=de'
2018/03/06 08:51:32 [TRACE] Session ID: 4b18674799e8a041
2018/03/06 08:51:32 [TRACE] CSRF Token: mwgyDIQFlkcTGOgRQtndG_7occM6MTUyMDMyMjY5MjkyOTA1NDM5MA==
2018/03/06 08:51:32 [TRACE] LDAP: Dialing with security protocol '2' without verifying: false
2018/03/06 08:51:32 [TRACE] LDAP will bind directly via UserDN template: uid=%s,ou=People,dc=company,dc=de
2018/03/06 08:51:32 [TRACE] Binding with userDN: uid=corben,ou=People,dc=company,dc=de
2018/03/06 08:51:32 [TRACE] Bound successfully with userDN: uid=corben,ou=People,dc=company,dc=de
2018/03/06 08:51:32 [TRACE] Fetching attributes 'uid', 'givenName', 'sn', 'mail', '' with filter '(&(objectClass=posixAccount)(uid=corben))' and base 'uid=corben,ou=People,dc=company,dc=de'
2018/03/06 08:51:32 [TRACE] HTTPGit - Authenticated user: corben
2018/03/06 08:51:33 [TRACE] LDAP: Dialing with security protocol '2' without verifying: false
2018/03/06 08:51:33 [TRACE] LDAP will bind directly via UserDN template: uid=%s,ou=People,dc=company,dc=de
2018/03/06 08:51:33 [TRACE] Binding with userDN: uid=corben,ou=People,dc=company,dc=de
2018/03/06 08:51:33 [TRACE] Bound successfully with userDN: uid=corben,ou=People,dc=company,dc=de
2018/03/06 08:51:33 [TRACE] Fetching attributes 'uid', 'givenName', 'sn', 'mail', '' with filter '(&(objectClass=posixAccount)(uid=corben))' and base 'uid=corben,ou=People,dc=company,dc=de'
2018/03/06 08:51:33 [TRACE] Session ID: d750191d1d63e607
2018/03/06 08:51:33 [TRACE] CSRF Token: kizqundl7SpeFfdpvDqitR0M-BU6MTUyMDMyMjY5MzAyNTczNTg3OA==
2018/03/06 08:51:33 [TRACE] LDAP: Dialing with security protocol '2' without verifying: false
2018/03/06 08:51:33 [TRACE] LDAP will bind directly via UserDN template: uid=%s,ou=People,dc=company,dc=de
2018/03/06 08:51:33 [TRACE] Binding with userDN: uid=corben,ou=People,dc=company,dc=de
2018/03/06 08:51:33 [TRACE] Bound successfully with userDN: uid=corben,ou=People,dc=company,dc=de
2018/03/06 08:51:33 [TRACE] Fetching attributes 'uid', 'givenName', 'sn', 'mail', '' with filter '(&(objectClass=posixAccount)(uid=corben))' and base 'uid=corben,ou=People,dc=company,dc=de'
2018/03/06 08:51:33 [TRACE] HTTPGit - Authenticated user: corben
2018/03/06 08:51:33 [TRACE] Session ID: ee1ec21a385375ef
2018/03/06 08:51:33 [TRACE] CSRF Token: rnSxeW6lGDrr9f2jiV3I7tqx-0I6MTUyMDMyMjY5MzMyMTc2NjQwNw==
2018/03/06 08:51:33 [TRACE] TriggerTask 'todo/master' by 'corben'
2018/03/06 08:51:33 [TRACE] DeliverHooks [repo_id: 11]
2018/03/06 08:51:33 [TRACE] AddTestPullRequestTask [head_repo_id: 11, head_branch: master]: finding pull requests
2018/03/06 08:51:33 [TRACE] AddTestPullRequestTask [base_repo_id: 11, base_branch: master]: finding pull requests

Output:

[Macaron] 2018-03-06 08:51:32: Started GET /corben/todo.git/info/refs?service=git-receive-pack for 10.1.30.99
[Macaron] 2018-03-06 08:51:32: Completed GET /corben/todo.git/info/refs?service=git-receive-pack 401 Unauthorized in 6.15149ms
[Macaron] 2018-03-06 08:51:32: Started GET /corben/todo.git/info/refs?service=git-receive-pack for 10.1.30.99
[Macaron] 2018-03-06 08:51:32: Completed GET /corben/todo.git/info/refs?service=git-receive-pack 200 OK in 38.121036ms
[Macaron] 2018-03-06 08:51:33: Started POST /corben/todo.git/git-receive-pack for 10.1.30.99
[Macaron] 2018-03-06 08:51:33: Started HEAD /corben/todo/tasks/trigger?branch=master&secret=e2ff3a21668921 fc00ce320a850958a&pusher=2 for 127.0.0.1
[Macaron] 2018-03-06 08:51:33: Completed HEAD /corben/todo/tasks/trigger?branch=master&secret=e2ff3a216689 15fc00ce320a850958a&pusher=2 202 Accepted in 3.973645ms
[Macaron] 2018-03-06 08:51:33: Completed POST /corben/todo.git/git-receive-pack 200 OK in 308.976213ms
@unknwon
Copy link
Member

unknwon commented Mar 6, 2018

I think it's possible your hook script doesn't have correct first bang-line. Can you post content here?

@unknwon unknwon added the status: needs feedback Tell me more about it label Mar 6, 2018
@Corben78
Copy link
Contributor Author

Corben78 commented Mar 6, 2018

Ah, that's interesting.
Indeed, if I put a shebang like #!/usr/bin/env bash on the first line, it works.
This must be a change though, as it still works without any shebang line on gogs v0.9.141 or other git services. Is there a documentation that I missed describing that a shebang line is now needed?

Thank you very much for your quick reply!

@unknwon
Copy link
Member

unknwon commented Mar 6, 2018

@Corben78 I'm not 100% sure but I think in the old version something like /bin/bash it used to execute hooks (e.g. $ bash post-receive). Since new version has a delegation layer, it is execute by ./post-receive, that's why bang-line now matters.

Either way, I believe it is convention to have the bang-line (examples from Git also have it).

@unknwon unknwon closed this as completed Mar 6, 2018
@unknwon unknwon removed the status: needs feedback Tell me more about it label Mar 6, 2018
@biji
Copy link

biji commented Mar 13, 2018

post-receive hook does not work after upgrading, the content is: /home/git/git_multimail.py

first line of .py script already contains:
#! /usr/bin/env python

please help

@unknwon
Copy link
Member

unknwon commented Mar 13, 2018

@biji

  1. Define "does not work", post your error message.
  2. Classify on vague words: "after upgrading".

@biji
Copy link

biji commented Mar 13, 2018

Sorry, previously im using 0.9.97 , email notification from post-receive script get sent
After upgrading to 0.11.34, no email get sent
I have a lot repo using similiar hook

log/hooks/post-receive.log contains:
exec format error

thanks

@unknwon
Copy link
Member

unknwon commented Mar 13, 2018

@biji is your server Windows?

@biji
Copy link

biji commented Mar 14, 2018

It's linux, I misread
already solved by adding #!/usr/bin/env bash to post-receive script file, so the script contains:

#!/usr/bin/env bash
/home/git/git_multimail.py

But now i have to change all repos post-receive

richmahn referenced this issue in unfoldingWord/dcs Feb 4, 2019
* fix release creation via API

* fix release create tests
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants