Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate unit file for st2api, st2auth and st2stream #721

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
6 changes: 5 additions & 1 deletion packages/st2/debian/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ case "$1" in
[ "$upgrading" = 1 ] || set_permissions "$SET_PERMS"
rm -f $ST2_UPGRADESTAMP

# make sure that our socket generators run
# Reload systemd to run generators for unit and socket files.
systemctl daemon-reload >/dev/null 2>&1 || true

# Enable services created by systemd generator
systemctl enable st2api st2auth st2stream >/dev/null 2>&1 || true
systemctl start st2api st2auth st2stream >/dev/null 2>&1 || true
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
Expand Down
3 changes: 0 additions & 3 deletions packages/st2/debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ override_dh_gencontrol:
override_dh_installinit:
dh_systemd_enable --name=st2actionrunner st2actionrunner.service
install -p -m644 debian/st2actionrunner@.service debian/st2/lib/systemd/system/st2actionrunner@.service
dh_systemd_enable --name=st2api st2api.service
dh_systemd_enable --name=st2stream st2stream.service
dh_systemd_enable --name=st2auth st2auth.service
dh_systemd_enable --name=st2notifier st2notifier.service
dh_systemd_enable --name=st2rulesengine st2rulesengine.service
dh_systemd_enable --name=st2sensorcontainer st2sensorcontainer.service
Expand Down
31 changes: 28 additions & 3 deletions packages/st2/debian/st2api-generator
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ section = ST2SVC[3:]
bind_address = config[section].get("host", DEFAULT_IP)
bind_port = config[section].get("port", DEFAULT_PORT)

contents = f"""[Unit]
socket_contents = f"""[Unit]
# Generated by {sys.argv[0]} at {time.asctime(time.localtime())}
Description=StackStorm {ST2SVC} Socket.
PartOf={ST2SVC}.service
Expand All @@ -51,6 +51,31 @@ WantedBy=sockets.target
"""

with open(f"{NORMAL_DIR}/{ST2SVC}.socket", "w") as f:
f.write(contents)
f.write(socket_contents)

LOG.info(f"{ST2SVC} generated.")
LOG.info(f"{ST2SVC} socket generated.")

unit_contents = f"""[Unit]
# Generated by {sys.argv[0]} at {time.asctime(time.localtime())}
Description=StackStorm service {ST2SVC}
After=network.target {ST2SVC}.socket
Requires={ST2SVC}.socket

[Service]
Type=simple
User=st2
Group=st2
ExecStart=/opt/stackstorm/st2/bin/gunicorn {ST2SVC}.wsgi:application -k eventlet -b {bind_address}:{bind_port} --workers 1 --threads 1 --graceful-timeout 10 --timeout 30 --log-config /etc/st2/logging.api.gunicorn.conf --error-logfile /var/log/st2/{ST2SVC}.log
TimeoutSec=60
PrivateTmp=true
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
"""

with open(f"{NORMAL_DIR}/{ST2SVC}.service", "w") as f:
f.write(unit_contents)

LOG.info(f"{ST2SVC} unit generated")
19 changes: 0 additions & 19 deletions packages/st2/debian/st2api.service

This file was deleted.

37 changes: 31 additions & 6 deletions packages/st2/debian/st2auth-generator
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import logging
import time
import sys

ST2SVC="st2auth"
DEFAULT_IP="127.0.0.1"
DEFAULT_PORT="9100"
ST2SVC = "st2auth"
DEFAULT_IP = "127.0.0.1"
DEFAULT_PORT = "9101"
cognifloyd marked this conversation as resolved.
Show resolved Hide resolved
ST2CFG = "/etc/st2/st2.conf"

# Systemd passes 3 paths to a generator, normal_dir, early_dir, late_dir.
Expand Down Expand Up @@ -37,7 +37,7 @@ section = ST2SVC[3:]
bind_address = config[section].get("host", DEFAULT_IP)
bind_port = config[section].get("port", DEFAULT_PORT)

contents = f"""[Unit]
socket_contents = f"""[Unit]
# Generated by {sys.argv[0]} at {time.asctime(time.localtime())}
Description=StackStorm {ST2SVC} Socket.
PartOf={ST2SVC}.service
Expand All @@ -51,6 +51,31 @@ WantedBy=sockets.target
"""

with open(f"{NORMAL_DIR}/{ST2SVC}.socket", "w") as f:
f.write(contents)
f.write(socket_contents)

LOG.info(f"{ST2SVC} generated.")
LOG.info(f"{ST2SVC} socket generated.")

unit_contents = f"""[Unit]
# Generated by {sys.argv[0]} at {time.asctime(time.localtime())}
Description=StackStorm service {ST2SVC}
After=network.target {ST2SVC}.socket
Requires={ST2SVC}.socket

[Service]
Type=simple
User=st2
Group=st2
ExecStart=/opt/stackstorm/st2/bin/gunicorn {ST2SVC}.wsgi:application -k eventlet -b {bind_address}:{bind_port} --workers 1 --threads 1 --graceful-timeout 10 --timeout 30 --log-config /etc/st2/logging.api.gunicorn.conf --error-logfile /var/log/st2/{ST2SVC}.log
TimeoutSec=60
PrivateTmp=true
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
"""

with open(f"{NORMAL_DIR}/{ST2SVC}.service", "w") as f:
f.write(unit_contents)

LOG.info(f"{ST2SVC} unit generated")
19 changes: 0 additions & 19 deletions packages/st2/debian/st2auth.service

This file was deleted.

37 changes: 31 additions & 6 deletions packages/st2/debian/st2stream-generator
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import logging
import time
import sys

ST2SVC="st2stream"
DEFAULT_IP="127.0.0.1"
DEFAULT_PORT="9102"
ST2SVC = "st2stream"
DEFAULT_IP = "127.0.0.1"
DEFAULT_PORT = "9101"
cognifloyd marked this conversation as resolved.
Show resolved Hide resolved
ST2CFG = "/etc/st2/st2.conf"

# Systemd passes 3 paths to a generator, normal_dir, early_dir, late_dir.
Expand Down Expand Up @@ -37,7 +37,7 @@ section = ST2SVC[3:]
bind_address = config[section].get("host", DEFAULT_IP)
bind_port = config[section].get("port", DEFAULT_PORT)

contents = f"""[Unit]
socket_contents = f"""[Unit]
# Generated by {sys.argv[0]} at {time.asctime(time.localtime())}
Description=StackStorm {ST2SVC} Socket.
PartOf={ST2SVC}.service
Expand All @@ -51,6 +51,31 @@ WantedBy=sockets.target
"""

with open(f"{NORMAL_DIR}/{ST2SVC}.socket", "w") as f:
f.write(contents)
f.write(socket_contents)

LOG.info(f"{ST2SVC} generated.")
LOG.info(f"{ST2SVC} socket generated.")

unit_contents = f"""[Unit]
# Generated by {sys.argv[0]} at {time.asctime(time.localtime())}
Description=StackStorm service {ST2SVC}
After=network.target {ST2SVC}.socket
Requires={ST2SVC}.socket

[Service]
Type=simple
User=st2
Group=st2
ExecStart=/opt/stackstorm/st2/bin/gunicorn {ST2SVC}.wsgi:application -k eventlet -b {bind_address}:{bind_port} --workers 1 --threads 1 --graceful-timeout 10 --timeout 30 --log-config /etc/st2/logging.api.gunicorn.conf --error-logfile /var/log/st2/{ST2SVC}.log
TimeoutSec=60
PrivateTmp=true
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
"""

with open(f"{NORMAL_DIR}/{ST2SVC}.service", "w") as f:
f.write(unit_contents)

LOG.info(f"{ST2SVC} unit generated")
19 changes: 0 additions & 19 deletions packages/st2/debian/st2stream.service

This file was deleted.

6 changes: 5 additions & 1 deletion packages/st2/rpm/postinst_script.spec
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
set -e

# make sure that our socket generators run
# Reload systemd to run generators for unit and socket files.
systemctl daemon-reload >/dev/null 2>&1 || true

# Enable services created by systemd generator
systemctl enable st2api st2auth st2stream >/dev/null 2>&1 || true
systemctl start st2api st2auth st2stream >/dev/null 2>&1 || true
Copy link
Member

@cognifloyd cognifloyd Oct 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the test error for EL distros:

I think this is already handled by the %post macro which uses the %service_post helper. That runs:

systemctl --no-reload enable %{?*} >/dev/null 2>&1 || : \

What if you remove the output redirection in the %service_post macro helper? Then maybe we'll see if there's an error. And maybe remove it here too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There appears to be a worker timeout for gunicorn on EL7, but I don't think that's the cause of the services failing to start for the RPM based distros. I still don't see any errors in the logs that indicate why the service is not enabled and started.

3 changes: 0 additions & 3 deletions packages/st2/rpm/st2.spec
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@ Conflicts: st2common
%attr(775, root, %{packs_group}) /opt/stackstorm/virtualenvs
%{_unitdir}/st2actionrunner.service
%{_unitdir}/%{worker_name}.service
%{_unitdir}/st2api.service
%{_unitdir}/st2stream.service
%{_unitdir}/st2auth.service
%{_unitdir}/st2notifier.service
%{_unitdir}/st2rulesengine.service
%{_unitdir}/st2sensorcontainer.service
Expand Down