[Debpool-commits] [SCM] Debpool Project Repository branch, master, updated. 0.2.3-63-g38a32aa
ceros-guest
ceros-guest at alioth.debian.org
Tue Jun 3 07:07:14 UTC 2008
The following commit has been merged in the master branch:
commit 7b907deb73d0b958ded2281b85c11123e293a31e
Author: ceros-guest <ceros-guest>
Date: Thu Jan 17 03:10:12 2008 +0000
Made it easier to run debpool as any user other than root using init scripts.
diff --git a/bin/debpool b/bin/debpool
index 6c18208..7e034d4 100755
--- a/bin/debpool
+++ b/bin/debpool
@@ -108,32 +108,42 @@ if ($Options{'get_lock_path'}) {
if (!sysopen(LOCK_FILE, $Options{'lock_file'}, O_WRONLY|O_CREAT|O_EXCL, 0644)) {
my($msg) = "Couldn't obtain lockfile '$Options{'lock_file'}': ";
-
- if (open(LOCK_FILE, '<', $Options{'lock_file'}) &&
- (my($pid) = <LOCK_FILE>)) {
+ if (( ! -s $Options{'lock_file'} ) and
+ (open(LOCK_FILE, '>', $Options{'lock_file'}))) {
+ # Empty file found for lock file
+ print LOCK_FILE "$$\n";
+ close(LOCK_FILE);
+ } elsif (open(LOCK_FILE, '<', $Options{'lock_file'}) &&
+ (my($pid) = <LOCK_FILE>)) {
chomp($pid);
if (open(STAT_FILE, '<', "/proc/$pid/stat") &&
- (my($stat) = <STAT_FILE>)) {
+ (my($stat) = <STAT_FILE>)) {
if ($stat =~ m/debpool/) {
# debpool process was already started
$msg .= "debpool was already running with PID $pid\n";
close(LOCK_FILE);
close(STAT_FILE);
+ Log_Message($msg, LOG_GENERAL, LOG_ERROR);
die $msg;
}
} else {
- # debpool wasn't running using the specified PID so remove
- # the lock and create a new one
+ # debpool wasn't running using the specified PID so close
+ # the file and reopen it for overwriting.
+ close(LOCK_FILE);
+ if (!open(LOCK_FILE, '>', $Options{'lock_file'})) {
+ $msg .= "debpool could not place new PID ";
+ $msg .= "in lock file.\n";
+ Log_Message($msg, LOG_GENERAL, LOG_ERROR);
+ die $msg;
+ }
+ print LOCK_FILE "$$\n";
close(LOCK_FILE);
- unlink $Options{'lock_file'};
- sysopen(NEW_LOCK_FILE, $Options{'lock_file'},
- O_WRONLY|O_CREAT|O_EXCL, 0644);
- print NEW_LOCK_FILE "$$\n";
- close(NEW_LOCK_FILE);
}
} else {
# Could not read PID from lockfile
$msg .= "(unable to read PID)\n";
+ Log_Message($msg, LOG_GENERAL, LOG_ERROR);
+ die $msg;
}
} else { # debpool wasn't running so create a lock
print LOCK_FILE "$$\n";
diff --git a/debian/debpool.default b/debian/debpool.default
index 7760eaa..10be776 100644
--- a/debian/debpool.default
+++ b/debian/debpool.default
@@ -8,9 +8,11 @@ ENABLED="0"
# to specify --daemon.
OPTIONS=""
-# User or user:group to run debpool as. If you leave it empty, debpool
-# will run as root.
+# User and group to run debpool as. If you leave DEBPOOL_USER empty, debpool
+# will run as root. If you leave the group empty, DEBPOOL_GROUP will be the
+# same as DEBPOOL_USER.
DEBPOOL_USER=""
+DEBPOOL_GROUP=""
# Specify a path for the log file
LOGFILE="/var/log/$NAME.log"
diff --git a/debian/debpool.init b/debian/debpool.init
index 4405cc8..33f76b0 100644
--- a/debian/debpool.init
+++ b/debian/debpool.init
@@ -40,6 +40,7 @@ fi
# Run as root if DEBPOOL_USER not specified
if [ ! $DEBPOOL_USER ]; then
DEBPOOL_USER=root
+ DEBPOOL_GROUP=root
fi
# Check for an invalid user or one without a home directory
@@ -49,33 +50,34 @@ if [ "${USERHOME#/}" = "${USERHOME}" ]; then
exit 1
fi
-# Run as $DEBPOOL_USER if not running as root
+# Run as $DEBPOOL_USER:$DEBPOOL_GROUP if not running as root
if [ "$DEBPOOL_USER" != "root" ]; then
- CHUID="--chuid $DEBPOOL_USER"
+ if [ -z "$DEBPOOL_GROUP" ]; then
+ DEBPOOL_GROUP="$DEBPOOL_USER"
+ fi
+ CHUID="--chuid $DEBPOOL_USER:$DEBPOOL_GROUP"
fi
# If lock file specified, pass it to debpool with --lock_file
# else try to determine lock file using Debpool::Config
if [ "$LOCKFILE" ]; then
- PIDFILE=$LOCKFILE
- LOCKFILE="--lock_file $LOCKFILE"
+ LOCKFILE_OPT="--lock_file $LOCKFILE"
else
LOCKFILE=$(HOME=$USERHOME debpool --get_lock_path) || \
{
log_failure_msg "$NAME: could not determine lock file path."
exit 1
}
- PIDFILE=$LOCKFILE
- LOCKFILE="--lock_file $LOCKFILE"
+ LOCKFILE_OPT="--lock_file $LOCKFILE"
fi
# If log file specified, pass it to debpool with --log_file option
if [ "$LOGFILE" ]; then
- LOGFILE="--log_file $LOGFILE"
+ LOGFILE_OPT="--log_file $LOGFILE"
fi
# Specify all options to use for debpool
-DAEMON_ARGS="--daemon $LOGFILE $LOCKFILE $OPTIONS"
+DAEMON_ARGS="--daemon $LOGFILE_OPT $LOCKFILE_OPT $OPTIONS"
#
# Function that starts the daemon/service
@@ -86,10 +88,14 @@ do_start()
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
- start-stop-daemon --start --quiet --pidfile $PIDFILE \
+ touch $LOCKFILE
+ chown $DEBPOOL_USER:$DEBPOOL_GROUP $LOCKFILE
+ touch $LOGFILE
+ chown $DEBPOOL_USER:$DEBPOOL_GROUP $LOGFILE
+ start-stop-daemon --start --quiet --pidfile $LOCKFILE \
--startas $DAEMON $CHUID --test > /dev/null || \
return 1
- start-stop-daemon --start --quiet --pidfile $PIDFILE \
+ start-stop-daemon --start --quiet --pidfile $LOCKFILE \
--startas $DAEMON $CHUID -- $DAEMON_ARGS || \
return 2
}
@@ -104,9 +110,10 @@ do_stop()
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
- start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
+ start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $LOCKFILE --name $NAME
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
+ [ ! -f $LOCKFILE ] || rm $LOCKFILE
return "$RETVAL"
}
@@ -122,7 +129,7 @@ do_stop()
# # restarting (for example, when it is sent a SIGHUP),
# # then implement that here.
# #
-# start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
+# start-stop-daemon --stop --signal 1 --quiet --pidfile $LOCKFILE --name $NAME
# return 0
# }
--
Debpool Project Repository
More information about the Debpool-commits
mailing list