bmc / daemonize

Command line utility to run a program as a Unix daemon
http://software.clapper.org/daemonize/
Other
555 stars 95 forks source link

Problem daemonizing script from systemd service #24

Open vbr96 opened 7 years ago

vbr96 commented 7 years ago

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.

drawks commented 2 years ago

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