데몬을 시작하는 init 스크립트가 있습니다. 문제는 루트로 실행된다는 것입니다. “deploy”라는 사용자로 실행하고 싶습니다. 우분투 12.04
#! /bin/sh
# File: /etc/init.d/unicorn
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the unicorn web server
# Description: starts unicorn
### END INIT INFO
DAEMON=/usr/local/bin/unicorn_rails
DAEMON_OPTS="-c /var/www/current/config/unicorn.rb -D"
NAME=unicorn
DESC="Unicorn"
PID=/var/www/current/shared/pid/unicorn.pid
case "$1" in
start)
echo -n "Starting $DESC: "
$DAEMON $DAEMON_OPTS
echo "$NAME."
;;
*)
echo "Usage: $NAME {start|stop|restart|reload}" >&2
exit 1
;;
esac
exit 0
답변
start-stop-daemon
유틸리티를 사용 하여 데몬을 시작하십시오. 패스 -c
(또는 --chuid
다른 사용자로 실행) 옵션을 선택합니다. 에 몇 가지 예가 있습니다 /etc/init.d/*
.
case $1 in
start)
echo -n "Starting $DESC: "
start-stop-daemon --start --chuid deploy --pidfile "$PID" --start --exec "$DAEMON" -- $DAEMON_OPTS
echo "$NAME."
;;
…
답변
우분투에서는 그냥 사용할 수 있습니다
sudo -u deploy $DAEMON $DAEMON_OPTS