Skip to content

Commit

Permalink
Merge branch 'master' into packaging-runners.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
cognifloyd authored Feb 21, 2025
2 parents ff2e4d5 + d2d41b0 commit 8c21b51
Show file tree
Hide file tree
Showing 28 changed files with 607 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ Added
* Add python 3.10 and 3.11 to the GitHub Actions test matrix.
Contributed by @nzlosh, @guzzijones12, and @cognifloyd

* Copy systemd files from st2-packages.git for future packaging via pants. #6303
Cherry-picked by @cognifloyd

* Cherry-pick changes to runners.sh from st2-packages git repo. #6302
Cherry-picked by @cognifloyd

Expand Down
56 changes: 56 additions & 0 deletions packaging/common/systemd/st2api-generator
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env python3
import configparser
import logging
import time
import sys

ST2SVC = "st2api"
DEFAULT_IP = "127.0.0.1"
DEFAULT_PORT = "9101"
ST2CFG = "/etc/st2/st2.conf"

# Systemd passes 3 paths to a generator, normal_dir, early_dir, late_dir.
default_paths = ["/tmp", "/tmp", "/tmp"]
for i, p in enumerate(sys.argv[1:]):
default_paths[i] = p
EARLY_DIR, NORMAL_DIR, LATE_DIR = default_paths

LOG_TO_DISK = True
LOG_KW = {
"level": logging.DEBUG,
"format": "%(asctime)s - %(levelname)s - %(message)s",
}
if LOG_TO_DISK:
LOG_KW["filename"] = f"{NORMAL_DIR}/{ST2SVC}_generator.log"

logging.basicConfig(**LOG_KW)
LOG = logging.getLogger()

LOG.debug(
f"Systemd directories: Early='{EARLY_DIR}' Normal='{NORMAL_DIR}' Late='{LATE_DIR}'"
)

config = configparser.ConfigParser(strict=False)
config.read(ST2CFG)

section = ST2SVC[3:]
bind_address = config[section].get("host", DEFAULT_IP)
bind_port = config[section].get("port", DEFAULT_PORT)

contents = f"""[Unit]
# Generated by {sys.argv[0]} at {time.asctime(time.localtime())}
Description=StackStorm {ST2SVC} Socket.
PartOf={ST2SVC}.service
SourcePath={ST2CFG}
[Socket]
ListenStream={bind_address}:{bind_port}
[Install]
WantedBy=sockets.target
"""

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

LOG.info(f"{ST2SVC} generated.")
56 changes: 56 additions & 0 deletions packaging/common/systemd/st2auth-generator
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env python3
import configparser
import logging
import time
import sys

ST2SVC="st2auth"
DEFAULT_IP="127.0.0.1"
DEFAULT_PORT="9100"
ST2CFG = "/etc/st2/st2.conf"

# Systemd passes 3 paths to a generator, normal_dir, early_dir, late_dir.
default_paths = ["/tmp", "/tmp", "/tmp"]
for i, p in enumerate(sys.argv[1:]):
default_paths[i] = p
EARLY_DIR, NORMAL_DIR, LATE_DIR = default_paths

LOG_TO_DISK = True
LOG_KW = {
"level": logging.DEBUG,
"format": "%(asctime)s - %(levelname)s - %(message)s",
}
if LOG_TO_DISK:
LOG_KW["filename"] = f"{NORMAL_DIR}/{ST2SVC}_generator.log"

logging.basicConfig(**LOG_KW)
LOG = logging.getLogger()

LOG.debug(
f"Systemd directories: Early='{EARLY_DIR}' Normal='{NORMAL_DIR}' Late='{LATE_DIR}'"
)

config = configparser.ConfigParser(strict=False)
config.read(ST2CFG)

section = ST2SVC[3:]
bind_address = config[section].get("host", DEFAULT_IP)
bind_port = config[section].get("port", DEFAULT_PORT)

contents = f"""[Unit]
# Generated by {sys.argv[0]} at {time.asctime(time.localtime())}
Description=StackStorm {ST2SVC} Socket.
PartOf={ST2SVC}.service
SourcePath={ST2CFG}
[Socket]
ListenStream={bind_address}:{bind_port}
[Install]
WantedBy=sockets.target
"""

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

LOG.info(f"{ST2SVC} generated.")
56 changes: 56 additions & 0 deletions packaging/common/systemd/st2stream-generator
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env python3
import configparser
import logging
import time
import sys

ST2SVC="st2stream"
DEFAULT_IP="127.0.0.1"
DEFAULT_PORT="9102"
ST2CFG = "/etc/st2/st2.conf"

# Systemd passes 3 paths to a generator, normal_dir, early_dir, late_dir.
default_paths = ["/tmp", "/tmp", "/tmp"]
for i, p in enumerate(sys.argv[1:]):
default_paths[i] = p
EARLY_DIR, NORMAL_DIR, LATE_DIR = default_paths

LOG_TO_DISK = True
LOG_KW = {
"level": logging.DEBUG,
"format": "%(asctime)s - %(levelname)s - %(message)s",
}
if LOG_TO_DISK:
LOG_KW["filename"] = f"{NORMAL_DIR}/{ST2SVC}_generator.log"

logging.basicConfig(**LOG_KW)
LOG = logging.getLogger()

LOG.debug(
f"Systemd directories: Early='{EARLY_DIR}' Normal='{NORMAL_DIR}' Late='{LATE_DIR}'"
)

config = configparser.ConfigParser(strict=False)
config.read(ST2CFG)

section = ST2SVC[3:]
bind_address = config[section].get("host", DEFAULT_IP)
bind_port = config[section].get("port", DEFAULT_PORT)

contents = f"""[Unit]
# Generated by {sys.argv[0]} at {time.asctime(time.localtime())}
Description=StackStorm {ST2SVC} Socket.
PartOf={ST2SVC}.service
SourcePath={ST2CFG}
[Socket]
ListenStream={bind_address}:{bind_port}
[Install]
WantedBy=sockets.target
"""

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

LOG.info(f"{ST2SVC} generated.")
14 changes: 14 additions & 0 deletions packaging/deb/systemd/st2actionrunner.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=StackStorm service st2actionrunner
After=network.target

[Service]
Type=oneshot
EnvironmentFile=-/etc/default/st2actionrunner
ExecStart=/bin/bash /opt/stackstorm/st2/bin/runners.sh start
ExecStop=/bin/bash /opt/stackstorm/st2/bin/runners.sh stop
PrivateTmp=true
RemainAfterExit=true

[Install]
WantedBy=multi-user.target
21 changes: 21 additions & 0 deletions packaging/deb/systemd/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[Unit]
Description=StackStorm service st2actionrunner
After=network.target
JoinsNamespaceOf=st2actionrunner.service

[Service]
Type=simple
User=root
Group=st2packs
UMask=002
Environment="DAEMON_ARGS=--config-file /etc/st2/st2.conf"
Environment="WORKERID=%i"
EnvironmentFile=-/etc/default/st2actionrunner
ExecStart=/opt/stackstorm/st2/bin/st2actionrunner $DAEMON_ARGS
TimeoutSec=60
PrivateTmp=true
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
19 changes: 19 additions & 0 deletions packaging/deb/systemd/st2api.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[Unit]
Description=StackStorm service st2api
After=network.target st2api.socket
Requires=st2api.socket

[Service]
Type=simple
User=st2
Group=st2
Environment="DAEMON_ARGS=-k eventlet -b 127.0.0.1:9101 --workers 1 --threads 1 --graceful-timeout 10 --timeout 30 --log-config /etc/st2/logging.api.gunicorn.conf --error-logfile /var/log/st2/st2api.log"
EnvironmentFile=-/etc/default/st2api
ExecStart=/opt/stackstorm/st2/bin/gunicorn st2api.wsgi:application $DAEMON_ARGS
TimeoutSec=60
PrivateTmp=true
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
19 changes: 19 additions & 0 deletions packaging/deb/systemd/st2auth.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[Unit]
Description=StackStorm service st2auth
After=network.target st2auth.socket
Requires=st2auth.socket

[Service]
Type=simple
User=st2
Group=st2
Environment="DAEMON_ARGS=-k eventlet -b 127.0.0.1:9100 --workers 1 --threads 1 --graceful-timeout 10 --timeout 30 --log-config /etc/st2/logging.auth.gunicorn.conf --error-logfile /var/log/st2/st2auth.log"
EnvironmentFile=-/etc/default/st2auth
ExecStart=/opt/stackstorm/st2/bin/gunicorn st2auth.wsgi:application $DAEMON_ARGS
TimeoutSec=60
PrivateTmp=true
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
18 changes: 18 additions & 0 deletions packaging/deb/systemd/st2garbagecollector.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[Unit]
Description=StackStorm service st2garbagecollector
After=network.target

[Service]
Type=simple
User=st2
Group=st2
Environment="DAEMON_ARGS=--config-file /etc/st2/st2.conf"
EnvironmentFile=-/etc/default/st2garbagecollector
ExecStart=/opt/stackstorm/st2/bin/st2garbagecollector $DAEMON_ARGS
TimeoutSec=60
PrivateTmp=true
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
18 changes: 18 additions & 0 deletions packaging/deb/systemd/st2notifier.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[Unit]
Description=StackStorm service st2notifier
After=network.target

[Service]
Type=simple
User=st2
Group=st2
Environment="DAEMON_ARGS=--config-file /etc/st2/st2.conf"
EnvironmentFile=-/etc/default/st2notifier
ExecStart=/opt/stackstorm/st2/bin/st2notifier $DAEMON_ARGS
TimeoutSec=60
PrivateTmp=true
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
18 changes: 18 additions & 0 deletions packaging/deb/systemd/st2rulesengine.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[Unit]
Description=StackStorm service st2rulesengine
After=network.target

[Service]
Type=simple
User=st2
Group=st2
Environment="DAEMON_ARGS=--config-file /etc/st2/st2.conf"
EnvironmentFile=-/etc/default/st2rulesengine
ExecStart=/opt/stackstorm/st2/bin/st2rulesengine $DAEMON_ARGS
TimeoutSec=60
PrivateTmp=true
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
18 changes: 18 additions & 0 deletions packaging/deb/systemd/st2scheduler.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[Unit]
Description=StackStorm service st2scheduler
After=network.target

[Service]
Type=simple
User=st2
Group=st2
Environment="DAEMON_ARGS=--config-file /etc/st2/st2.conf"
EnvironmentFile=-/etc/default/st2scheduler
ExecStart=/opt/stackstorm/st2/bin/st2scheduler $DAEMON_ARGS
TimeoutSec=60
PrivateTmp=true
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
18 changes: 18 additions & 0 deletions packaging/deb/systemd/st2sensorcontainer.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[Unit]
Description=StackStorm service st2sensorcontainer
After=network.target

[Service]
Type=simple
User=st2
Group=st2
Environment="DAEMON_ARGS=--config-file /etc/st2/st2.conf"
EnvironmentFile=-/etc/default/st2sensorcontainer
ExecStart=/opt/stackstorm/st2/bin/st2sensorcontainer $DAEMON_ARGS
TimeoutSec=60
PrivateTmp=true
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
19 changes: 19 additions & 0 deletions packaging/deb/systemd/st2stream.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[Unit]
Description=StackStorm service st2stream
After=network.target st2stream.socket
Requires=st2stream.socket

[Service]
Type=simple
User=st2
Group=st2
Environment="DAEMON_ARGS=-k eventlet -b 127.0.0.1:9102 --workers 1 --threads 10 --graceful-timeout 10 --timeout 30 --log-config /etc/st2/logging.stream.gunicorn.conf --error-logfile /var/log/st2/st2stream.log"
EnvironmentFile=-/etc/default/st2stream
ExecStart=/opt/stackstorm/st2/bin/gunicorn st2stream.wsgi:application $DAEMON_ARGS
TimeoutSec=60
PrivateTmp=true
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
18 changes: 18 additions & 0 deletions packaging/deb/systemd/st2timersengine.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[Unit]
Description=StackStorm service st2timersengine
After=network.target

[Service]
Type=simple
User=st2
Group=st2
Environment="DAEMON_ARGS=--config-file /etc/st2/st2.conf"
EnvironmentFile=-/etc/default/st2timersengine
ExecStart=/opt/stackstorm/st2/bin/st2timersengine $DAEMON_ARGS
TimeoutSec=60
PrivateTmp=true
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
Loading

0 comments on commit 8c21b51

Please sign in to comment.