Bare-bones cross-platform process dispatcher and manager.
Create a configuration file, then run with:
python3 tsk.py [config]
where config
is the (optional) path to a JSON configuration file, defaulting to
~/.tsk.json
.
- Python 3.6+
Prior to running, you should create a JSON configuration file that specifies the processes to be managed, and optionally the directory in which to place the logs:
{
"logs": "~\\.tsk.log",
"log-archive": 5,
"processes":
[
{
"name": "DB",
"cmd": "docker-compose up database",
"stop": "docker-compose stop database",
"cwd": "~\\Development\\docker-workspace"
},
{
"name": "Webpack",
"cmd": "yarn develop",
"cwd": "~\\Development\\Application\\Application.Web",
"shell": true,
"taskkill": true
},
{
"name": "Storage Emulator",
"cmd": "\"C:\\Program Files (x86)\\Microsoft SDKs\\Azure\\Storage Emulator\\AzureStorageEmulator.exe\" start -inprocess",
"stop": "\"C:\\Program Files (x86)\\Microsoft SDKs\\Azure\\Storage Emulator\\AzureStorageEmulator.exe\" stop",
"timeout": 10
}
]
}
If tsk cannot find a configuration file at startup, it will create an example file.
name
: The name tsk will use to refer to this processcmd
: The command that will be issued to start the processstop
(optional): The command that will be issued to stop the processcwd
(optional): The directory to use as the current working directory for bothcmd
andstop
shell
(optional): Setshell
totrue
to start the process in an intermediate shelltaskkill
(optional, Windows only): When killing a process, uses Windows'taskkill
command, which can help clean up child processestimeout
(optional): The number of seconds to wait after issuingstop
before killing the process (defaults to 30 seconds)
Each process specified in the configuration file is assigned a number. If the process is not running, pressing the associated key will start the process. If the process is already running, pressing the key will stop the process.
The status listed for each process is updated when the screen is refreshed. To refresh, simply press any key other than those listed for process management (e.g., spacebar).
If the configuration file specifies a specific stop command for the process, attempting to
stop the process will result in this command being issued, at which point tsk will wait
for the process to stop. An optional timeout
for the stop command may be specified
(defaulting to 30 seconds).
If no stop command is specified (or if the stop process times out), tsk will force the
process to stop by issuing a kill command. On Windows, if taskkill
is set to true
, the
taskkill
command will be used (this can help clean up child processes that may be bound
to ports or writing to logs).
Each process is logged in its own log file in the specified logs
directory.
If no logs
directory is specified in the configuration file, it defaults to
~/.tsk.log/
.
When a process is started, any existing log file is placed in a zip archive, and only the
last few are kept. The number of past logs to keep is specified by log-archive
in the
configuration file (defaulting to 5).
Cross-platform getch
implementation from this Gist
by jfktrey.
Written by Gem Newman. Website | GitHub | Twitter
This work is licensed under the Mozilla Public License 2.0.
Remember: GitHub is not my CV.