Run as Systemd
February 1, 2018 ยท View on GitHub
This covers how Hex is setup to run as a systemd service.
- Create a Hex user
sudo useradd -r -s /bin/false hex - Download the latest Hex binary from https://hexbot.io/downloads/
- Place the
hexbinary in/usr/local/bin - Create a directory for the Hex config
sudo mkdir /etc/hex - Create a directory for the Hex rules
sudo mkdir /etc/hex/rules - Create a directory for the Hex plugins
sudo mkdir /etc/hex/plugins - Create a log file
sudo touch /var/log/hex.log - Change ownership for the log file
sudo chown hex:hex /var/log/hex.log - Create a Hex config file such as
/etc/hex/config.json:
{
"slack": true,
"slack_token": "<INSERT YOUR SLACK TOKEN>",
"log_file": "/var/log/hex.log",
"rules_dir": "/etc/hex/rules",
"plugins_dir": "/etc/hex/plugins"
}
- Create a systemd service file
/etc/systemd/system/hex.service:
[Unit]
Description=HexBot
[Service]
User=hex
Group=hex
Type=simple
ExecStart=/usr/local/bin/hex /etc/hex/config.json
Restart=on-failure
[Install]
WantedBy=multi-user.target
- Register the service file
sudo systemctl enable hex.service - Create your first Hex rule
/etc/hex/rules/hello.json:
{
"rule": "hello",
"match": "@hex hello",
"actions": [
{ "type": "hex-response", "command": "Hello ${hex.user}!" }
]
}
- Change the ownership of all Hex configuration
sudo chown -R hex:hex /etc/hex - Startup the Hex service
sudo systemctl start hex - Check in Slack if the Hex bot shows and ask
@hex helloand it should respond.