Oops, in previous message I forgot to attach the patch. Here it is...
--
Rowan Thorpe
PGP fingerprint:
BB0A 0787 C0EE BDD8 7F97 3D30 49F2 13A5 265D CCBD
----
"There is a great difference between worry and concern. A worried person sees
a problem, and a concerned person solves a problem."
- Harold Stephens
>From 3b8c7da4f4eee8a8cb8afca6c2f2498cfb595f79 Mon Sep 17 00:00:00 2001
From: Rowan Thorpe <[email protected]>
Date: Thu, 5 Mar 2015 12:05:48 +0200
Subject: Improve ease-of-use for running daemon as non-root
* tweak init-script to set user/group (default coquelicot:coquelicot)
* change pid location to avoid permissions problems
---
debian/coquelicot.dirs | 1 +
debian/coquelicot.init.d | 11 +++++++----
debian/coquelicot.postinst | 4 ++++
debian/coquelicot.postrm | 1 +
debian/patches/0011-Improve-running-as-non-root.patch | 17 +++++++++++++++++
debian/patches/series | 1 +
debian/settings.yml | 2 +-
7 files changed, 32 insertions(+), 5 deletions(-)
create mode 100644 debian/patches/0011-Improve-running-as-non-root.patch
diff --git a/debian/coquelicot.dirs b/debian/coquelicot.dirs
index 6565904..bb1dfc6 100644
--- a/debian/coquelicot.dirs
+++ b/debian/coquelicot.dirs
@@ -1,2 +1,3 @@
+var/run/coquelicot
var/log/coquelicot
var/lib/coquelicot
diff --git a/debian/coquelicot.init.d b/debian/coquelicot.init.d
index b4adcc7..fbd7e2e 100755
--- a/debian/coquelicot.init.d
+++ b/debian/coquelicot.init.d
@@ -18,10 +18,12 @@ DESC='Coquelicot "one-click" file sharing web application'
NAME=coquelicot
DAEMON=/usr/bin/coquelicot
DAEMON_ARGS="start"
-PIDFILE=/var/run/$NAME.pid
+PIDFILE=/var/run/${NAME}/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
# override the below settings in /etc/default/coquelicot
VERBOSE='yes'
+USER='coquelicot'
+GROUP='coquelicot'
# Exit if the package is not installed
[ -x $DAEMON ] || exit 0
@@ -35,10 +37,11 @@ VERBOSE='yes'
do_start()
{
- start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
+ start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test \
+ --chuid "${USER}:${GROUP}" > /dev/null \
|| return 1
- LC_ALL=C.UTF-8 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
- $DAEMON_ARGS \
+ LC_ALL=C.UTF-8 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON \
+ --chuid "${USER}:${GROUP}" -- $DAEMON_ARGS \
|| return 2
}
diff --git a/debian/coquelicot.postinst b/debian/coquelicot.postinst
index aa0e742..7611186 100755
--- a/debian/coquelicot.postinst
+++ b/debian/coquelicot.postinst
@@ -9,6 +9,10 @@ case "$1" in
--no-create-home \
--home /var/lib/coquelicot coquelicot >/dev/null
fi
+ if ! dpkg-statoverride --list "/var/run/coquelicot"; then
+ chown coquelicot:coquelicot /var/run/coquelicot
+ chmod 755 /var/lib/coquelicot
+ fi
if ! dpkg-statoverride --list "/var/lib/coquelicot"; then
chown coquelicot:coquelicot /var/lib/coquelicot
chmod 750 /var/lib/coquelicot
diff --git a/debian/coquelicot.postrm b/debian/coquelicot.postrm
index 75c905b..12a1988 100755
--- a/debian/coquelicot.postrm
+++ b/debian/coquelicot.postrm
@@ -5,6 +5,7 @@ set -e
case "$1" in
purge)
rm -rf /etc/coquelicot
+ rm -rf /var/run/coquelicot
rm -rf /var/lib/coquelicot
rm -rf /var/log/coquelicot
;;
diff --git a/debian/patches/0011-Improve-running-as-non-root.patch b/debian/patches/0011-Improve-running-as-non-root.patch
new file mode 100644
index 0000000..076cf05
--- /dev/null
+++ b/debian/patches/0011-Improve-running-as-non-root.patch
@@ -0,0 +1,17 @@
+Description: Improve running as non root (pid location)
+Author: Rowan Thorpe <[email protected]>
+Forwarded: not-needed
+Last-Update: 2015-03-05
+---
+This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
+--- a/lib/coquelicot/app.rb
++++ b/lib/coquelicot/app.rb
+@@ -240,7 +240,7 @@
+ set :random_pass_length, 16
+ set :about_text, 'en' => ''
+ set :additional_css, ''
+- set :pid, '/var/run/coquelicot.pid'
++ set :pid, '/var/run/coquelicot/coquelicot.pid'
+ set :log, '/var/log/coquelicot/coquelicot.log'
+ set :listen, [ "127.0.0.1:51161" ]
+ set :path, '/'
diff --git a/debian/patches/series b/debian/patches/series
index 3cdc319..f0b777a 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -4,3 +4,4 @@
0005-Adjust-paths-to-fit-Debian-packaging.patch
0006-Stop-using-non-free-background-image.patch
0010-Fix-gem-dependency-issues.patch
+0011-Improve-running-as-non-root.patch
diff --git a/debian/settings.yml b/debian/settings.yml
index c5653fd..0d2d3ba 100644
--- a/debian/settings.yml
+++ b/debian/settings.yml
@@ -81,7 +81,7 @@ about_text:
additional_css: ""
# Path to the PID file of the web server
-pid: "/var/run/coquelicot.pid"
+pid: "/var/run/coquelicot/coquelicot.pid"
# Path to Coquelicot log file
#
--
2.1.4