diskimage-builder/elements/os-svc-install/bin/os-svc-daemon
Clint Byrum 4762f65dc1 Streamline upstart scripts in os-svc-daemon
Best practice is to use start-stop-daemon rather than sudo, as sudo will
apply user-centric pam limits and create a wtmp entry. Also there is no
need for a script stanza, as we are only execing one command.

Change-Id: I0c2f12536b56d90fd43ab40e74424350efcc0b61
2013-04-03 11:32:17 -07:00

34 lines
627 B
Bash
Executable File

#!/bin/bash
set -eu
function install_upstart {
local name=$1
local user=$2
local cmd=$3
shift; shift; shift
local args=$*
cat > /etc/init/$name.conf <<EOF
start on runlevel [2345]
stop on runlevel [016]
pre-start script
mkdir -p /var/run/$user
chown -R $user:$user /var/run/$user
end script
respawn
exec start-stop-daemon --start -c $user --exec /opt/stack/venvs/$user/bin/$cmd $args
EOF
}
if [ $# -lt 4 ]; then
echo "Usage: os-svc-daemon DAEMON_NAME USER COMMAND [ARG[ARG[...]]]"
exit 1
fi
# TODO: check what system we are on, and install
# systemv instead, if appropriate.
install_upstart $*