People ask this question in different ways:
- How do I make TabPy to start automatically?
- How can I run TabPy in background?
- How can I run TabPy as if it was a service?
Answer to these questions are different depending on your OS and can even be different for different versions of the same OS.
In this post I am showing the simplest way to make TabPy something like a Windows service – which means it starts automatically and runs in background. For the following steps, I assume you have TabPy environment configured in Anaconda (read https://tabscifi.golovatyi.info/category/anaconda/ for more examples and how-to’s for using Anaconda with analytics extensions).
With my Anaconda I have
tabpy_demo environment where TabPy package is installed:
Next, I created
c:\demo\TabPy_as_a_service folder with the simple config file in it:
[TabPy] TABPY_PORT = 9004 [loggers] keys=root [handlers] keys=rootHandler [formatters] keys=rootFormatter [logger_root] level=DEBUG handlers=rootHandler qualname=root propagete=0 [handler_rootHandler] class=handlers.RotatingFileHandler level=DEBUG formatter=rootFormatter args=('tabpy_log.log', 'a', 1000000, 5) [formatter_rootFormatter] format=%(asctime)s %(levelname)ss:%(lineno)d): %(message)s datefmt=%Y-%m-%d,%H:%M:%S
For more information about custom TabPy config consider reading posts at https://tabscifi.golovatyi.info/category/tabpy-configuration/.
Now let’s create a task with Task Scheduler (Start->Task Scheduler). In Task Scheduler Library click Create Task… on Actions pane on the right. In the task dialog specify the task name (I use “TabPy as a Service” in this example), and choose if you want the task to run with specific account.
On Triggers tab click New… and specify At startup – now the task runs automatically at system startup.
On Actions tab add new action Start a program and use the following parameters:
- For Program/script use
- For arguments at Add arguments enter `”/K c:\ProgramData\Anaconda3\Scripts\activate.bat tabpy_demo && tabpy –config tabpy.conf”`. More about the string below.
- For Start in specify folder you have your config file in. The same folder will have TabPy logs in my case.
The arguments string above means:
- /K tells
cmdto run the command and continue (documentation for
cmdis here – https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/cmd).
c:\ProgramData\Anaconda3\Scripts\activate.bat tabpy_demoactivates Anaconda environment
tabpy_demo. For you this part will be different: Anaconda can be installed in a different folder and TabPy environment will have a different name.
tabpy --config tabpy.confstarts TabPy with the custom configuration file in
c:\demo\TabPy_as_a_servicefolder specifies as Start in folder.
On Conditions and Settings tabs change parameters as needed.
Now you can test the task – click Run action on Actions pane. If the task was configured properly you’ll see TabPy is running.
Log files for TabPy can be found in the same
c:\demo\TabPy_as_a_service folder where config file is:
Now we have TabPy scheduled to start on a system start up.
One question remains – how can I make
cmd window go away? It is possible and requires a little bit of scripting so I am saving it for the next post 😉