Suggestion: add "--daemonize" parameter to web command #976

Closed
opened 2025-11-02 03:43:59 -06:00 by GiteaMirror · 9 comments
Owner

Originally created by @vizcay on GitHub (Aug 18, 2017).

A --daemonize parameter will allow better integration with daemon watchers because it doesn't blocks. For example I'm trying to configure monit with:

check process gitea
  with pidfile /var/run/gitea.pid
  start program = "/usr/bin/sudo -iu user /bin/bash -c 'cd /home/user/applications/gitea && /home/user/applications/gitea/gitea web start'"
  stop program = "/usr/bin/sudo -iu user /bin/bash -c 'cd /home/user/applications/gitea && /home/user/applications/gitea/gitea web stop'"
  if 5 restarts with 5 cycles then timeout

But it fails because it blocks and doesn't returns.

Originally created by @vizcay on GitHub (Aug 18, 2017). A **--daemonize** parameter will allow better integration with daemon watchers because it doesn't blocks. For example I'm trying to configure monit with: ``` check process gitea with pidfile /var/run/gitea.pid start program = "/usr/bin/sudo -iu user /bin/bash -c 'cd /home/user/applications/gitea && /home/user/applications/gitea/gitea web start'" stop program = "/usr/bin/sudo -iu user /bin/bash -c 'cd /home/user/applications/gitea && /home/user/applications/gitea/gitea web stop'" if 5 restarts with 5 cycles then timeout ``` But it fails because it blocks and doesn't returns.
GiteaMirror added the type/proposal label 2025-11-02 03:43:59 -06:00
Author
Owner

@vizcay commented on GitHub (Aug 21, 2017):

Just for the record (and for the next soul trying to do the same) I ended up creating a systemd wrapper around gitea, and I use that as an interface to start / stop it with monit. Instructions: https://gogs.io/docs/intro/faqs#how-do-i-run-gogs-at-startup-with-systemd%3F .

@vizcay commented on GitHub (Aug 21, 2017): Just for the record (and for the next soul trying to do the same) I ended up creating a systemd wrapper around gitea, and I use that as an interface to start / stop it with monit. Instructions: https://gogs.io/docs/intro/faqs#how-do-i-run-gogs-at-startup-with-systemd%3F .
Author
Owner

@sapk commented on GitHub (Aug 21, 2017):

We could add that possibility. In the mean time you could also simply :
"/usr/bin/sudo -iu user /bin/bash -c 'cd /home/user/applications/gitea && /home/user/applications/gitea/gitea web start &'"

@sapk commented on GitHub (Aug 21, 2017): We could add that possibility. In the mean time you could also simply : `"/usr/bin/sudo -iu user /bin/bash -c 'cd /home/user/applications/gitea && /home/user/applications/gitea/gitea web start &'"`
Author
Owner

@vizcay commented on GitHub (Aug 21, 2017):

Well I've tried that before, but it doesn't works (even it says the exit status is 0).

Here is my monit.log:

[ART Aug 21 13:01:01] error    : 'gitea' process is not running
[ART Aug 21 13:01:01] info     : 'gitea' trying to restart
[ART Aug 21 13:01:01] info     : 'gitea' start: /usr/bin/sudo
[ART Aug 21 13:01:31] error    : 'gitea' failed to start (exit status 0) -- /usr/bin/sudo: 2017/08/21 13:01:01 [T] Custom path: /home/vizcay/applications/gitea/custom
2017/08/21 13:01:01 [T] Log path: /home/vizcay/applications/gitea/log
2017/08/21 13:01:01 [I] Gitea v1.1.3 built with: bindata, sqlite

It's strange that gitead stdout gets merged with monit logs.. as far as I understand to daemonize not only means to spawn child ps as daemon but also to detach from stdout & stderr, maybe that's the cause.

@vizcay commented on GitHub (Aug 21, 2017): Well I've tried that before, but it doesn't works (even it says the exit status is 0). Here is my monit.log: ``` [ART Aug 21 13:01:01] error : 'gitea' process is not running [ART Aug 21 13:01:01] info : 'gitea' trying to restart [ART Aug 21 13:01:01] info : 'gitea' start: /usr/bin/sudo [ART Aug 21 13:01:31] error : 'gitea' failed to start (exit status 0) -- /usr/bin/sudo: 2017/08/21 13:01:01 [T] Custom path: /home/vizcay/applications/gitea/custom 2017/08/21 13:01:01 [T] Log path: /home/vizcay/applications/gitea/log 2017/08/21 13:01:01 [I] Gitea v1.1.3 built with: bindata, sqlite ``` It's strange that gitead stdout gets merged with monit logs.. as far as I understand to daemonize not only means to spawn child ps as daemon but also to detach from stdout & stderr, maybe that's the cause.
Author
Owner

@sapk commented on GitHub (Aug 21, 2017):

in this case try nohup or you could also use deamon-start-stop (available on most distrib) that is used for this case in many (old) init.d file.

@sapk commented on GitHub (Aug 21, 2017): in this case try `nohup` or you could also use `deamon-start-stop` (available on most distrib) that is used for this case in many (old) init.d file.
Author
Owner

@vizcay commented on GitHub (Aug 22, 2017):

@sapk nohup wasn't working either, but I was able to solve it with damonize (https://github.com/bmc/daemonize) in the meantime. The only thing is that I havent been able to find the PPA of it still (installed the old way).

Here is the resulting monit conf:

check process gitea
  with pidfile /var/run/gitea.pid
  start program = "/usr/local/sbin/daemonize -c /home/vizcay/applications/gitea -p /var/run/gitea.pid -u vizcay /home/vizcay/applications/gitea/gitea web start"
  stop program = "/bin/bash -c '/bin/kill $(cat /var/run/gitea.pid)'"
  if 5 restarts with 5 cycles then timeout

Edit: systemd is too complicated IMHO so I prefer to stay away of it if I can..

@vizcay commented on GitHub (Aug 22, 2017): @sapk nohup wasn't working either, but I was able to solve it with damonize (https://github.com/bmc/daemonize) in the meantime. The only thing is that I havent been able to find the PPA of it still (installed the old way). Here is the resulting monit conf: ``` check process gitea with pidfile /var/run/gitea.pid start program = "/usr/local/sbin/daemonize -c /home/vizcay/applications/gitea -p /var/run/gitea.pid -u vizcay /home/vizcay/applications/gitea/gitea web start" stop program = "/bin/bash -c '/bin/kill $(cat /var/run/gitea.pid)'" if 5 restarts with 5 cycles then timeout ``` Edit: systemd is too complicated IMHO so I prefer to stay away of it if I can..
Author
Owner

@eloo commented on GitHub (Sep 16, 2017):

yeah would be create if we could run gitea as a daemon
further it would be create if gitea would create a pidfile itself

currently i'm don't get it running with supervisord and a pidfile

@eloo commented on GitHub (Sep 16, 2017): yeah would be create if we could run gitea as a daemon further it would be create if gitea would create a pidfile itself currently i'm don't get it running with supervisord and a pidfile
Author
Owner

@bkcsoft commented on GitHub (Oct 21, 2017):

Essentially, Go doesn't really do deamonizing well https://github.com/golang/go/issues/227#issuecomment-254735160 and the package I see "highly recommended" https://github.com/sevlyar/go-daemon is IMO not an option since it's 1) POSIX only, 2) very poorly implemented and generally a bad solution.

And in general I'm with the golang devs on this, there's at least 10 different projects for deamonizing a process in linux/BSD, pick one of them.

@bkcsoft commented on GitHub (Oct 21, 2017): Essentially, Go doesn't really do deamonizing well https://github.com/golang/go/issues/227#issuecomment-254735160 and the package I see "highly recommended" https://github.com/sevlyar/go-daemon is IMO not an option since it's 1) POSIX only, 2) very poorly implemented and generally a bad solution. And in general I'm with the golang devs on this, there's at least 10 different projects for deamonizing a process in linux/BSD, pick one of them.
Author
Owner

@vizcay commented on GitHub (Nov 17, 2017):

@bkcsoft Go as a language doesn't has anything to do with daemonizing a process, because it's a behaviour of the process. As far as I can tell, if something is meant to run as a service in the unix world, you can expect at least some of that behaviour (at least dont-block going into the background and write a pidfile), everything else is a hack.

@vizcay commented on GitHub (Nov 17, 2017): @bkcsoft Go as a language doesn't has anything to do with daemonizing a process, because it's a behaviour of the process. As far as I can tell, if something is meant to run as a service in the unix world, you can expect at least some of that behaviour (at least dont-block going into the background and write a pidfile), everything else is a hack.
Author
Owner

@bkcsoft commented on GitHub (Nov 23, 2017):

Running gitea web -P ./gitea.pid & works fine for me. Still prints to stdout because it's configures to do so, but it works.

@bkcsoft commented on GitHub (Nov 23, 2017): Running `gitea web -P ./gitea.pid &` works fine for me. Still prints to stdout because it's configures to do so, but it works.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#976