add systemd and launchd scripts
This commit is contained in:
parent
9cf9604c00
commit
41d36a4eb9
|
@ -0,0 +1,55 @@
|
||||||
|
<?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>Goldilocks</string>
|
||||||
|
<key>ProgramArguments</key>
|
||||||
|
<array>
|
||||||
|
<string>/usr/local/bin/goldilocks</string>
|
||||||
|
<string>-agree</string>
|
||||||
|
<string>-conf</string>
|
||||||
|
<string>/etc/goldilocks/goldilocks.yml</string>
|
||||||
|
<string>-root</string>
|
||||||
|
<string>/var/tmp</string>
|
||||||
|
</array>
|
||||||
|
<key>EnvironmentVariables</key>
|
||||||
|
<dict>
|
||||||
|
<key>GOLDILOCKS_PATH</key>
|
||||||
|
<string>/opt/goldilocks</string>
|
||||||
|
</dict>
|
||||||
|
|
||||||
|
<key>UserName</key>
|
||||||
|
<string>root</string>
|
||||||
|
<key>GroupName</key>
|
||||||
|
<string>wheel</string>
|
||||||
|
<key>InitGroups</key>
|
||||||
|
<true/>
|
||||||
|
|
||||||
|
<key>RunAtLoad</key>
|
||||||
|
<true/>
|
||||||
|
<key>KeepAlive</key>
|
||||||
|
<dict>
|
||||||
|
<key>Crashed</key>
|
||||||
|
<true/>
|
||||||
|
<key>SuccessfulExit</key>
|
||||||
|
<false/>
|
||||||
|
</dict>
|
||||||
|
|
||||||
|
<key>SoftResourceLimits</key>
|
||||||
|
<dict>
|
||||||
|
<key>NumberOfFiles</key>
|
||||||
|
<integer>8192</integer>
|
||||||
|
</dict>
|
||||||
|
<key>HardResourceLimits</key>
|
||||||
|
<dict/>
|
||||||
|
|
||||||
|
<key>WorkingDirectory</key>
|
||||||
|
<string>/srv/www</string>
|
||||||
|
|
||||||
|
<key>StandardErrorPath</key>
|
||||||
|
<string>/var/log/goldilocks/error.log</string>
|
||||||
|
<key>StandardOutPath</key>
|
||||||
|
<string>/var/log/goldilocks/info.log</string>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
13
README.md
13
README.md
|
@ -34,10 +34,10 @@ Install
|
||||||
npm install -g goldilocks
|
npm install -g goldilocks
|
||||||
|
|
||||||
# master in git (via ssh)
|
# master in git (via ssh)
|
||||||
npm install -g git+ssh://git@git.daplie.com:Daplie/goldilocks.js
|
npm install -g git+ssh://git@git.daplie.com:Daplie/goldilocks.js#v1
|
||||||
|
|
||||||
# master in git (unauthenticated)
|
# master in git (unauthenticated)
|
||||||
npm install -g git+https://git@git.daplie.com:Daplie/goldilocks.js
|
npm install -g git+https://git@git.daplie.com:Daplie/goldilocks.js#v1
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
@ -48,6 +48,15 @@ goldilocks
|
||||||
Serving /Users/foo/ at https://localhost.daplie.me:8443
|
Serving /Users/foo/ at https://localhost.daplie.me:8443
|
||||||
```
|
```
|
||||||
|
|
||||||
|
With service support for
|
||||||
|
|
||||||
|
* systemd
|
||||||
|
* launchd
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl https://git.daplie.com/Daplie/goldilocks.js/raw/master/install.sh | bash
|
||||||
|
```
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Goldilocks Internet Server
|
||||||
|
Documentation=https://git.daplie.com/Daplie/goldilocks.js
|
||||||
|
After=network-online.target
|
||||||
|
Wants=network-online.target systemd-networkd-wait-online.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
# Restart on crash (bad signal), and on 'clean' failure (error exit code)
|
||||||
|
# Allow up to 3 restarts within 10 seconds
|
||||||
|
# (it's unlikely that a user or properly-running script will do this)
|
||||||
|
Restart=on-failure
|
||||||
|
StartLimitInterval=10
|
||||||
|
StartLimitBurst=3
|
||||||
|
|
||||||
|
# The v8 VM will output a "clean" for JavaScript errors.
|
||||||
|
# If we knew we were never going to accidentally exit cleanly
|
||||||
|
# we would use on-abnormal:
|
||||||
|
; Restart=on-abnormal
|
||||||
|
|
||||||
|
# User and group the process will run as
|
||||||
|
# (www-data is the de facto standard on most systems)
|
||||||
|
User=www-data
|
||||||
|
Group=www-data
|
||||||
|
|
||||||
|
# If we need to pass environment variables in the future
|
||||||
|
; Environment=GOLDILOCKS_PATH=/opt/goldilocks
|
||||||
|
|
||||||
|
# Set a sane working directory, sane flags, and specify how to reload the config file
|
||||||
|
WorkingDirectory=/srv/www
|
||||||
|
ExecStart=/usr/local/bin/goldilocks --log stdout --config=/etc/goldilocks/goldilocks.yml
|
||||||
|
ExecReload=/bin/kill -USR1 $MAINPID
|
||||||
|
|
||||||
|
# Limit the number of file descriptors and processes; see `man systemd.exec` for more limit settings.
|
||||||
|
# Unmodified goldilocks is not expected to use more than this.
|
||||||
|
LimitNOFILE=1048576
|
||||||
|
LimitNPROC=64
|
||||||
|
|
||||||
|
# Use private /tmp and /var/tmp, which are discarded after goldilocks stops.
|
||||||
|
PrivateTmp=true
|
||||||
|
# Use a minimal /dev
|
||||||
|
PrivateDevices=true
|
||||||
|
# Hide /home, /root, and /run/user. Nobody will steal your SSH-keys.
|
||||||
|
ProtectHome=true
|
||||||
|
# Make /usr, /boot, /etc and possibly some more folders read-only.
|
||||||
|
ProtectSystem=full
|
||||||
|
# … except TLS/SSL, ACME, and Let's Encrypt certificates
|
||||||
|
# and /var/log/goldilocks, because we want a place where logs can go.
|
||||||
|
# This merely retains r/w access rights, it does not add any new. Must still be writable on the host!
|
||||||
|
ReadWriteDirectories=/etc/goldilocks /etc/acme /etc/letsencrypt /etc/ssl /var/log/goldilocks /opt/goldilocks /srv/www
|
||||||
|
|
||||||
|
# Note: in v231 and above ReadWritePaths has been renamed to ReadWriteDirectories
|
||||||
|
; ReadWritePaths=/etc/goldilocks /var/log/goldilocks
|
||||||
|
;
|
||||||
|
# The following additional security directives only work with systemd v229 or later.
|
||||||
|
# They further retrict privileges that can be gained.
|
||||||
|
# Note that you may have to add capabilities required by any plugins in use.
|
||||||
|
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
|
||||||
|
AmbientCapabilities=CAP_NET_BIND_SERVICE
|
||||||
|
NoNewPrivileges=true
|
||||||
|
|
||||||
|
# Caveat: Some plugins need additional capabilities.
|
||||||
|
# For example "upload" needs CAP_LEASE
|
||||||
|
; CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_LEASE
|
||||||
|
; AmbientCapabilities=CAP_NET_BIND_SERVICE CAP_LEASE
|
||||||
|
; NoNewPrivileges=true
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
|
@ -0,0 +1,10 @@
|
||||||
|
# /etc/tmpfiles.d/goldilocks.conf
|
||||||
|
# See https://www.freedesktop.org/software/systemd/man/tmpfiles.d.html
|
||||||
|
|
||||||
|
# Type Path Mode UID GID Age Argument
|
||||||
|
d /etc/goldilocks 0755 www-data www-data - -
|
||||||
|
d /opt/goldilocks 0775 www-data www-data - -
|
||||||
|
d /srv/www 0775 www-data www-data - -
|
||||||
|
d /etc/ssl/goldilocks 0750 www-data www-data - -
|
||||||
|
d /var/log/goldilocks 0750 www-data www-data - -
|
||||||
|
#d /run/goldilocks 0755 www-data www-data - -
|
129
install.sh
129
install.sh
|
@ -1,4 +1,129 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
echo "no installer yet"
|
###############################
|
||||||
exit 1
|
# #
|
||||||
|
# http_get #
|
||||||
|
# boilerplate for curl / wget #
|
||||||
|
# #
|
||||||
|
###############################
|
||||||
|
|
||||||
|
# See https://git.daplie.com/Daplie/daplie-snippets/blob/master/bash/http-get.sh
|
||||||
|
|
||||||
|
http_get=""
|
||||||
|
http_opts=""
|
||||||
|
http_out=""
|
||||||
|
|
||||||
|
detect_http_get()
|
||||||
|
{
|
||||||
|
if type -p curl >/dev/null 2>&1; then
|
||||||
|
http_get="curl"
|
||||||
|
http_opts="-fsSL"
|
||||||
|
http_out="-o"
|
||||||
|
elif type -p wget >/dev/null 2>&1; then
|
||||||
|
http_get="wget"
|
||||||
|
http_opts="--quiet"
|
||||||
|
http_out="-O"
|
||||||
|
else
|
||||||
|
echo "Aborted, could not find curl or wget"
|
||||||
|
return 7
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
dap_dl()
|
||||||
|
{
|
||||||
|
$http_get $http_opts $http_out "$2" "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
dap_dl_bash()
|
||||||
|
{
|
||||||
|
dap_url=$1
|
||||||
|
#dap_args=$2
|
||||||
|
rm -rf dap-tmp-runner.sh
|
||||||
|
$http_get $http_opts $http_out dap-tmp-runner.sh "$dap_url"; bash dap-tmp-runner.sh; rm dap-tmp-runner.sh
|
||||||
|
}
|
||||||
|
|
||||||
|
detect_http_get
|
||||||
|
|
||||||
|
## END HTTP_GET ##
|
||||||
|
|
||||||
|
# Dependencies
|
||||||
|
dap_dl_bash "https://git.daplie.com/coolaj86/node-install-script/raw/master/setup-min.sh"
|
||||||
|
|
||||||
|
# Install
|
||||||
|
npm install -g 'git+https://git@git.daplie.com/Daplie/goldilocks.js.git#v1'
|
||||||
|
|
||||||
|
|
||||||
|
###################
|
||||||
|
# #
|
||||||
|
# Install service #
|
||||||
|
# #
|
||||||
|
###################
|
||||||
|
|
||||||
|
# Not every platform has or needs sudo
|
||||||
|
sudo_cmd=""
|
||||||
|
((EUID)) && [[ -z "$ANDROID_ROOT" ]] && sudo_cmd="sudo"
|
||||||
|
|
||||||
|
my_app_name=goldilocks
|
||||||
|
my_app_pkg_name=com.daplie.goldilocks.web
|
||||||
|
my_app_dir=$(mktemp -d)
|
||||||
|
installer_base="https://git.daplie.com/Daplie/goldilocks.js/raw/master"
|
||||||
|
|
||||||
|
my_app_systemd_service="etc/systemd/system/${my_app_name}.service"
|
||||||
|
my_app_systemd_tmpfiles="etc/tmpfiles.d/${my_app_name}.conf"
|
||||||
|
my_app_launchd_service="Library/LaunchDaemons/${my_app_pkg_name}.plist"
|
||||||
|
|
||||||
|
install_for_systemd()
|
||||||
|
{
|
||||||
|
echo ""
|
||||||
|
echo "Installing as systemd service"
|
||||||
|
echo ""
|
||||||
|
dap_dl "$installer_base/$my_app_system_service" "$my_app_dir/$my_app_system_service"
|
||||||
|
$sudo_cmd mv "$my_app_dir/$my_app_system_service" "$PREFIX/$my_app_system_service"
|
||||||
|
$sudo_cmd chown -R root:root "$PREFIX/$my_app_system_service"
|
||||||
|
$sudo_cmd chmod 644 "$PREFIX/$my_app_system_service"
|
||||||
|
|
||||||
|
dap_dl "$installer_base/$my_app_system_tmpfiles" "$my_app_dir/$my_app_system_tmpfiles"
|
||||||
|
$sudo_cmd mv "$my_app_dir/$my_app_system_tmpfiles" "$PREFIX/$my_app_system_tmpfiles"
|
||||||
|
$sudo_cmd chown -R root:root "$PREFIX/$my_app_system_tmpfiles"
|
||||||
|
$sudo_cmd chmod 644 "$PREFIX/$my_app_system_tmpfiles"
|
||||||
|
|
||||||
|
$sudo_cmd systemctl stop "${my_app_name}.service" >/dev/null 2>/dev/null
|
||||||
|
$sudo_cmd systemctl daemon-reload
|
||||||
|
$sudo_cmd systemctl start "${my_app_name}.service"
|
||||||
|
$sudo_cmd systemctl enable "${my_app_name}.service"
|
||||||
|
|
||||||
|
echo "$my_app_name started with systemctl"
|
||||||
|
}
|
||||||
|
|
||||||
|
install_for_launchd()
|
||||||
|
{
|
||||||
|
echo ""
|
||||||
|
echo "Installing as launchd service"
|
||||||
|
echo ""
|
||||||
|
# See http://www.launchd.info/
|
||||||
|
dap_dl "$installer_base/$my_app_launchd_service" "$my_app_dir/$my_app_launchd_service"
|
||||||
|
dap_dl "$caddy_launchd_service" "$my_app_dir/$my_app_launchd_service"
|
||||||
|
$sudo_cmd mv "$my_app_dir/$my_app_launchd_service" "$PREFIX/$my_app_launchd_service"
|
||||||
|
$sudo_cmd chown root:wheel "$PREFIX/$my_app_launchd_service"
|
||||||
|
$sudo_cmd chmod 0644 "$PREFIX/$my_app_launchd_service"
|
||||||
|
$sudo_cmd launchctl unload -w "$PREFIX/$my_app_launchd_service" >/dev/null 2>/dev/null
|
||||||
|
$sudo_cmd launchctl load -w "$PREFIX/$my_app_launchd_service"
|
||||||
|
|
||||||
|
echo "$my_app_name started with launchd"
|
||||||
|
}
|
||||||
|
|
||||||
|
install_service()
|
||||||
|
{
|
||||||
|
if [ -d "$PREFIX/etc/systemd/system" ]; then
|
||||||
|
install_for_systemd
|
||||||
|
elif [ -d "/Library/LaunchAgents" ]; then
|
||||||
|
install_for_launchd
|
||||||
|
else
|
||||||
|
echo ""
|
||||||
|
echo "Unknown system service init type. You must install as a system service manually."
|
||||||
|
echo '(please file a bug with the output of "uname -a")'
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
install_service
|
||||||
|
|
Loading…
Reference in New Issue