1

How can I run a command in background inside composer script and go to next command. I tried something like below but It still hangs up until the chgrp command finishes and doesn't execute next command.

composer.json

"post-install-cmd": [
            "sh ./scripts/composer/post-install.sh"
 ],

post-install.sh

#!/bin/sh

set -ex

echo "Setting appropriate permissions"
nohup chgrp -R www web &
echo "Executing next command"
SkyRar
  • 1,107
  • 1
  • 20
  • 37
  • How long is "a lot of time"? How much stuff is in the `web` directory? – ceejayoz Feb 01 '19 at 15:10
  • 1
    There are other things to do as well in my script. This is just a small snippet of the script. So lets don't consider the time rather how can It be achieved in a composer script ? – SkyRar Feb 01 '19 at 15:19
  • My profile should make it quite clear I'm capable of answering questions. I'm asking clarifying questions so I can best assist, as there's probably a better approach than what you're trying to do. If you refuse to answer them, it makes it more difficult for me and others to help you. – ceejayoz Feb 01 '19 at 15:49
  • Probably this comment "I'm asking clarifying questions so I can best assist, as there's probably a better approach than what you're trying to do" could surely force me to reply to your question. It was not needed to vote down the question. It was not expected from such reputed people to vote down a valid question. – SkyRar Feb 01 '19 at 15:55
  • 1. Who downvoted what isn't public. You're making assumptions. 2. I'm trying to explain why I ask clarifying questions. I suspect using ACLs will be more effective than `chgrp`, but if you've only got a few hundred files in `web` and it's taking several minutes that'd be indicative of something else going on. Hence the questions. – ceejayoz Feb 01 '19 at 15:58
  • I saw and upvoted devdonkey's approach. Calling others egotistical while saying "I hadn't asked you any workaround or better approach" is... fascinating. Consider the ACL approach. It's a good one. – ceejayoz Feb 01 '19 at 16:03
  • @ceejayoz "I suspect using ACLs will be more effective than chgrp" I cant use ACl because I am using it docker ALPINE container. So let me know if you have any better solution. – SkyRar Feb 01 '19 at 16:03
  • For ACLs with Docker: https://stackoverflow.com/questions/22714885/how-to-use-setfacl-within-a-docker-container – ceejayoz Feb 01 '19 at 16:04
  • @ceejayoz I have already gone through the same before some days back. Do you have an answer for the comment on that question "Do you have any idea if Overlay2 supports ACL?" – SkyRar Feb 01 '19 at 16:06
  • Per https://tech.kaleo.blog/post/use-setfacl-within-docker/, the answer is "yes". – ceejayoz Feb 01 '19 at 16:09
  • I am using docker for mac with edge version, Server Version: 18.09.1 Storage Driver: overlay2 . I tried to set ACL but it still says ACL doesn't support. Have you ever tried it on your own recently or have any solid proof that it is working on Alpine with docker default driver overlay 2. I tried it before 1 month back. – SkyRar Feb 01 '19 at 16:13
  • I'd encourage you to open up a separate question on getting ACLs to work in your Docker install rather than handling it via a series of comments. I don't use Alpine; others are likely to be able to speak to it better than I. It's highly likely it can be made to work, and it'll likely ease your deployment flow in the long run. – ceejayoz Feb 01 '19 at 16:15

1 Answers1

2

PHP is single threaded so running composer will lock it until the process is finished which means its still 'busy' when its running your shell script as it'll be waiting for that to finish.

However, it is possible to multithread it, but only from the CLI and it won't help you as you'll be starting proceedings from composer at the outset.

Have a look at this question and answers to see if it can be fit into your use case.

DevDonkey
  • 4,835
  • 2
  • 27
  • 41