I have a custom service in /etc/systemd/system/microphone_disable_startup.service
[Unit]
Description=Disable microphone on startup
After=alsa-restore.service
[Service]
ExecStart=/opt/bin/check_mic_startup
The script that is executed is check_mic_startup located in /opt/bin
#!/bin/bash
# DEBUG: touch /home/GeorgeMP/Desktop/testfile_works
i_toggle=$(amixer get Capture toggle | grep -c "\[on\]")
if [ $i_toggle = 2 ] ; then
amixer -q set Capture toggle
fi
amixer -q set Capture 0%
echo Microphone turned OFF
exit 0
As you can see I have tried debugging the service with the touch command, and it works flawlessly, even when used by the service. The problem is with the more complex commands in the script.
Doing a systemctl status on my custom service, i can check that the service succeded without errors.
microphone_disable_startup.service - Disable microphone on startup
Loaded: loaded (/etc/systemd/system/microphone_disable_startup.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Tue 2020-12-01 17:36:39 CET; 8min ago
Process: 610 ExecStart=/opt/bin/check_mic_startup (code=exited, status=0/SUCCESS)
Main PID: 610 (code=exited, status=0/SUCCESS)
Dec 01 17:36:39 GeorgeMP systemd[1]: Started Disable microphone on startup.
Dec 01 17:36:39 GeorgeMP systemd[1]: microphone_disable_startup.service: Succeeded.
However, after restarting/shutting down even though it executed successfully, the command didn't execute or it happened without any effect because
amixer get Capture
Simple mixer control 'Capture',0
Capabilities: cvolume cswitch
Capture channels: Front Left - Front Right
Limits: Capture 0 - 63
Front Left: Capture 63 [100%] [30.00dB] [on]
Front Right: Capture 63 [100%] [30.00dB] [on]
They are 100% and turned [on].
They should be 0% and [off]
If i execute /opt/bin/check_mic_startup from the terminal, it works flawlessly. Even so if i do systemctl start microphone_disable_startup.service. It just doesn't work when used by my custom service microphone_disable_startup.service What's the issue?
EDIT 1:
I change my script to this to contain the /opt/bin directory too
#!/bin/bash
# DEBUG: touch /home/GeorgeMP/Desktop/testfile_works
# USE THESE IF NEEDED SOMEWHERE ELSE
#DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus"
#DISPLAY=":0.0"
export PATH="$PATH:/opt/bin"
i_toggle=$(/usr/bin/amixer get Capture toggle | grep -c "\[on\]")
if [ $i_toggle = 2 ] ; then
/usr/bin/amixer -q set Capture toggle
fi
/usr/bin/amixer -q set Capture 0%
echo Microphone turned OFF
env > /home/GeorgeMP/Desktop/environment
exit 0
And i check and every command can be accessed by the script in the new environment.
By the way, the environment file that was created on my Desktop is
LC_ADDRESS=en_US.UTF-8
LC_NAME=en_US.UTF-8
LC_MONETARY=en_US.UTF-8
PWD=/
LC_PAPER=en_US.UTF-8
LANG=en_US.UTF-8
INVOCATION_ID=549485b12a4149bb889e55d42711e923
LC_IDENTIFICATION=en_US.UTF-8
SHLVL=1
LC_TELEPHONE=en_US.UTF-8
LC_MEASUREMENT=en_US.UTF-8
LC_TIME=en_US.UTF-8
JOURNAL_STREAM=9:26568
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/opt/bin
LC_NUMERIC=en_US.UTF-8
_=/usr/bin/env
So it contains the /opt/bin path. It still doesn't work... but when i run the script in the terminal it works...
0 Answers