kcmerrill / alfred

(v0.2) Even Batman needs a little help. Task runner. Automator. Build system.
MIT License
64 stars 14 forks source link

How to run task in background #85

Closed iilyak closed 6 years ago

iilyak commented 6 years ago

I am using alfred to start development environment. My development environment includes few long running processes which need to stay running after alfred start finishes. I am sure I am doing something wrong.

I am trying to do something like the following

start:
  tasks:
    task1
    task2

task1:
  command: echo task1

task2:
  command: alfred -no-formatting task3 &

task3:
  command: sleep 100 && echo task3
iilyak commented 6 years ago

following worked

test:
  tasks:
    task1
    task2

task1:
  command: echo task1

task2:
  command: nohup alfred -no-formatting task3 > /dev/null 2>&1 &
  exit: 0

task3:
  command: sleep 100 && echo task3
iilyak commented 6 years ago

Now I need to invent a way to implement stop command. Probably would have to rely on a pid file.

kcmerrill commented 6 years ago

Just curious but why do you want to run it in the background?

On Fri, Jul 27, 2018, 9:00 AM iilyak notifications@github.com wrote:

Now I need to invent a way to implement stop command. Probably would have to rely on a pid file.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/kcmerrill/alfred/issues/85#issuecomment-408445319, or mute the thread https://github.com/notifications/unsubscribe-auth/AAqMSVUxTYL4OLZUyoz9eqUsxt5SAGzzks5uKyscgaJpZM4VjJ-Y .

kcmerrill commented 6 years ago

There are a bunch of other considerations that you might need to account for. Either way, you can use nohop for example, or check out another tiny project of mine kj on my GitHub repos.

On Fri, Jul 27, 2018, 9:10 AM Casey M. kcmerrill@gmail.com wrote:

Just curious but why do you want to run it in the background?

On Fri, Jul 27, 2018, 9:00 AM iilyak notifications@github.com wrote:

Now I need to invent a way to implement stop command. Probably would have to rely on a pid file.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/kcmerrill/alfred/issues/85#issuecomment-408445319, or mute the thread https://github.com/notifications/unsubscribe-auth/AAqMSVUxTYL4OLZUyoz9eqUsxt5SAGzzks5uKyscgaJpZM4VjJ-Y .

iilyak commented 6 years ago

I ended up using nohop to start process and pgrep -f "alfred -no-formatting task_namepwd". By passing pwd I can make sure I reliably find the pid of a running process.