How to run rasa as service in linux?

Hi all, Now i am running rasa and actions in two-terminal. I want to run as a service. How can i do this?

2 Likes

Not sure, what you call a service. If you want to run everything in a single terminal just start the action server in the background, but the on-screen log will get messier. So make sure to write everything to files.

Now i am running the rasa using rasa run --enable-api --cors "*" and for actions rasa run actions in another terminal. When i close these terminal the rasa stops. So i want to run like sudo service rasa start. How can i do this?

Rasa Version: 1.5.3 Python Version : 3.7 OS : Debian 10

First, you have to create a service file in /etc/systemd/system/

nano /etc/systemd/system/rasa-core.service

[Unit]
Description=Rasa-Core
After=multi-user.target
[Service]
Type=simple
WorkingDirectory=<path-to-rasa-project-directory>
ExecStart=<path-to-python-bin>/bin/python3 -m rasa run --cors '*' --model <path-to-rasa-project-directory>/models/ --endpoints <path-to-rasa-project-directory>/endpoints.yml --credentials <path-to-rasa-project-directory>/credentials.yml
User=root
Group=daemon

Then run: systemctl daemon-reload Start service: service rasa-core start Check Status: service rasa-core status

To run action server as service : nano /etc/systemd/system/rasa-action.service

[Unit]
Description=Rasa-Action
After=multi-user.target
[Service]
Type=simple
WorkingDirectory=<path-to-rasa-project-directory>
ExecStart=<path-to-python-bin>/bin/python3 -m rasa_sdk --actions actions
User=root
Group=daemon

Then run: systemctl daemon-reload Start service: service rasa-action start Check Status: service rasa-action status

I am using root user to run my service and python virtual environment so I am passing different python path.

I hope it will help :slight_smile:

3 Likes

I tried what ShreyasNayak posted, and it kinda works. When I start the core service it executes right, but as soon as I try to talk with the bot the core service crashes with this msg:

Feb 14 14:47:32 instance-2 python3[8231]: 2020-02-14 14:47:32 DEBUG    rasa.core.processor  - Logged UserUtterance - tracker now has 4 events.
Feb 14 14:47:32 instance-2 python3[8231]: 2020-02-14 14:47:32 DEBUG    rasa.core.policies.memoization  - Current tracker state [None, None, No
Feb 14 14:47:32 instance-2 python3[8231]: 2020-02-14 14:47:32 DEBUG    rasa.core.policies.memoization  - There is no memorised next action
Feb 14 14:47:32 instance-2 python3[8231]: 2020-02-14 14:47:32 DEBUG    rasa.core.policies.form_policy  - There is no active form
Feb 14 14:47:32 instance-2 python3[8231]: 2020-02-14 14:47:32 DEBUG    rasa.core.policies.fallback  - NLU confidence threshold met, confidence
Feb 14 14:47:32 instance-2 python3[8231]: 2020-02-14 14:47:32 DEBUG    rasa.core.policies.ensemble  - Predicted next action using policy_0_Ker
Feb 14 14:47:32 instance-2 python3[8231]: 2020-02-14 14:47:32 DEBUG    rasa.core.processor  - Predicted next action 'action_comienzo' with con
Feb 14 14:47:32 instance-2 python3[8231]: 2020-02-14 14:47:32 DEBUG    rasa.core.actions.action  - Calling action endpoint to run action 'acti
Feb 14 14:47:33 instance-2 systemd[1]: chatbot_core.service: Main process exited, code=killed, status=11/SEGV
Feb 14 14:47:33 instance-2 systemd[1]: chatbot_core.service: Failed with result 'signal'.

If I run the core from a terminal it works at usual, but if I do it from the service that error happens.

Does anyone have the same issue or know how to solve it? Im working on Ubuntu 18.04 and Rasa-1.7.0

It happens right after the action server is called. Is an action server running? If yes, does it get the request? If yes, does it work as intended or is there an exception?

Just trying to guess, what the problem is.

Hi @ShreyasNayak,

Thanks for the service. Can you also add an argument for logging actions into a file? I tried using piping to file. But no luck. I’m a newbie to Linux. Thanks

Hi @vsatyav007

[ My environment, Rasa Version: 1.5.3 Python Version: 3.7 OS: Debian 10 ]

RASA Core: If you want to log rasa-core, you can use command-line arguments --log-file

ExecStart=<path-to-python-bin>/bin/python3 -m rasa run --cors '*' --model <path-to-rasa-project-directory>/models/ --endpoints <path-to-rasa-project-directory>/endpoints.yml --credentials <path-to-rasa-project-directory>/credentials.yml --log-file /var/log/rasa_core.log

RASA Action Server: If you want to log rasa-action-server, I don’t think there is something like --log-file

But I am using logging python libraries, But it won’t capture all message (Which we see when we run from the terminal )

import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

# create a file handler
handler = logging.FileHandler('/var/log/rasa_action_server.log')
handler.setLevel(logging.INFO)

# create a logging format
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)

# add the file handler to the logger
logger.addHandler(handler)

logger.info('Action Server is running')

Also, you can try journalctl command

journalctl --unit your_service_name.service --lines=100

There are so many command line arguments in journalctl to filer the log

If I get some better solution I will post it here :slightly_smiling_face: