2013-02-21 05:46:27 +00:00
|
|
|
#!/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
|
2013-04-01 21:55:15 +00:00
|
|
|
|
|
|
|
script
|
|
|
|
exec sudo -u $user /opt/stack/venvs/$user/bin/$cmd $args
|
|
|
|
end script
|
2013-02-21 05:46:27 +00:00
|
|
|
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 $*
|