@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PhabricatorDaemonsSetupCheck extends PhabricatorSetupCheck {
4
5 public function getDefaultGroup() {
6 return self::GROUP_IMPORTANT;
7 }
8
9 protected function executeChecks() {
10
11 try {
12 $task_daemons = id(new PhabricatorDaemonLogQuery())
13 ->setViewer(PhabricatorUser::getOmnipotentUser())
14 ->withStatus(PhabricatorDaemonLogQuery::STATUS_ALIVE)
15 ->withDaemonClasses(array('PhabricatorTaskmasterDaemon'))
16 ->setLimit(1)
17 ->execute();
18
19 $no_daemons = !$task_daemons;
20 } catch (Exception $ex) {
21 // Just skip this warning if the query fails for some reason.
22 $no_daemons = false;
23 }
24
25 if ($no_daemons) {
26 $doc_href = PhabricatorEnv::getDoclink('Managing Daemons with phd');
27
28 $summary = pht(
29 'You must start the daemons to send email, rebuild search indexes, '.
30 'and do other background processing.');
31
32 $message = pht(
33 'The daemons are not running, background processing (including '.
34 'sending email, rebuilding search indexes, importing commits, '.
35 'cleaning up old data, and running builds) can not be performed.'.
36 "\n\n".
37 'Use %s to start daemons. See %s for more information.',
38 phutil_tag('tt', array(), 'bin/phd start'),
39 phutil_tag(
40 'a',
41 array(
42 'href' => $doc_href,
43 'target' => '_blank',
44 ),
45 pht('Managing Daemons with phd')));
46
47 $this->newIssue('daemons.not-running')
48 ->setShortName(pht('Daemons Not Running'))
49 ->setName(pht('Daemons Are Not Running'))
50 ->setSummary($summary)
51 ->setMessage($message)
52 ->addCommand(
53 hsprintf(
54 '<samp>%s $</samp><kbd>./bin/phd start</kbd>',
55 PlatformSymbols::getPlatformServerPath()));
56 }
57
58 $expect_user = PhabricatorEnv::getEnvConfig('phd.user');
59 if (phutil_nonempty_string($expect_user)) {
60
61 try {
62 $all_daemons = id(new PhabricatorDaemonLogQuery())
63 ->setViewer(PhabricatorUser::getOmnipotentUser())
64 ->withStatus(PhabricatorDaemonLogQuery::STATUS_ALIVE)
65 ->execute();
66 } catch (Exception $ex) {
67 // If this query fails for some reason, just skip this check.
68 $all_daemons = array();
69 }
70
71 foreach ($all_daemons as $daemon) {
72 $actual_user = $daemon->getRunningAsUser();
73 if ($actual_user == $expect_user) {
74 continue;
75 }
76
77 $summary = pht(
78 'At least one daemon is currently running as the wrong user.');
79
80 $message = pht(
81 'A daemon is running as user %s, but daemons should be '.
82 'running as %s.'.
83 "\n\n".
84 'Either adjust the configuration setting %s or restart the '.
85 'daemons. Daemons should attempt to run as the proper user when '.
86 'restarted.',
87 phutil_tag('tt', array(), $actual_user),
88 phutil_tag('tt', array(), $expect_user),
89 phutil_tag('tt', array(), 'phd.user'));
90
91 $this->newIssue('daemons.run-as-different-user')
92 ->setName(pht('Daemon Running as Wrong User'))
93 ->setSummary($summary)
94 ->setMessage($message)
95 ->addPhabricatorConfig('phd.user')
96 ->addCommand(
97 hsprintf(
98 '<samp>%s $</samp><kbd>./bin/phd restart</kbd>',
99 PlatformSymbols::getPlatformServerPath()));
100
101 break;
102 }
103 }
104 }
105
106}