Skip to content

Commit c041e2c

Browse files
authored
Merge pull request #47 from jameshcorbett/dws-systemd-service
Dws systemd service
2 parents 7e03704 + 6476759 commit c041e2c

File tree

8 files changed

+209
-11
lines changed

8 files changed

+209
-11
lines changed

Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.NOTPARALLEL:
22

3-
SUBDIRS = . src t
3+
SUBDIRS = . src etc t
44

55
EXTRA_DIST = \
66
config/tap-driver.sh \

config/adl_recursive_eval.m4

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
dnl
2+
dnl Unknown origin, but was presumably part of autoconf-archive at
3+
dnl some point in the past.
4+
dnl
5+
dnl adl_RECURSIVE_EVAL(VALUE, RESULT)
6+
dnl =================================
7+
dnl Interpolate the VALUE in loop until it doesn't change,
8+
dnl and set the result to $RESULT.
9+
dnl WARNING: It's easy to get an infinite loop with some unsane input.
10+
AC_DEFUN([adl_RECURSIVE_EVAL],
11+
[_lcl_receval="$1"
12+
$2=`(test "x$prefix" = xNONE && prefix="$ac_default_prefix"
13+
test "x$exec_prefix" = xNONE && exec_prefix="${prefix}"
14+
_lcl_receval_old=''
15+
while test "[$]_lcl_receval_old" != "[$]_lcl_receval"; do
16+
_lcl_receval_old="[$]_lcl_receval"
17+
eval _lcl_receval="\"[$]_lcl_receval\""
18+
done
19+
echo "[$]_lcl_receval")`])

config/systemd.m4

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
dnl Probe for systemd libraries and installation paths.
2+
dnl
3+
dnl Provides the RRA_WITH_SYSTEMD_UNITDIR macro, which adds the
4+
dnl --with-systemdsystemunitdir configure flag, sets the systemdsystemunitdir
5+
dnl substitution variable, and provides the HAVE_SYSTEMD Automake conditional
6+
dnl to use to control whether to install unit files.
7+
dnl
8+
dnl Provides the RRA_LIB_SYSTEMD_DAEMON_OPTIONAL macro, which sets
9+
dnl SYSTEMD_CFLAGS and SYSTEMD_LIBS substitution variables if
10+
dnl libsystemd-daemon is available and defines HAVE_SD_NOTIFY. pkg-config
11+
dnl support for libsystemd-daemon is required for it to be detected.
12+
dnl
13+
dnl Depends on the Autoconf macros that come with pkg-config.
14+
dnl
15+
dnl The canonical version of this file is maintained in the rra-c-util
16+
dnl package, available at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
17+
dnl
18+
dnl Written by Russ Allbery <[email protected]>
19+
dnl Copyright 2013, 2014
20+
dnl The Board of Trustees of the Leland Stanford Junior University
21+
dnl
22+
dnl This file is free software; the authors give unlimited permission to copy
23+
dnl and/or distribute it, with or without modifications, as long as this
24+
dnl notice is preserved.
25+
26+
dnl Determine the systemd system unit directory, along with a configure flag
27+
dnl to override, and sets @systemdsystemunitdir@. Provides the Automake
28+
dnl HAVE_SYSTEMD Automake conditional.
29+
AC_DEFUN([RRA_WITH_SYSTEMD_UNITDIR],
30+
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])
31+
AS_IF([test x"$PKG_CONFIG" = x], [PKG_CONFIG=false])
32+
AC_ARG_WITH([systemdsystemunitdir],
33+
[AS_HELP_STRING([--with-systemdsystemunitdir=DIR],
34+
[Directory for systemd service files])],
35+
[],
36+
[with_systemdsystemunitdir=\${prefix}$($PKG_CONFIG --variable=systemdsystemunitdir systemd)])
37+
AS_IF([test x"$with_systemdsystemunitdir" != xno],
38+
[AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])])
39+
AM_CONDITIONAL([HAVE_SYSTEMD],
40+
[test -n "$with_systemdsystemunitdir" -a x"$with_systemdsystemunitdir" != xno])])
41+
42+
dnl Check for libsystemd-daemon and define SYSTEMD_DAEMON_{CFLAGS,LIBS} if it
43+
dnl is available.
44+
AC_DEFUN([RRA_LIB_SYSTEMD_DAEMON_OPTIONAL],
45+
[PKG_CHECK_EXISTS([libsystemd-daemon],
46+
[PKG_CHECK_MODULES([SYSTEMD_DAEMON], [libsystemd-daemon])
47+
AC_DEFINE([HAVE_SD_NOTIFY], 1, [Define if sd_notify is available.])])])

config/x_ac_expand_install_dirs.m4

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
##*****************************************************************************
2+
## $Id: x_ac_expand_install_dirs.m4 494 2006-05-08 22:59:28Z dun $
3+
##*****************************************************************************
4+
# AUTHOR:
5+
# Chris Dunlap <[email protected]>
6+
#
7+
# SYNOPSIS:
8+
# X_AC_EXPAND_INSTALL_DIRS
9+
#
10+
# DESCRIPTION:
11+
# Expand the installation directory variables.
12+
##*****************************************************************************
13+
14+
AC_DEFUN([X_AC_EXPAND_INSTALL_DIRS], [
15+
AC_MSG_CHECKING([installation directory variables])
16+
17+
_x_ac_expand_install_dirs_prefix="$prefix"
18+
test "$prefix" = NONE && prefix="$ac_default_prefix"
19+
_x_ac_expand_install_dirs_exec_prefix="$exec_prefix"
20+
test "$exec_prefix" = NONE && exec_prefix="$prefix"
21+
22+
adl_RECURSIVE_EVAL(["$prefix"], [X_PREFIX])
23+
AC_DEFINE_UNQUOTED([X_PREFIX], ["$X_PREFIX"],
24+
[Expansion of the "prefix" installation directory.])
25+
AC_SUBST([X_PREFIX])
26+
27+
adl_RECURSIVE_EVAL(["$exec_prefix"], [X_EXEC_PREFIX])
28+
AC_DEFINE_UNQUOTED([X_EXEC_PREFIX], ["$X_EXEC_PREFIX"],
29+
[Expansion of the "exec_prefix" installation directory.])
30+
AC_SUBST([X_EXEC_PREFIX])
31+
32+
adl_RECURSIVE_EVAL(["$bindir"], [X_BINDIR])
33+
AC_DEFINE_UNQUOTED([X_BINDIR], ["$X_BINDIR"],
34+
[Expansion of the "bindir" installation directory.])
35+
AC_SUBST([X_BINDIR])
36+
37+
adl_RECURSIVE_EVAL(["$sbindir"], [X_SBINDIR])
38+
AC_DEFINE_UNQUOTED([X_SBINDIR], ["$X_SBINDIR"],
39+
[Expansion of the "sbindir" installation directory.])
40+
AC_SUBST([X_SBINDIR])
41+
42+
adl_RECURSIVE_EVAL(["$libexecdir"], [X_LIBEXECDIR])
43+
AC_DEFINE_UNQUOTED([X_LIBEXECDIR], ["$X_LIBEXECDIR"],
44+
[Expansion of the "libexecdir" installation directory.])
45+
AC_SUBST([X_LIBEXECDIR])
46+
47+
adl_RECURSIVE_EVAL(["$datadir"], [X_DATADIR])
48+
AC_DEFINE_UNQUOTED([X_DATADIR], ["$X_DATADIR"],
49+
[Expansion of the "datadir" installation directory.])
50+
AC_SUBST([X_DATADIR])
51+
52+
adl_RECURSIVE_EVAL(["$sysconfdir"], [X_SYSCONFDIR])
53+
AC_DEFINE_UNQUOTED([X_SYSCONFDIR], ["$X_SYSCONFDIR"],
54+
[Expansion of the "sysconfdir" installation directory.])
55+
AC_SUBST([X_SYSCONFDIR])
56+
57+
adl_RECURSIVE_EVAL(["$sharedstatedir"], [X_SHAREDSTATEDIR])
58+
AC_DEFINE_UNQUOTED([X_SHAREDSTATEDIR], ["$X_SHAREDSTATEDIR"],
59+
[Expansion of the "sharedstatedir" installation directory.])
60+
AC_SUBST([X_SHAREDSTATEDIR])
61+
62+
adl_RECURSIVE_EVAL(["$localstatedir"], [X_LOCALSTATEDIR])
63+
AC_DEFINE_UNQUOTED([X_LOCALSTATEDIR], ["$X_LOCALSTATEDIR"],
64+
[Expansion of the "localstatedir" installation directory.])
65+
AC_SUBST([X_LOCALSTATEDIR])
66+
67+
adl_RECURSIVE_EVAL(["$runstatedir"], [X_RUNSTATEDIR])
68+
AC_DEFINE_UNQUOTED([X_RUNSTATEDIR], ["$X_RUNSTATEDIR"],
69+
[Expansion of the "runstatedir" installation directory.])
70+
AC_SUBST([X_RUNSTATEDIR])
71+
72+
adl_RECURSIVE_EVAL(["$libdir"], [X_LIBDIR])
73+
AC_DEFINE_UNQUOTED([X_LIBDIR], ["$X_LIBDIR"],
74+
[Expansion of the "libdir" installation directory.])
75+
AC_SUBST([X_LIBDIR])
76+
77+
adl_RECURSIVE_EVAL(["$includedir"], [X_INCLUDEDIR])
78+
AC_DEFINE_UNQUOTED([X_INCLUDEDIR], ["$X_INCLUDEDIR"],
79+
[Expansion of the "includedir" installation directory.])
80+
AC_SUBST([X_INCLUDEDIR])
81+
82+
adl_RECURSIVE_EVAL(["$oldincludedir"], [X_OLDINCLUDEDIR])
83+
AC_DEFINE_UNQUOTED([X_OLDINCLUDEDIR], ["$X_OLDINCLUDEDIR"],
84+
[Expansion of the "oldincludedir" installation directory.])
85+
AC_SUBST([X_OLDINCLUDEDIR])
86+
87+
adl_RECURSIVE_EVAL(["$infodir"], [X_INFODIR])
88+
AC_DEFINE_UNQUOTED([X_INFODIR], ["$X_INFODIR"],
89+
[Expansion of the "infodir" installation directory.])
90+
AC_SUBST([X_INFODIR])
91+
92+
adl_RECURSIVE_EVAL(["$mandir"], [X_MANDIR])
93+
AC_DEFINE_UNQUOTED([X_MANDIR], ["$X_MANDIR"],
94+
[Expansion of the "mandir" installation directory.])
95+
AC_SUBST([X_MANDIR])
96+
97+
prefix="$_x_ac_expand_install_dirs_prefix"
98+
exec_prefix="$_x_ac_expand_install_dirs_exec_prefix"
99+
100+
AC_MSG_RESULT([yes])
101+
])

configure.ac

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ AC_SUBST(fluxplugin_ldflags)
135135
fluxlib_ldflags="-shared -export-dynamic --disable-static -Wl,--no-undefined"
136136
AC_SUBST(fluxlib_ldflags)
137137

138+
139+
X_AC_EXPAND_INSTALL_DIRS
140+
141+
##
142+
# Check for systemd
143+
##
144+
RRA_WITH_SYSTEMD_UNITDIR
145+
138146
AC_CONFIG_FILES([Makefile
139147
src/Makefile
140148
src/job-manager/Makefile
@@ -145,6 +153,8 @@ AC_CONFIG_FILES([Makefile
145153
src/modules/Makefile
146154
src/python/Makefile
147155
src/python/flux_k8s/Makefile
156+
etc/Makefile
157+
etc/flux-coral2-dws.service
148158
t/Makefile])
149159
AC_OUTPUT
150160

etc/Makefile.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#if HAVE_SYSTEMD
2+
systemdsystemunit_DATA = flux-coral2-dws.service
3+
#endif

etc/flux-coral2-dws.service.in

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[Unit]
2+
Description=Flux-DWS communication service
3+
Requires=flux.service
4+
After=flux.service
5+
6+
[Service]
7+
TimeoutStopSec=90
8+
KillMode=mixed
9+
ExecStart=@X_BINDIR@/flux python @X_BINDIR@/coral2_dws.py
10+
SyslogIdentifier=flux-coral2-dws
11+
Restart=always
12+
RestartSec=10s
13+
14+
User=flux
15+
Group=flux
16+
17+
[Install]
18+
WantedBy=flux.service

src/modules/coral2_dws.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,6 @@ def main():
434434
help="Kill workflows in Error state for more than 'N' seconds",
435435
)
436436
args = parser.parse_args()
437-
try:
438-
jobid = id_parse(os.environ["FLUX_JOB_ID"])
439-
except KeyError as keyerr:
440-
raise RuntimeError("this script is meant to be run as a Flux job") from keyerr
441437
log_level = logging.WARNING
442438
if args.verbose > 1:
443439
log_level = logging.INFO
@@ -501,12 +497,16 @@ def main():
501497
watchers.add_watch(
502498
Watch(k8s_api, WORKFLOW_CRD, 0, workflow_state_change_cb, fh, k8s_api)
503499
)
504-
505-
# This job event is used to close the race condition between the python
506-
# process starting and the `dws` service being registered. Once
507-
# https://github.com/flux-framework/flux-core/issues/3821 is
508-
# implemented/closed, this can be replaced with that solution.
509-
Future(fh.job_raise(jobid, "exception", 7, "dws watchers setup")).get()
500+
try:
501+
jobid = id_parse(os.environ["FLUX_JOB_ID"])
502+
except KeyError as keyerr:
503+
pass
504+
else:
505+
# This job event is used to close the race condition between the python
506+
# process starting and the `dws` service being registered. Once
507+
# https://github.com/flux-framework/flux-core/issues/3821 is
508+
# implemented/closed, this can be replaced with that solution.
509+
Future(fh.job_raise(jobid, "exception", 7, "dws watchers setup")).get()
510510

511511
fh.reactor_run()
512512

0 commit comments

Comments
 (0)