alfred icon indicating copy to clipboard operation
alfred copied to clipboard

Add ability to run alfred as a named daemon

Open iilyak opened this issue 5 years ago • 3 comments

Rationale

There are cases when some task need to be run forever in a loop. For example watching for changes in files, compiling and triggering live reload. Currently it can be implemented as alfred watch &:

  watch: ".*$"
  command: |
    compile && reload
  every: 5s

If there are multiple commands like this. In order to start all processes the one would have to create a separate script to call a number of alfred tasks. Also there is a problem of how to stop all tasks running in background. They are tottally independent processes so new invocation of alfred has no idea about them.

Proposal

Implement alfred -d <name> <task> command. This command would daemonize alfred task and remember somewhere (persistent storage maybe https://github.com/kcmerrill/alfred/issues/43) the mapping between name and pid. In addition we would implement alfred -k <name> to stop the background task. The naming of commands is not important:

  • -d/-k
  • --up/--down
  • --start/--stop

iilyak avatar Jul 27 '18 15:07 iilyak

I hear you but I think this might be outside the scope of alfred. I really like to see all the output so I tend to have another shell running when I'm rocking vim, or I have an integrated terminal running when I'm in vscode. I'm not a huge fan of running processes in the background(when there can be errors I need to see). Else, I'd use nohup or https://github.com/kcmerrill/kj. Regarding live reloading/compiling and bringing up containers this is actually my main purpose for building alfred. :)

I don't quite follow the multiple scripts to achieve this as you can do things with tasks and multitasks ... perhaps if you could clarify what you're looking for there might be a way to do what you're looking for.

kcmerrill avatar Jul 27 '18 16:07 kcmerrill

One particular example. I use alfred to start my development environment. The goal is to start up all things I need and drop me into the container which has all dependencies and tools I need. I also prefer to edit the code on my host. Which means that I need to use -v ${PWD}:/src flag when running docker container. Unfortunately this is extremely slow in case of docker on mac. There are multiple ways to speed it up. I adopted the one which uses unison tool. This is how it works in my case:

  1. I run alfred start
  2. alfred would run docker-compose up
  3. compose would start my development container and couple of side containers
  • unison container exposed on localhost port 5000
  • ssh agent container
  1. Then I need to start a filesystem watcher which would notice all changes to source and call unison blabla localhost:5000 command.
  2. When I want to start development I attach to development container using alfred shell <service> which uses docker-compose exec {{ index .Args 0 }} bash (this task is interactive: true).

I could write bash scripts to start things up. However one of the goals for this environment is to minimize the amount of commands and arguments developer need to remember.

Eventually I want to write a bootstrap.sh and alfred config which would do the following.

  • bootstrap.sh download and install golang and build alfred it would also install unison
  • alfred config would have
    • start: to run all the things and start fs watcher (fs watcher would be a background process)
    • shell: to drop developer inside the container
    • stop
  • alfred config inside the container would have project specific commands:
    • show logs
    • search source files
    • run tests
    • compile
    • cleanup
    • .... and so on

iilyak avatar Jul 30 '18 19:07 iilyak

Makes sense.

Not sure if this will help but I typically do something like this(on my mac, as I use iterm, although this can be used with any terminal manager you're using).

Multitask the watch and then also run something like this https://apple.stackexchange.com/questions/110778/open-new-tab-in-iterm-and-execute-command-there which will pop me into a new terminal(inside the container) while the original window has your watch.

kcmerrill avatar Jul 30 '18 19:07 kcmerrill