diff --git a/roles/services/tasks/discord_bot.yaml b/roles/services/tasks/discord_bot.yaml index 1f159bb..de74de0 100644 --- a/roles/services/tasks/discord_bot.yaml +++ b/roles/services/tasks/discord_bot.yaml @@ -4,7 +4,17 @@ name: - python3-paho-mqtt - python3-tz - # Not in apt, install manually: discord.py, discord_webhook + - virtualenv + +- name: Create virtualenv + command: virtualenv /opt/miflora_exporter/.venv + args: + creates: /var/lib/discord-bot/.venv + +- name: Install Python dependencies + shell: . .venv/bin/activate && pip install -r requirements.txt + args: + chdir: /var/lib/discord-bot - name: Clone source git: diff --git a/roles/services/templates/discord-bot.service b/roles/services/templates/discord-bot.service index e022601..179628c 100644 --- a/roles/services/templates/discord-bot.service +++ b/roles/services/templates/discord-bot.service @@ -8,7 +8,7 @@ After=network.target Type=simple Restart=on-failure RestartSec=10s -ExecStart=/var/lib/discord-bot/main.py +ExecStart=/var/lib/discord-bot/.venv/bin/python /var/lib/discord-bot/main.py DynamicUser=true Environment="DISCORD_TOKEN={{ discord_token }}"