daemonize icon indicating copy to clipboard operation
daemonize copied to clipboard

Problem daemonizing script from systemd service

Open vbr96 opened this issue 8 years ago • 1 comments

Hello,

When I try to daemonize a script from a systemd service:

[Unit] After=network.target [Service] ExecStart=/home/vbr/daemonize/daemonize /home/vbr/service/dfhome.sh [Install] WantedBy=default.target

the script works randomly; it writes a few bytes to the file and stop working.

The dfhome.sh script is:

#!/bin/sh

while true ; do /bin/date >> /home/vbr/service/disk_space_report.txt /usr/bin/du -sh /home/ >> /home/vbr/service/disk_space_report.txt /bin/sleep 15 done

I have tried to set the stdout to the file and replace the redirection from the script, but it not works.

However, if I exec the script directly without daemonizing it (...ExecStart=/home/vbr/service/dfhome.sh ..) , it works ok. But I prefer to daemonize in order to close files, run in background, dissasociate from terminal, etc.

Thank you.

Regards, Vic.

vbr96 avatar Apr 11 '17 16:04 vbr96

Change your systemd unit to specify Type=simple there is no need to daemonize a program run under systemd.

drawks avatar Oct 25 '22 20:10 drawks