Allow testing systemd integration with a test unit file
This commit is contained in:
parent
6594a667af
commit
74580d382b
|
@ -0,0 +1,32 @@
|
||||||
|
# Unit file for testing systemd integration with a test instance of Syncthing
|
||||||
|
# 1. Copy to ~/.config/systemd/user/syncthing-testinstance.service for using it.
|
||||||
|
# 2. Set HOME=/tmp/syncthingtest when launching Syncthing Tray itself to be in
|
||||||
|
# accordance with this unit file.
|
||||||
|
# 3. Set SYNCTHINGTRAY_SYSTEMD_USER_UNIT=syncthing-testinstance.service so the
|
||||||
|
# wizard will make use of this unit instead of the normal one.
|
||||||
|
|
||||||
|
[Unit]
|
||||||
|
Description=Test instance of Syncthing with HOME under /tmp/syncthingtest
|
||||||
|
Documentation=man:syncthing(1)
|
||||||
|
StartLimitIntervalSec=60
|
||||||
|
StartLimitBurst=4
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=/usr/bin/syncthing serve --no-browser --no-restart --logflags=0
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=1
|
||||||
|
SuccessExitStatus=3 4
|
||||||
|
RestartForceExitStatus=3 4
|
||||||
|
Environment=HOME=/tmp/syncthingtest
|
||||||
|
|
||||||
|
# Hardening
|
||||||
|
SystemCallArchitectures=native
|
||||||
|
MemoryDenyWriteExecute=true
|
||||||
|
NoNewPrivileges=true
|
||||||
|
|
||||||
|
# Elevated permissions to sync ownership (disabled by default),
|
||||||
|
# see https://docs.syncthing.net/advanced/folder-sync-ownership
|
||||||
|
#AmbientCapabilities=CAP_CHOWN CAP_FOWNER
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=default.target
|
|
@ -1,5 +1,8 @@
|
||||||
#include "./setupdetection.h"
|
#include "./setupdetection.h"
|
||||||
|
|
||||||
|
// use meta-data of syncthingtray application here
|
||||||
|
#include "resources/../../tray/resources/config.h"
|
||||||
|
|
||||||
#if defined(LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD) && (defined(PLATFORM_UNIX) || defined(PLATFORM_MINGW) || defined(PLATFORM_CYGWIN))
|
#if defined(LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD) && (defined(PLATFORM_UNIX) || defined(PLATFORM_MINGW) || defined(PLATFORM_CYGWIN))
|
||||||
#define PLATFORM_HAS_GETLOGIN
|
#define PLATFORM_HAS_GETLOGIN
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -11,8 +14,17 @@ SetupDetection::SetupDetection(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
{
|
{
|
||||||
// assume default service names
|
// assume default service names
|
||||||
|
const auto defaultUserUnit =
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
||||||
|
qEnvironmentVariable(PROJECT_VARNAME_UPPER "_SYSTEMD_USER_UNIT",
|
||||||
|
#endif
|
||||||
|
QStringLiteral("syncthing.service")
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
||||||
|
)
|
||||||
|
#endif
|
||||||
|
;
|
||||||
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
||||||
userService.setUnitName(QStringLiteral("syncthing.service"));
|
userService.setUnitName(defaultUserUnit);
|
||||||
systemService.setUnitName(QStringLiteral("syncthing@") %
|
systemService.setUnitName(QStringLiteral("syncthing@") %
|
||||||
#ifdef PLATFORM_HAS_GETLOGIN
|
#ifdef PLATFORM_HAS_GETLOGIN
|
||||||
QString::fromLocal8Bit(getlogin()) %
|
QString::fromLocal8Bit(getlogin()) %
|
||||||
|
|
Loading…
Reference in New Issue