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
Related
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.
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'
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.