Skip to content

Commit f376330

Browse files
authored
Add option to run scc-daemon in foreground (#90)
1 parent edcd536 commit f376330

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

scc/bin/scc_daemon.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def main() -> None:
1414
parser.add_argument("command", type=str, choices=["start", "stop", "restart", "debug"])
1515
parser.add_argument("--alone", action="store_true", help="prevent scc-daemon from launching osd-daemon and autoswitch-daemon")
1616
parser.add_argument("--once", action="store_true", help="use with 'stop' to send single SIGTERM without waiting for daemon to exit")
17+
parser.add_argument("--foreground", action="store_true", help="run scc-daemon in foreground")
1718
daemon = SCCDaemon(get_pid_file(), get_daemon_socket())
1819
args = parser.parse_args()
1920
daemon.alone = args.alone
@@ -25,7 +26,7 @@ def main() -> None:
2526
# from config
2627

2728
if args.command == "start":
28-
daemon.start()
29+
daemon.start(foreground = args.foreground)
2930
elif args.command == "stop":
3031
daemon.stop(once = args.once)
3132
elif args.command == "restart":

scc/lib/daemon.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def delpid(self):
7373
"""Delete pid file"""
7474
os.remove(self.pidfile)
7575

76-
def start(self):
76+
def start(self, foreground=False):
7777
"""Start the daemon."""
7878

7979
# Check for a pidfile to see if the daemon already runs
@@ -103,7 +103,10 @@ def start(self):
103103
sys.stderr.write("Overwriting stale pidfile\n")
104104

105105
# Start the daemon
106-
self.daemonize()
106+
if not foreground:
107+
self.daemonize()
108+
else:
109+
self.write_pid()
107110
syslog.syslog(syslog.LOG_INFO, '{}: started'.format(os.path.basename(sys.argv[0])))
108111
self.on_start()
109112
while True:

0 commit comments

Comments
 (0)