Running Binary on EC2 Instance Start

Viewed 287

I'm trying to run meilisearch on an ec2 instance, but having a lot of trouble getting it to start automatically and was wondering if somebody might be able to assist.

https://docs.meilisearch.com/guides/advanced_guides/installation.html#usage

My current user data is the following, but I'm not setting the env variable be set and the process is then starting up listening on a different port. Is there another way to set env variables in an ec2 start up script? Or is there something else I'm doing wrong?

#!/bin/bash
export MEILI_HTTP_ADDR="0.0.0.0:80"

curl -L https://install.meilisearch.com | sh

# Write systemd unit file
cat << EOF > /etc/systemd/system/meilisearch@ecs-agent.service
[Unit]
Description=Meilisearch Service %I

[Service]
Restart=always
ExecStart=/meilisearch

[Install]
WantedBy=default.target
EOF

systemctl enable meilisearch@ecs-agent.service
systemctl start meilisearch@ecs-agent.service
1 Answers

I think that the env variable that you export on line 2 of your script is not being used by Systemd.

Instead, you should provide the env variable in the service file like this:

[Service]
Restart=always
ExecStart=/meilisearch
Environment=MEILI_HTTP_ADDR=0.0.0.0:80

Please let me know if that solves your problem :)

Related