From 0b4c80c15be86071cce1b400bef701dcaf3cf8f7 Mon Sep 17 00:00:00 2001 From: Benjamin Chambers Date: Mon, 9 Jul 2018 21:06:46 -0400 Subject: [PATCH] Added StartLimitBurst to systemd and cleaned up logic for checking daemon status --- deploy/info.php | 2 +- deploy/service-check | 8 ++++---- deploy/upgrade | 5 +++++ libraries/Syncthing.php | 16 +++++++++------- packaging/app-syncthing.cron | 1 + packaging/app-syncthing.spec | 2 +- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/deploy/info.php b/deploy/info.php index 6e7fcfa..06dae44 100644 --- a/deploy/info.php +++ b/deploy/info.php @@ -4,7 +4,7 @@ // General information ///////////////////////////////////////////////////////////////////////////// $app['basename'] = 'syncthing'; -$app['version'] = '1.1.14'; +$app['version'] = '1.1.15'; $app['release'] = '1'; $app['vendor'] = 'WikiSuite'; $app['packager'] = 'WikiSuite'; diff --git a/deploy/service-check b/deploy/service-check index 9967023..edc8d77 100755 --- a/deploy/service-check +++ b/deploy/service-check @@ -72,19 +72,19 @@ use \Exception as Exception; // Command line options //-------------------------------------------------------------------- -$short_options = ''; - -// Common +$short_options = 'f'; // Force $options = getopt($short_options); +$force = isset($options['f']) ? TRUE : FALSE; + // Command line options //-------------------------------------------------------------------- $syncthing = new Syncthing(); try { - $syncthing->restart_multiuser(); + $syncthing->restart_multiuser($force); } catch (Exception $e) { echo clearos_exception_message($e) . "\n"; } diff --git a/deploy/upgrade b/deploy/upgrade index ef1f641..7f8ffd4 100755 --- a/deploy/upgrade +++ b/deploy/upgrade @@ -5,3 +5,8 @@ if [ -z "$CHECK" ]; then sed -i "/RewriteCond/d" /usr/clearos/sandbox/etc/httpd/conf.d/syncthing.conf sed -i "/RewriteRule/d" /usr/clearos/sandbox/etc/httpd/conf.d/syncthing.conf fi +CHECK=`grep "StartLimitBurst=0" /etc/systemd/system/syncthing@.service` +if [ -z "$CHECK" ]; then + sed -i "/^User=%i$/a StartLimitBurst=0" /etc/systemd/system/syncthing@.service + /usr/bin/systemctl daemon-reload +fi diff --git a/libraries/Syncthing.php b/libraries/Syncthing.php index 90b4300..1d3c0f0 100644 --- a/libraries/Syncthing.php +++ b/libraries/Syncthing.php @@ -287,7 +287,7 @@ public function set_state($username, $enabled) $shell = new Shell(); if ($enabled) { $shell->execute(parent::COMMAND_SYSTEMCTL, "enabled syncthing@$username.service", TRUE, $options); - $shell->execute(parent::COMMAND_SYSTEMCTL, "start syncthing@$username.service", TRUE, $options); + $shell->execute(parent::COMMAND_SYSTEMCTL, "restart syncthing@$username.service", TRUE, $options); } else { $shell->execute(parent::COMMAND_SYSTEMCTL, "disabled syncthing@$username.service", TRUE, $options); $shell->execute(parent::COMMAND_SYSTEMCTL, "stop syncthing@$username.service", TRUE, $options); @@ -387,26 +387,28 @@ public function get_lan_ip() /** * Restart all daemons. + * @param $force force restart * * @throws Engine_Exception */ - function restart_multiuser() + function restart_multiuser($force = false) { clearos_profile(__METHOD__, __LINE__); $file = new File(self::FILE_RESTART_MULTIUSER); - if (!$file->exists()) + if (!$force && !$file->exists()) return; $users = $this->get_users_config(); foreach ($users as $user => $meta) { try { - $this->set_state($user, FALSE); - if ($meta['enabled'] !== TRUE) - $this->set_state($user, TRUE); + if ($force || ($meta['status'] && !$meta['enabled']) || (!$meta['status'] && $meta['enabled'])) + $this->set_state($user, $meta['enabled']); } catch (Exception $e) { + clearos_log('syncthing', $user . ":" . clearos_exception_message($e)); } } - $file->delete(); + if ($file->exists()) + $file->delete(); } /** diff --git a/packaging/app-syncthing.cron b/packaging/app-syncthing.cron index f74c02d..dbdbfe8 100644 --- a/packaging/app-syncthing.cron +++ b/packaging/app-syncthing.cron @@ -1,2 +1,3 @@ */10 * * * * root /usr/clearos/apps/syncthing/deploy/service-check >/dev/null 2>&1 +0 4 * * * root /usr/clearos/apps/syncthing/deploy/service-check -f >/dev/null 2>&1 0 */4 * * * root /usr/clearos/apps/syncthing/deploy/config-check >/dev/null 2>&1 diff --git a/packaging/app-syncthing.spec b/packaging/app-syncthing.spec index cb1636e..c986038 100644 --- a/packaging/app-syncthing.spec +++ b/packaging/app-syncthing.spec @@ -1,7 +1,7 @@ Name: app-syncthing Epoch: 1 -Version: 1.1.14 +Version: 1.1.15 Release: 1%{dist} Summary: Syncthing License: GPLv3