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.
Related
I have service created with below details. I want to log myApp data to a file. File gets created with date correctly but I see the file name is generated as data-cab9605edaa5484da7c2f02b8fd10762-10-2023.json. There is extra text coming between data- and date.
Can anyone point the issue here.
[Unit]
Description=MyApp
After=network.target
[Service]
Type=simple
User=root
ExecStart=/bin/bash -c "/usr/local/MyApp > /var/log/myapp/data-$(date +\"%m-%d-%Y\").json"
Restart=on-abnormal
[Install]
WantedBy=multi-user.target
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.
im currently setting up a minecraft server on my root but struggle with the startup on boot.
Before having this in startup i was starting the server with a .sh file which i had to start manually.
the .sh file also created a screen where i was able to check the console
.sh file:
screen -AmdS minecraft java -Xms4096M -Xmx4096M -jar /home/minecraft/server/server.jar nogui
But then i tried to have the server in startup of the root server so it starts automaticly
i created a service with a .bash file which starts the server with no problem on startup but without the screen option for the console
Service:
[Unit]
Description=Start Minecraft
After=network.target
[Service]
Type=simple
ExecStart=/root/start_minecraft_server.bash
TimeoutStartSec=0
[Install]
WantedBy=default.target
Bash:
#!/bin/bash
#Standard Minecraft
cd /home/minecraft/server/
exec java -Xmx4096M -Xms1024M -jar server.jar nogui
now i want to ask if you know any easy option for adding the screen option to the service or bash file?
Try this and make sure your screen is actually in /usr/bin/ by which screen
[Unit]
Description=Start Minecraft
After=network.target
[Service]
user=minecraft
Type=simple
ExecStart=/usr/bin/screen -S Minecraft_Server -d -m sh /root/start_minecraft_server.bash
TimeoutStartSec=0
[Install]
WantedBy=default.target
But you should also alter your startcript itself:
#!/bin/bash
#Standard Minecraft
cd /home/minecraft/server/
while true; do
exec java -Xmx4096M -Xms1024M -jar server.jar nogui
done;
And just for security reasons, you should never run your mc server as root - create another user for it with limited permissions and add something like user=minecraft below the SERVICE tag in the init startscript
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.
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.