Attempting to make systemctl user unit

This commit is contained in:
notplants 2022-04-11 16:57:05 -04:00
parent 659b298249
commit 0907c07c97
9 changed files with 87 additions and 59 deletions

View File

@ -1,4 +1,4 @@
Package: peach-go-sbot
Package: go-sbot
Version: {{version}}
Architecture: all
Maintainer: Andrew Reid <gnomad@cryptolab.net>

View File

@ -1,40 +1,43 @@
#!/bin/sh
set -e
# create user which go-sbot runs as
adduser --quiet --system peach-go-sbot
# create user which go-sbot runs as (if doesnt exist)
id -u peach &>/dev/null || adduser --quiet peach
# set permissions
chown peach-go-sbot /usr/bin/go-sbot
chown peach-go-sbot /usr/bin/sbotcli
chown peach /usr/bin/go-sbot
chown peach /usr/bin/sbotcli
# Automatically added by cargo-deb
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
# This will only remove masks created by d-s-h on package removal.
deb-systemd-helper unmask peach-go-sbot.service >/dev/null || true
deb-systemd-helper --user unmask go-sbot.service >/dev/null || true
# was-enabled defaults to true, so new installations run enable.
if deb-systemd-helper --quiet was-enabled peach-go-sbot.service; then
if deb-systemd-helper --user --quiet was-enabled go-sbot.service; then
# Enables the unit on first installation, creates new
# symlinks on upgrades if the unit file has changed.
deb-systemd-helper enable peach-go-sbot.service >/dev/null || true
deb-systemd-helper --user enable go-sbot.service >/dev/null || true
else
# Update the statefile to add new symlinks (if any), which need to be
# cleaned up on purge. Also remove old symlinks.
deb-systemd-helper update-state peach-go-sbot.service >/dev/null || true
deb-systemd-helper --user update-state go-sbot.service >/dev/null || true
fi
fi
# End automatically added section
# Automatically added by cargo-deb
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
if [ -d /run/systemd/system ]; then
systemctl --system daemon-reload >/dev/null || true
# USER="$(who | head -1 | awk '{print $1;}')"
USER="peach"
runuser -l $USER -c "XDG_RUNTIME_DIR=/run/user/$(id -u $USER) systemctl --user daemon-reload >/dev/null || true"
if [ -n "$2" ]; then
_dh_action=restart
else
_dh_action=start
fi
deb-systemd-invoke $_dh_action peach-go-sbot.service >/dev/null || true
runuser -l $USER -c "XDG_RUNTIME_DIR=/run/user/$(id -u $USER) deb-systemd-invoke --user $_dh_action go-sbot.service >/dev/null || true"
fi
fi
# End automatically added section

View File

@ -0,0 +1,21 @@
# Automatically added by cargo-deb
if [ -d /run/systemd/system ]; then
# USER="$(who | head -1 | awk '{print $1;}')"
USER="peach"
runuser -l $USER -c "XDG_RUNTIME_DIR=/run/user/$(id -u $USER) systemctl --user daemon-reload >/dev/null || true"
fi
# End automatically added section
# Automatically added by cargo-deb
if [ "$1" = "remove" ]; then
if [ -x "/usr/bin/deb-systemd-helper" ]; then
deb-systemd-helper --user mask service >/dev/null || true
fi
fi
if [ "$1" = "purge" ]; then
if [ -x "/usr/bin/deb-systemd-helper" ]; then
deb-systemd-helper --user purge service >/dev/null || true
deb-systemd-helper --user unmask service >/dev/null || true
fi
fi
# End automatically added section

View File

@ -0,0 +1,7 @@
# Automatically added by cargo-deb
if [ -d /run/systemd/system ] && [ "$1" = remove ]; then
# USER="$(who | head -1 | awk '{print $1;}')"
USER="peach"
runuser -l $USER -c "XDG_RUNTIME_DIR=/run/user/$(id -u $USER) deb-systemd-invoke --user stop service >/dev/null || true"
fi
# End automatically added section

View File

@ -0,0 +1,15 @@
# For details about go-sbot configuration, please visit the repo: https://github.com/cryptoscope/ssb
repo = "/home/peach/.ssb-go"
debugdir = ""
shscap = "1KHLiKZvAvjbY1ziZEHMXawbCEIM6qwjCDm3VYRan/s="
hmac = ""
hops = 2
lis = "127.0.0.1:8008"
wslis = ":8987"
debuglis = "localhost:6078"
localadv = true
localdiscov = true
enable_ebt = true
promisc = true
nounixsock = false
repair = true

View File

@ -3,7 +3,8 @@ Description=peachs go-sbot
[Service]
Type=simple
User=peach-go-sbot
User=peach
Environment="LIBRARIAN_WRITEALL=0"
ExecStart=/usr/bin/go-sbot
Restart=always

View File

@ -1,21 +0,0 @@
#!/bin/sh
set -e
# Automatically added by cargo-deb
if [ -d /run/systemd/system ]; then
systemctl --system daemon-reload >/dev/null || true
fi
# End automatically added section
# Automatically added by cargo-deb
if [ "$1" = "remove" ]; then
if [ -x "/usr/bin/deb-systemd-helper" ]; then
deb-systemd-helper mask peach-go-sbot.service >/dev/null || true
fi
fi
if [ "$1" = "purge" ]; then
if [ -x "/usr/bin/deb-systemd-helper" ]; then
deb-systemd-helper purge peach-go-sbot.service >/dev/null || true
deb-systemd-helper unmask peach-go-sbot.service >/dev/null || true
fi
fi
# End automatically added section

View File

@ -1,7 +0,0 @@
#!/bin/sh
set -e
# Automatically added by cargo-deb
if [ -d /run/systemd/system ] && [ "$1" = remove ]; then
deb-systemd-invoke stop peach-go-sbot.service >/dev/null || true
fi
# End automatically added section

View File

@ -14,15 +14,15 @@ from peach_package_builder.constants import *
from peach_package_builder.utils import render_template, add_deb_to_freight, update_freight_cache
# manually update this version when we want to build a new peach-go-sbot package
PEACH_GO_SBOT_VERSION = '0.1.4'
GO_SBOT_VERSION = '0.1.21'
# constants
DEB_CONF_DIR = os.path.join(PROJECT_PATH, 'conf/templates/peach_go_sbot')
DEB_BUILD_DIR = "/tmp/peach_go_sbot"
DEB_CONF_DIR = os.path.join(PROJECT_PATH, 'conf/templates/go_sbot')
DEB_BUILD_DIR = "/tmp/go_sbot"
GO_SSB_DIR = "/srv/peachcloud/automation/go-ssb"
def crosscompile_peach_go_sbot():
def crosscompile_go_sbot():
subprocess.check_call(["git", "pull"], cwd=GO_SSB_DIR)
print("[CROSS-COMPILING sbotcli]")
subprocess.check_call(["env", "GOOS=linux", "GOARCH=arm64", "go", "build", "./cmd/sbotcli"], cwd=GO_SSB_DIR)
@ -30,8 +30,8 @@ def crosscompile_peach_go_sbot():
subprocess.check_call(["env", "GOOS=linux", "GOARCH=arm64", "go", "build", "./cmd/go-sbot"], cwd=GO_SSB_DIR)
def package_peach_go_sbot(version):
print("[ PACKAGING peach-go-sbot ]")
def package_go_sbot(version):
print("[ PACKAGING go-sbot ]")
# copy debian conf files into correct locations in package build directory
DEBIAN_SRC_DIR = os.path.join(DEB_CONF_DIR, 'DEBIAN')
DEBIAN_DEST_DIR = os.path.join(DEB_BUILD_DIR, 'DEBIAN')
@ -43,16 +43,25 @@ def package_peach_go_sbot(version):
shutil.copyfile(src, dest)
subprocess.check_call(["chmod", "775", dest])
# copy control file putting in correct version number
src = os.path.join("peach_go_sbot/DEBIAN/control")
src = os.path.join("go_sbot/DEBIAN/control")
dest = os.path.join(DEBIAN_DEST_DIR, "control")
render_template(src=src, dest=dest, template_vars={"version": version})
# copy systemd service file
SERVICE_DIR = os.path.join(DEB_BUILD_DIR, 'lib/systemd/system')
SERVICE_DIR = os.path.join(DEB_BUILD_DIR, 'home/peach/.config/systemd')
# SERVICE_DIR = os.path.join(DEB_BUILD_DIR, 'lib/systemd/system')
os.makedirs(SERVICE_DIR)
shutil.copyfile(
os.path.join(DEB_CONF_DIR, 'peach-go-sbot.service'),
os.path.join(SERVICE_DIR, 'peach-go-sbot.service')
os.path.join(DEB_CONF_DIR, 'go-sbot.service'),
os.path.join(SERVICE_DIR, 'go-sbot.service')
)
# copy go-sbot config.toml
SBOT_CONFIG_DIR = os.path.join(DEB_BUILD_DIR, 'home/peach/.ssb-go')
os.makedirs(SBOT_CONFIG_DIR)
shutil.copyfile(
os.path.join(DEB_CONF_DIR, 'config.toml'),
os.path.join(SBOT_CONFIG_DIR, 'config.toml')
)
# copy cross-compiled binaries
@ -68,7 +77,7 @@ def package_peach_go_sbot(version):
subprocess.check_call(["chmod", "770", destination])
# create deb package
deb_file_name = "peach-go-sbot_{}_arm64.deb".format(version)
deb_file_name = "go-sbot_{}_arm64.deb".format(version)
print("[ CREATING {}]".format(deb_file_name))
subprocess.check_call(["dpkg-deb", "-b", ".", deb_file_name], cwd=DEB_BUILD_DIR)
@ -83,22 +92,22 @@ def package_peach_go_sbot(version):
update_freight_cache()
def build_peach_go_sbot():
def build_go_sbot():
# gets the most recently built peach_go_sbot version, and increments the micro-number by 1
version = PEACH_GO_SBOT_VERSION
print("[ BUILDING PEACH-GO-SBOT VERSION {}]".format(version))
# gets the most recently built go_sbot version, and increments the micro-number by 1
version = GO_SBOT_VERSION
print("[ BUILDING GO-SBOT VERSION {}]".format(version))
# delete build directory if it already exists or create it
subprocess.check_call(["rm", "-rf", DEB_BUILD_DIR])
if not os.path.exists(DEB_BUILD_DIR):
os.makedirs(DEB_BUILD_DIR)
# cross-compile and package peach-go-sbot with new version number
crosscompile_peach_go_sbot()
package_peach_go_sbot(version=version)
# cross-compile and package go-sbot with new version number
crosscompile_go_sbot()
package_go_sbot(version=version)
if __name__ == '__main__':
build_peach_go_sbot()
build_go_sbot()