Adding contrib dir

Moving:
- deployment/helm -> contrib/helm
- tools -> contrib/tools
Adding:
- contrib/init/{stacks.init,stacks.service,org.stacks.stacks-blockchain.plist}
- docs/init.md
This commit is contained in:
wileyj
2022-03-11 20:48:40 -08:00
parent f6c78b0263
commit b14f366797
21 changed files with 312 additions and 0 deletions

11
contrib/init/README.md Normal file
View File

@@ -0,0 +1,11 @@
Sample configuration files for:
```
systemd: stacks.service
SysVinit: stacks.init
MacOS: org.stacks.stacks-blockchain.plist
```
have been made available to assist packagers in creating node packages here.
See [docs/init.md](../../docs/init.md) for more information.

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.stacks.stacks-blockchain</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/stacks-node</string>
<string>start</string>
<string>--config=/etc/stacks-blockchain/Config.toml</string>
</array>
<key>Nice</key>
<integer>1</integer>
<key>StartInterval</key>
<integer>60</integer>
<key>ProcessType</key>
<integer>Standard</integer>
<key>StandardErrorPath</key>
<string>/tmp/stacks-blockchain.log</string>
<key>StandardOutPath</key>
<string>/tmp/stacks-blockchain.log</string>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>

114
contrib/init/stacks.init Normal file
View File

@@ -0,0 +1,114 @@
#!/usr/bin/env bash
# # Modelled after https://github.com/bitcoin/bitcoin/blob/master/contrib/init/bitcoind.init
#
# Stacks Blockchain
#
#
# chkconfig: 345 80 20
# description: stacks-blockchain
# processname: stacks-node
#
### BEGIN INIT INFO
# Provides: stacks-blockchain
# Required-Start:
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Stacks Blockchain
# Description: Stacks Blockchain
### END INIT INFO
# Source function library.
. /etc/init.d/functions
# you can override defaults in /etc/sysconfig/stacks-blockchain, see below
if [ -f /etc/sysconfig/stacks-blockchain ]; then
. /etc/sysconfig/stacks-blockchain
fi
RETVAL=0
prog=stacks-node
# you can override the lockfile via STACKS_BLOCKCHAIN_LOCKFILE in /etc/sysconfig/stacks-blockchain
lockfile=${STACKS_BLOCKCHAIN_LOCKFILE-/var/lock/subsys/stacks-blockchain}
# stacks-blockchain defaults to /usr/local/bin/stacks-node, override with STACKS_BLOCKCHAIN_BIN
stacks_bin=${STACKS_BLOCKCHAIN_BIN-/usr/local/bin/stacks-node}
# stacks-blockchain path to config toml, override with STACKS_BLOCKCHAIN_CONFIG
stacks_config=${STACKS_BLOCKCHAIN_CONFIG-/etc/stacks-blockchain/Config.toml}
# stacks-blockchain log file default to /var/log/stacks-blockchain.log, override with STACKS_BLOCKCHAIN_LOG
stacks_log=${STACKS_BLOCKCHAIN_LOG-/stacks-blockchain/output.log}
# Note: no logrotate is provided, you're encouraged to set something up like the following logrotate file:
# cat <<EOF> /etc/logrotate.d/stacks-blockchain
# /stacks-blockchain/output.log
# {
# missingok
# daily
# copytruncate
# rotate 7
# }
# EOF
start() {
if [ ! -f $stacks_config ];then
echo -n "Missing config file: $stacks_config "
return 1
fi
[ -x $exec ] || exit 5
echo -n $"Starting $prog: "
$stacks_bin start --config=$stacks_config > $stacks_log 2>&1 &
RETVAL=$?
[ $RETVAL -eq 0 ] && touch $lockfile
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -INT
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $lockfile
return $RETVAL
}
restart() {
stop
start
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 1
$1
;;
stop)
rh_status_q || exit 1
$1
;;
status)
rh_status
;;
restart)
$1
;;
*)
echo "Usage: service $prog {start|stop|status|restart}"
exit 2
;;
esac
exit $?

View File

@@ -0,0 +1,62 @@
# # Modeled after https://github.com/bitcoin/bitcoin/blob/master/contrib/init/bitcoind.service
[Unit]
Description=Stacks Blockchain
# https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/
After=network-online.target
Wants=network-online.target
ConditionFileIsExecutable=/usr/local/bin/stacks-node
ConditionPathExists=/etc/stacks-blockchain/Config.toml
ConditionPathIsDirectory=/stacks-blockchain
[Service]
#ExecStart=/bin/sh -c "/usr/local/bin/stacks-node start --config=/etc/stacks-blockchain/Config.toml >> /stacks-blockchain/output.log 2>&1"
ExecStart=/bin/sh -c "/usr/local/bin/stacks-node start --config=/etc/stacks-blockchain/Config.toml"
ExecStartPost=/bin/sh -c "umask 022; sleep 2 && pgrep -f \"/usr/local/bin/stacks-node start --config=/etc/stacks-blockchain/Config.toml\" > /run/stacks-blockchain/stacks-blockchain.pid"
ExecStopPost=/bin/sh -c "if [ -f \"/run/stacks-blockchain/stacks-blockchain.pid\" ]; then rm -f /run/stacks-blockchain/stacks-blockchain.pid; fi"
# Make sure the config directory is readable by the service user
PermissionsStartOnly=true
#ExecStartPre=/bin/chgrp stacks /etc/stacks-blockchain/
# Process management
####################
Type=simple
PIDFile=/run/stacks-blockchain/stacks-blockchain.pid
Restart=on-failure
TimeoutStopSec=600
KillSignal=SIGTERM
# Directory creation and permissions
####################################
# Run as stacks:stacks
User=stacks
Group=stacks
# /run/stacks-blockchain
RuntimeDirectory=stacks-blockchain
RuntimeDirectoryMode=0710
# Hardening measures
####################
# Provide a private /tmp and /var/tmp.
PrivateTmp=true
# Mount /usr, /boot/ and /etc read-only for the process.
ProtectSystem=full
# Deny access to /home, /root and /run/user
ProtectHome=true
# Disallow the process and all of its children to gain
# new privileges through execve().
NoNewPrivileges=true
# Use a new /dev namespace only populated with API pseudo devices
# such as /dev/null, /dev/zero and /dev/random.
PrivateDevices=true
[Install]
WantedBy=multi-user.target

93
docs/init.md Normal file
View File

@@ -0,0 +1,93 @@
# Sample init scripts and service configuration for stacks-blockchain
Sample scripts and configuration files for systemd and SysVinit
can be found in the [contrib/init](../contrib/init) folder.
contrib/init/stacks.service: systemd service unit configuration
contrib/init/stacks.init: SysV style init script
## Service User
All Linux startup configurations assume the existence of a "stacks" user
and group. They must be created before attempting to use these scripts.
The MacOS configuration assumes stacks-blockchain will be set up for the current user.
## Configuration
For an example configuration file that describes the configuration settings,
see [mainnet-follower-conf.toml](../testnet/stacks-node/conf/mainnet-follower-conf.toml).
Available configuration options are documented here: https://docs.stacks.co/references/stacks-node-configuration
## Paths
### Linux
All three configurations assume several paths that might need to be adjusted.
Binary: /usr/local/bin/stacks-node
Configuration file: /etc/stacks-blockchain/Config.toml
Data directory: /stacks-blockchain
PID file: /run/stacks-blockchain/stacks.pid
Lock file: /var/lock/subsys/stacks (SysVinit)
The PID directory and data directory should both be owned by the
stacks user and group. It is advised for security reasons to make the
configuration file and data directory only readable by the stacks user and
group.
NOTE: When using the systemd .service file, the creation of the aforementioned
directories and the setting of their permissions is automatically handled by
systemd. Directories are given a permission of 710, giving the stacks group
access to files under it _if_ the files themselves give permission to the
stacks group to do so. This does not allow for the listing of files under the directory.
```bash
$ mkdir -p /etc/stacks-blockchain/
$ mkdir -p /stacks-blockchain
$ useradd stacks
$ chown -R stacks:stacks /stacks-blockchain/
$ chgrp -R stacks /etc/stacks-blockchain
```
### macOS
Binary: /usr/local/bin/stacks-node
Configuration file: /etc/stacks-blockchain/Config.toml
The Config.toml file is presumed to have group ownership by the `wheel` group, with the current user having membership to that group. The data directory defined in the config is required to be writable by the current user. Logs (stdout & stderr) are saved under `/tmp/stacks-blockchain.log`
## Installing Service Configuration
### systemd
Installing this .service file consists of just copying it to
/usr/lib/systemd/system directory, followed by the command
`systemctl daemon-reload` in order to update running systemd configuration.
To test, run `systemctl start stacks` and to enable for system startup run
`systemctl enable stacks`
NOTE: When installing for systemd in Debian/Ubuntu the .service file needs to be copied to the /lib/systemd/system directory instead.
### SysVinit
Copy stacks.init to /etc/init.d/stacks. Test by running `service stacks start`.
Using this script, you can adjust the config path and log location to the stacks-node program by
setting the STACKS_BLOCKCHAIN_CONFIG and STACKS_BLOCKCHAIN_LOG environment variables in the file
/etc/sysconfig/stacks-blockchain.
### MacOS
Copy org.stacks.stacks-blockchain.plist into ~/Library/LaunchAgents. Load the launch agent by
running `launchctl load ~/Library/LaunchAgents/org.stacks.stacks-blockchain.plist`.
This Launch Agent will cause the stacks-blockchain to start whenever the user logs in.
NOTE: This approach is intended for those wanting to run stacks-blockchain as the current user.
You will need to modify org.stacks.stacks-blockchain.plist if you intend to use it as a
Launch Daemon with a dedicated stacks user.
## Auto-respawn
Auto respawning is currently only configured for systemd.