Systemd ExecStart with arguments - linux

I have process, that i run in this way :
sudo RADIODEV=/dev/spidev0.0 /opt/basicstation/build-rpi-std/bin/station -d -h /opt/basicstation/build-rpi-std/bin
I would like to lunch it on raspberry boot with systemctl like that :
[Unit]
Description=Basic station secure websocket
Wants=network-online.target
After=network-online.target
[Service]
User=root
Group=root
ExecStart= RADIODEV=/dev/spidev0.0 /opt/basicstation/build-rpi-std/bin/station -d -h /opt/basicstation/build-rpi-std/bin
[Install]
WantedBy=multi-user.target
Alias=basic_station.service
So i want to know how put the argument
RADIODEV=/dev/spidev0.0
-d
-h /opt/basicstation/build-rpi-std/bin
because wheni just put :
ExecStart= RADIODEV=/dev/spidev0.0 /opt/basicstation/build-rpi-std/bin/station -d -h /opt/basicstation/build-rpi-std/bin
That's not work
I already check some issue like :
issue systemd
But i can't reproduce what they propose.

Related

systemd and ExecStart with arguments with parsing errors

I have created a fluidsynth service with this ".service" file:
[Unit]
Description=fluidsynth-ng
After=xsynth-network.service
[Service]
EnvironmentFile=/etc/fluidsynth-ng.conf
ExecStart=/usr/bin/fluidsynth -a $AUDIO_DEVICE -c $AUDIO_BUFFERS -z $BUFFER_SIZE -r $SAMPLE_RATE -s -o shell.port=9988 -m $MIDI_DRIVER -i
Type=simple
User=root
Group=root
PIDFile=/tmp/fluidsynth-ng.pid
[Install]
WantedBy=multi-user.target
The problem is I want to pass port parameter to ExecStart but it doesn't work:
[Unit]
Description=fluidsynth-ng
After=xsynth-network.service
[Service]
EnvironmentFile=/etc/fluidsynth-ng.conf
ExecStart=/usr/bin/fluidsynth -a $AUDIO_DEVICE -c $AUDIO_BUFFERS -z $BUFFER_SIZE -r $SAMPLE_RATE -s -o shell.port=$SERVER_PORT -m $MIDI_DRIVER -i
Type=simple
User=root
Group=root
PIDFile=/tmp/fluidsynth-ng.pid
[Install]
WantedBy=multi-user.target
I think there's a problem with $SERVER_PORT parse, because I get this error: "fluidsynth: error: Failed to bind server socket"
EnvironmentFile looks correct:
AUDIO_DEVICE=jack
SERVER_PORT=9988
SAMPLE_RATE=48000
AUDIO_BUFFERS=2
BUFFER_SIZE=64
MIDI_DRIVER=alsa_seq
Any help?
Launch either ss -tulp or netstat -tulp to check which ports are open and which process is listening on your port 9988, and you will probably see some other instance of your process already listening, so you can't assign the port to a different process.

How to start Greeplum on boot - linux

Trying to start Greenplum on system startup. Please find systemd service file content below.
[Unit]
Description=Greenplum daemon
[Service]
EnvironmentFile=/etc/environment
EnvironmentFile=/etc/default/greenplum
User=gpadmin
Group=gpadmin
Type=simple
ExecStartPre=/bin/bash -c "source /opt/greenplum-db-6-6.11.2/greenplum_path.sh"
#ExecStartPre=/opt/greenplum-db-6-6.11.2/greenplum_path.sh
ExecStart=/opt/greenplum-db-6-6.11.2/bin/gpstart -a -l /home/gpadmin/gpAdminLogs -d /greenplum/master/gpseg-1
Restart=on-failure
RestartSec=5s
PrivateTmp=true
[Install]
WantedBy=multi-user.target
All required environment variables are loaded and required path is sourced still not able to start service. Getting "ImportError: No module named gppylib.mainUtils". After machine is started if I run start command(/opt/greenplum-db-6-6.11.2/bin/gpstart -a -l /home/gpadmin/gpAdminLogs -d /greenplum/master/gpseg-1) it is working fine. I am not able to understand what is going wrong. My current setup has two hosts(master and segment host). I have kept segment node up and trying on master. Any help is much appreciated.
Sourcing greenplum_path.sh in ExecStartPre won't work because the environment isn't preserved between ExecStartPre and ExecStart. I would try something like
ExecStart=/bin/bash -c "source /opt/greenplum-db-6-6.11.2/greenplum_path.sh; gpstart -a -l /home/gpadmin/gpAdminLogs -d /greenplum/master/gpseg-1.

Could not edit systemd service file

Need to edit following entries:
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
in /lib/systemd/system/docker.service file
$ sudo -E systemctl edit docker.service
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2376 --containerd=/run/containerd/containerd.sock
did not update the service file after restart(sudo systemctl restart docker.service)
Edit
On AWS EC2, below is the issue:
$ nano /etc/systemd/system/docker.service.d/override.conf
$ sudo systemctl daemon-reload
$ sudo systemctl restart docker
/lib/systemd/system/docker.service still shows unmodified
1) What is the recommended approach to edit service file(docker.service)?
2) Why /lib/systemd/system/docker.service cannot be edited directly?
You need to create a systemd drop-in file for docker.service.
Create /etc/systemd/system/docker.service.d/override.conf file with contents
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2376 --containerd=/run/containerd/containerd.sock
Reload systemd unit files.
systemctl daemon-reload
NOTE: Reloading systemctl daemon is required after editing any systemd unit file that's as per systemd design. For more info check this.
Restart docker daemon.
systemctl restart docker
You need to restart docker daemon to pick up the latest updated systemd unit file.
For more info check this.

Adding a shell command inside/inline of a systemd service file

I am running the gunicorn server as a service via systemd, Here is the sample service file:
[Unit]
Description=Gunicorn NGINX
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/test
ExecStart=/usr/local/bin/gunicorn --workers 8 --threads 8 --backlog 100 --bind 10.0.0.20:5000 -m 777 abc:app
Restart=always
[Install]
WantedBy=multi-user.target
I want now to replace the number near --workers and --threads by number of cores using the shell command so that it will dynamically pick the number of cores
nproc --all
Can someone help me how to do this
You can explicitly invoke a shell to get shell parsing.
ExecStart=/bin/bash -c '/usr/local/bin/gunicorn --workers "$(nproc --all)" --threads "$(nproc --all)" --backlog 100 --bind 10.0.0.20:5000 -m 777 abc:app'

systemd-path service not working

I have added systemd service to monitor a path. But it is not working. I touched a .txt file under /tmp/test/. But it is not kicking in my service. I cant see "/tmp/testlog.txt" getting generated. Is there anything wrong in my service?
myservice.path
[Unit]
Description=Path Exists
[Path]
PathExistsGlob=/tmp/test/*.txt
PathChanged=/tmp/test/
[Install]
WantedBy=multi-user.target
myservice.service
[Unit]
Description=Test
[Service]
ExecStartPre=/bin/sh -c 'mkdir /tmp/test && sleep 60'
ExecStart=/bin/sh -c 'echo "Test Success" >> /tmp/testlog.txt & '
[Install]
WantedBy=multi-user.target
tmp dir:
# ls /tmp/test/
ab.txt
#
What could be the reason for the failure?
That was a timing issue. I added dependency and made this service to start as the very last one. That one solved the issue.

Resources