Skip to content

Commit

Permalink
Eliminate daemonizing and use of PID files and let systemd take care …
Browse files Browse the repository at this point in the history
…of it. #1364
  • Loading branch information
mfeit-internet2 committed Nov 8, 2023
1 parent a1b3046 commit 3c839e6
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 82 deletions.
23 changes: 1 addition & 22 deletions pscheduler-server/pscheduler-server/daemons/archiver.raw
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import signal
import threading
import time

import daemon
import pscheduler

from dateutil.tz import tzlocal
Expand All @@ -27,17 +26,6 @@ pscheduler.set_graceful_exit()

opt_parser = optparse.OptionParser()

# Daemon-related options

opt_parser.add_option("--daemon",
help="Daemonize",
action="store_true",
dest="daemon", default=False)
opt_parser.add_option("--pid-file",
help="Location of PID file",
action="store", type="string", dest="pidfile",
default=None)

# Program options

opt_parser.add_option("-a", "--archive-defaults",
Expand Down Expand Up @@ -1123,13 +1111,4 @@ def main_program():



with pscheduler.PidFile(options.pidfile) as pidfile:
if options.daemon:
with daemon.DaemonContext(pidfile=pidfile):
# Any return of True means run it again.
while main_program():
pass
else:
# Ibid.
while main_program():
pass
main_program()
19 changes: 1 addition & 18 deletions pscheduler-server/pscheduler-server/daemons/runner
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Execute runs of tasks and put the results into the database.
#

import daemon
import datetime
import errno
import multiprocessing
Expand All @@ -26,17 +25,6 @@ pscheduler.set_graceful_exit()

opt_parser = optparse.OptionParser()

# Daemon-related options

opt_parser.add_option("--daemon",
help="Daemonize",
action="store_true",
dest="daemon", default=False)
opt_parser.add_option("--pid-file",
help="Location of PID file",
action="store", type="string", dest="pidfile",
default=None)

# Program options

opt_parser.add_option("-d", "--dsn",
Expand Down Expand Up @@ -970,9 +958,4 @@ def main_program():
db.close()


with pscheduler.PidFile(options.pidfile) as pidfile:
if options.daemon:
with daemon.DaemonContext(pidfile=pidfile):
main_program()
else:
main_program()
main_program()
19 changes: 1 addition & 18 deletions pscheduler-server/pscheduler-server/daemons/scheduler
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#

import copy
import daemon
import datetime
import errno
import optparse
Expand All @@ -25,17 +24,6 @@ random.seed()

opt_parser = optparse.OptionParser()

# Daemon-related options

opt_parser.add_option("--daemon",
help="Daemonize",
action="store_true",
dest="daemon", default=False)
opt_parser.add_option("--pid-file",
help="Location of PID file",
action="store", type="string", dest="pidfile",
default=None)

# Program options

opt_parser.add_option("-d", "--dsn",
Expand Down Expand Up @@ -1028,9 +1016,4 @@ def main_program():



with pscheduler.PidFile(options.pidfile) as pidfile:
if options.daemon:
with daemon.DaemonContext(pidfile=pidfile):
main_program()
else:
main_program()
main_program()
14 changes: 8 additions & 6 deletions pscheduler-server/pscheduler-server/daemons/service-template.raw
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,30 @@ Description=pScheduler server - __PROG__


[Service]
Type=simple
Type=exec
User=__PSUSER__
Group=__PSUSER__
PermissionsStartOnly=true
PIDFile=__RUNDIR__/__PROG__/pid
LimitNOFILE=32768
LimitNPROC=32768

Restart=always
RestartSec=3

# Make sure the run directory exists and is owned as expected.

# Create the run directory
ExecStartPre=-/bin/mkdir -p __RUNDIR__/__PROG__
ExecStartPre=-/bin/chown __PSUSER__:__PSUSER__ __RUNDIR__/__PROG__
ExecStartPre=-/bin/chmod 755 __RUNDIR__/__PROG__

# Set up some temporary space and export its location
ExecStartPre=-/bin/mkdir -p __RUNDIR__/__PROG__/tmp
ExecStartPre=-/bin/chmod 700 __RUNDIR__/__PROG__/tmp
ExecStartPre=-/bin/chown __PSUSER__:__PSUSER__ __RUNDIR__/__PROG__/tmp
Environment=TMPDIR=__RUNDIR__/__PROG__/tmp

# Set ownership
ExecStartPre=-/bin/chown -R __PSUSER__:__PSUSER__ __RUNDIR__/__PROG__


# Generate options file
ExecStartPre=-/bin/sh -c "if [ -r __CONFIGDIR__/__PROG__.conf ]; then opts=$(sed -e 's/#.*$//' __CONFIGDIR__/__PROG__.conf); echo OPTIONS=$opts > __RUNDIR__/__PROG__/options; chown __PSUSER__:__PSUSER__ __RUNDIR__/__PROG__/options; fi"

Expand All @@ -34,7 +36,7 @@ StandardError=journal

# Start service
EnvironmentFile=-__RUNDIR__/__PROG__/options
ExecStart=__DAEMONDIR__/__PROG__ --dsn @__DSN__ $OPTIONS --pid-file __RUNDIR__/__PROG__/pid
ExecStart=__DAEMONDIR__/__PROG__ --dsn @__DSN__ $OPTIONS

# Stop service
ExecStopPost=/bin/rm -rf __RUNDIR__/__PROG__
Expand Down
19 changes: 1 addition & 18 deletions pscheduler-server/pscheduler-server/daemons/ticker
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Operate all on-boot and periodic functions in the database.
#

import daemon
import errno
import optparse
import pscheduler
Expand All @@ -20,17 +19,6 @@ pscheduler.set_graceful_exit()

opt_parser = optparse.OptionParser()

# Daemon-related options

opt_parser.add_option("--daemon",
help="Daemonize",
action="store_true",
dest="daemon", default=False)
opt_parser.add_option("--pid-file",
help="Location of PID file",
action="store", type="string", dest="pidfile",
default=None)

# Program options

opt_parser.add_option("-d", "--dsn",
Expand Down Expand Up @@ -164,9 +152,4 @@ def main_program():
db.close()


with pscheduler.PidFile(options.pidfile) as pidfile:
if options.daemon:
with daemon.DaemonContext(pidfile=pidfile):
main_program()
else:
main_program()
main_program()

0 comments on commit 3c839e6

Please sign in to comment.