0

I created a small go program that uses these go bindings to record some commands from the default microphone and act accordingly. It works fine as a standalone binary(both as normal user and root user) but when I tried to convert it into a systemd unit the Capture function in the go bindings failed with error saying connection refused.

The program is failing to capture the microphone input when running as a systemd service. The following is the unit file which is pretty much copy-pasted from here.

[Unit]
Description=Commander service providing voice commands

[Service]
ExecStart=/path/to/binary/binary.sh

[Install]
WantedBy=multi-user.target

binary.sh is a simple shell script that for providing environment variables to the go binary. The script is below

#!/bin/bash
cd /path/to/binary
env LD_LIBRARY_PATH=/usr/local/lib ./binary > stdout 2> stderr

The LD_LIBRARY_PATH is needed for pocketsphinx shared libraries which is being used for recognizing commands from audio.

I think something is wrong with the unit file but I don't know what it is. The whole project can be found here.

Any insight would be helpful. Thanks.

2 Answers2

0

pulseaudio is a daemon which probably has yet to get launched ... update your binary.sh with a

sleep 10
echo about to determine whether pulseaudio is up and running
pulseaudio --check
echo if pulseaudio is running above check silently returns

prior to launching your golang binary

Scott Stensland
  • 26,870
  • 12
  • 93
  • 104
  • Hi Scott, thanks for the input but `pulseaudio` is running. I'm testing the service side-by-side with the binary. The binary is running but the service is giving me problems. I'll add this check though once this problem is solved. – Siddharth Shishulkar Aug 15 '18 at 12:23
0

It is required to set XDG_RUNTIME_DIR environmental variable to directory /run/user/<USER_ID>, e.g.

[Service]
Environment="XDG_RUNTIME_DIR=/run/user/1001"
ExecStart=/path/to/binary/binary.sh