@@ -0,0 +1,14 @@
|
|||||||
|
#!/usr/bin/env ssm
|
||||||
|
|
||||||
|
# Backup rotation — oneshot service with tmpfiles.
|
||||||
|
#
|
||||||
|
# service_tmpfiles creates paths before start:
|
||||||
|
# "path:file:perms:owner:group"
|
||||||
|
# "path:dir:perms:owner:group"
|
||||||
|
# "path:symlink:target"
|
||||||
|
# Directories default to 755, files to 644, owners default to root:root.
|
||||||
|
|
||||||
|
service_oneshot = yes
|
||||||
|
service_tmpfiles = /var/backup:dir:0755:backup:backup \
|
||||||
|
/var/backup/manifest:file:0640:root:backup
|
||||||
|
service_command = /usr/local/bin/backup-rotate --config /etc/backup.conf
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
#!/usr/bin/env ssm
|
||||||
|
|
||||||
|
# cron daemon.
|
||||||
|
#
|
||||||
|
# cron forks and daemonizes by default; -f keeps it in the foreground so
|
||||||
|
# ssm can track it directly.
|
||||||
|
|
||||||
|
service_respawn = always
|
||||||
|
service_command = /usr/sbin/cron -f
|
||||||
@@ -1,11 +1,26 @@
|
|||||||
#!/usr/bin/env ssm
|
#!/usr/bin/env ssm
|
||||||
|
|
||||||
service_oneshot = true
|
# nftables ruleset.
|
||||||
service_command = /usr/bin/false
|
#
|
||||||
|
# There is no nftables daemon: the ruleset is applied at startup and
|
||||||
|
# stays in the kernel until changed. We therefore treat this as a oneshot
|
||||||
|
# service whose real job is to apply the ruleset.
|
||||||
|
|
||||||
service::pre_start() {
|
service_oneshot = yes
|
||||||
cat <<- EOF
|
service_command = /usr/sbin/nft -f /etc/nftables.conf
|
||||||
Please don't. Use ferm or any other wrapper.
|
|
||||||
You will just reinvent one in here anyway.
|
var nftables_conf = /etc/nftables.conf
|
||||||
EOF
|
|
||||||
|
check_config() {
|
||||||
|
[[ ! -f "$nftables_conf" ]] && err "nftables config not found: $nftables_conf"
|
||||||
|
}
|
||||||
|
|
||||||
|
pre_start() {
|
||||||
|
check_config || return 17
|
||||||
|
}
|
||||||
|
|
||||||
|
reload() {
|
||||||
|
check_config || return 17
|
||||||
|
|
||||||
|
/usr/sbin/nft -f "$nftables_conf"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/env ssm
|
||||||
|
|
||||||
|
# logrotate — a oneshot service.
|
||||||
|
#
|
||||||
|
# This service runs once and exits. ssm marks it "enabled" after a
|
||||||
|
# successful run; use the reset-exit action (or `ssm logrotate reset-exit`)
|
||||||
|
# to let it run again. Schedule the service to run from whatever timer
|
||||||
|
# you prefer (systemd timer, cron, ...).
|
||||||
|
|
||||||
|
service_oneshot = yes
|
||||||
|
service_command = /usr/sbin/logrotate -f /etc/logrotate.conf
|
||||||
+19
-5
@@ -1,8 +1,22 @@
|
|||||||
#!/usr/bin/env ssm
|
#!/usr/bin/env ssm
|
||||||
|
|
||||||
service_respawn = on-failure
|
# nginx web server.
|
||||||
service_command = /usr/bin/nginx
|
#
|
||||||
service_pidfile = /run/nginx.pid
|
# nginx daemonizes itself (the parent returns after handing off to
|
||||||
|
# workers), so we don't wait for the process to exit — we wait for the
|
||||||
|
# port instead.
|
||||||
|
|
||||||
# Do not reload the service if the config test fails.
|
service_respawn = on-failure
|
||||||
pre_reload() { "$service_command" -t "$@"; }
|
service_command = /usr/sbin/nginx
|
||||||
|
service_pidfile = /run/nginx.pid
|
||||||
|
service_pidfile_timeout = 10
|
||||||
|
|
||||||
|
# ngs sometimes takes a moment to bind; poll until the socket answers.
|
||||||
|
ready() {
|
||||||
|
(exec 3<>/dev/tcp/127.0.0.1/80) 2>/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
# Do not send the reload signal if the config doesn't parse.
|
||||||
|
pre_reload() {
|
||||||
|
"$service_command" -t
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#!/usr/bin/env ssm
|
||||||
|
|
||||||
|
# PostgreSQL.
|
||||||
|
#
|
||||||
|
# postgres writes its own postmaster.pid file, so ssm doesn't create one
|
||||||
|
# — instead it waits for the pidfile to appear and treats any process
|
||||||
|
# exit as a failure. This is how services with their own pidfile should
|
||||||
|
# be written.
|
||||||
|
|
||||||
|
service_respawn = on-failure
|
||||||
|
service_command = /usr/lib/postgresql/17/bin/postgres -D /var/lib/postgresql/data
|
||||||
|
service_pidfile = /var/lib/postgresql/data/postmaster.pid
|
||||||
|
service_pidfile_timeout = 30
|
||||||
|
|
||||||
|
# Wait for the server to actually accept connections.
|
||||||
|
ready() {
|
||||||
|
(exec 3<>/dev/tcp/127.0.0.1/5432) 2>/dev/null
|
||||||
|
}
|
||||||
@@ -1,9 +1,13 @@
|
|||||||
#!/usr/bin/env ssm
|
#!/usr/bin/env ssm
|
||||||
|
|
||||||
service_type = oneshot
|
# /etc/rc.local — a oneshot service that runs whatever the system admin
|
||||||
service_command = /etc/rc.local
|
# drops there. Missing or non-executable files are not an error; the
|
||||||
|
# system may legitimately have no rc.local.
|
||||||
|
|
||||||
pre_start() {
|
service_oneshot = yes
|
||||||
# Do nothing, successfully, if /etc/rc.local is not executable.
|
|
||||||
[[ -x "/etc/rc.local" ]] || die 0
|
if [[ -x /etc/rc.local ]]; then
|
||||||
}
|
service_command = /etc/rc.local
|
||||||
|
else
|
||||||
|
service_command = /bin/true
|
||||||
|
fi
|
||||||
|
|||||||
+16
-3
@@ -1,10 +1,23 @@
|
|||||||
#!/usr/bin/env ssm
|
#!/usr/bin/env ssm
|
||||||
|
|
||||||
service_respawn = always
|
# OpenSSH server.
|
||||||
service_command = /usr/bin/sshd -D -f "/etc/ssh/sshd_config"
|
#
|
||||||
|
# sshd is run in foreground (-D) so ssm can track the process directly.
|
||||||
|
# Host keys are created if they're missing; sshd refuses to start
|
||||||
|
# without them, so do it before service_command is spawned.
|
||||||
|
|
||||||
|
service_respawn = on-failure
|
||||||
|
service_command = /usr/sbin/sshd -D -f /etc/ssh/sshd_config
|
||||||
|
service_ready_timeout = 10
|
||||||
|
|
||||||
pre_start() {
|
pre_start() {
|
||||||
if ! [[ -e "/etc/ssh/ssh_host_key" ]]; then
|
if [[ ! -f /etc/ssh/ssh_host_rsa_key ]]; then
|
||||||
ssh-keygen -A
|
ssh-keygen -A
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Wait for sshd to answer on port 22, not just for the parent process
|
||||||
|
# to return.
|
||||||
|
ready() {
|
||||||
|
(exec 3<>/dev/tcp/127.0.0.1/22) 2>/dev/null
|
||||||
|
}
|
||||||
|
|||||||
+13
-2
@@ -1,7 +1,18 @@
|
|||||||
#!/usr/bin/env ssm
|
#!/usr/bin/env ssm
|
||||||
|
|
||||||
# This trick was neat back in 2011, I swear
|
# One tinc network per service instance.
|
||||||
var tinc_network = "${service_name##*-}"
|
#
|
||||||
|
# The service name is expected to look like "tinc-<network>", e.g.
|
||||||
|
# "tinc-vpn" for the network configured in /etc/tinc/vpn.
|
||||||
|
|
||||||
|
var tinc_network = "${service_name#tinc-}"
|
||||||
|
|
||||||
service_respawn = on-failure
|
service_respawn = on-failure
|
||||||
service_command = /usr/bin/tincd -D -n "$tinc_network"
|
service_command = /usr/bin/tincd -D -n "$tinc_network"
|
||||||
|
|
||||||
|
pre_start() {
|
||||||
|
if [[ ! -d "/etc/tinc/$tinc_network" ]]; then
|
||||||
|
err "tinc network '$tinc_network' has no config directory"
|
||||||
|
return 17
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#!/usr/bin/env ssm
|
||||||
|
|
||||||
|
# Example application that depends on PostgreSQL.
|
||||||
|
#
|
||||||
|
# service_depends_ready makes ssm start the postgres service and wait
|
||||||
|
# for it to report ready before starting this one.
|
||||||
|
|
||||||
|
service_respawn = always
|
||||||
|
service_depends_ready = postgres
|
||||||
|
service_command = /usr/bin/webapp --config /etc/webapp/config.toml
|
||||||
|
|
||||||
|
# Wait for the app to answer on its HTTP port. ssm polls this hook until
|
||||||
|
# the ready timeout expires.
|
||||||
|
ready() {
|
||||||
|
(exec 3<>/dev/tcp/127.0.0.1/8080) 2>/dev/null
|
||||||
|
}
|
||||||
@@ -123,6 +123,8 @@ die() {
|
|||||||
exit "$code"
|
exit "$code"
|
||||||
}; readonly -f die
|
}; readonly -f die
|
||||||
|
|
||||||
|
err() { printf '%s\n' "$@" >&2; }
|
||||||
|
|
||||||
if_service_action() {
|
if_service_action() {
|
||||||
for f in "service::$1" "$1"; do
|
for f in "service::$1" "$1"; do
|
||||||
is_function "$f" && return 0
|
is_function "$f" && return 0
|
||||||
|
|||||||
Reference in New Issue
Block a user