I created an Alfred workflow to manage a local server script. It's basically a mini HTTP server that performs actions by calling particular URLs. This is what the workflow looks like:
The script filter comes from a static XML file, just to get a list of actions to choose from:
<?xml version='1.0'?>
<items>
<item arg='./start_server.sh'>
<title>Start server</title>
</item>
<item arg='/usr/bin/curl -s "http://127.0.0.1:7070/start"'>
<title>Start downloader</title>
</item>
<item arg='/usr/bin/curl -s "http://127.0.0.1:7070/stop"'>
<title>Stop downloader</title>
</item>
<item arg='/usr/bin/curl -s "http://127.0.0.1:7070/shutdown"'>
<title>Shutdown server</title>
</item>
</items>
As you can see, the shell commands are inside of the arg
attribute, which is passed to the next step in the workflow when selecting an entry.
The Run Script step is as bare as could be:
No escaping, no additional commands… It just takes the output from the Script Filter and executes it in a shell.
The start_server.sh
is a bit special because:
Contents of the start_server.sh
script:
#!/bin/bash
source $HOME/Development/virtualenv/alfred/bin/activate
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
nohup python traffic_server.py & disown
Whenever the server (Python script) is started through Alfred, I'm unable to shut it down again through Alfred (the HTTP call through cURL).
What does work (using the same script and commands each time):
I can tell the server is running when started from Alfred, through the PID file that's created. I can also see that when I try to stop it through Alfred, the PID file is still there and the process remains active.
It seems that whenever I start the server through Alfred, it won't listen to any subsequent calls coming from Alfred.
Debugging is rather limited in Alfred, so any hints / suggestions would be appreciated!
I finally found what's causing the issue, but can't really explain it fully yet.
The Run Script step was set to run the scripts sequentially. I didn't expect this to be an issue, as the calls to curl
were instantaneous, and the actual script was started with nohup
and disown
. However, it seems that even with those two additional keywords, it still blocks any following commands from executing.
I assume that this is something specifically related to Alfred?