diff --git a/lutim.conf.template b/lutim.conf.template index 7af278e..c285d04 100644 --- a/lutim.conf.template +++ b/lutim.conf.template @@ -7,12 +7,6 @@ hypnotoad => { # array of IP addresses and ports you want to listen to listen => ['http://127.0.0.1:8080'], - # user and group you want for Lutim to run with - # be sure that this user/group have rights on the lutim directory - # if you launch lutim from a different user, be sure that this user have the right to su this user/group - # => if current_user is not the user that you sets here and is not root, there's chances that it will fail (see https://github.com/ldidry/lutim/issues/25) - user => 'www-data', - group => 'www-data' }, ################ diff --git a/utilities/lutim.default b/utilities/lutim.default index db9072f..bb7877f 100644 --- a/utilities/lutim.default +++ b/utilities/lutim.default @@ -1,3 +1,6 @@ # LDIR is the path where you installed Lutim # It has to end with a final / -LDIR=/var/lutim/ +LDIR=/var/www/lutim/ + +# USER is the user who will launch Lutim +USER=www-data diff --git a/utilities/lutim.init b/utilities/lutim.init index 21b88b1..702544a 100755 --- a/utilities/lutim.init +++ b/utilities/lutim.init @@ -26,6 +26,11 @@ then echo "LDIR variable is empty, please fill it in /etc/default/lutim" exit 0 fi + if [ -z $USER ] + then + echo "USER variable is empty, please fill it in /etc/default/lutim" + exit 0 + fi else echo "Missing /etc/default/lutim file" exit 0 @@ -49,7 +54,7 @@ do_start() # 2 if daemon could not be started cd $LDIR - carton exec hypnotoad $DAEMON >/dev/null 2>&1 + su $USER -c "carton exec hypnotoad $DAEMON >/dev/null 2>&1" return "$?" } @@ -62,7 +67,7 @@ do_stop() # other if a failure occurred cd $LDIR - carton exec hypnotoad -s $DAEMON >/dev/null 2>&1 + su $USER -c "carton exec hypnotoad -s $DAEMON >/dev/null 2>&1" return "$?" } @@ -75,10 +80,10 @@ do_status() if [ "$?" = "0" ]; then log_progress_msg "$NAME is running" else - log_progress_msg "$NAME is NOT running" + log_failure_msg "$NAME is NOT running but PID file exists" fi else - log_progress_msg "$NAME is NOT running" + log_failure_msg "$NAME is NOT running" fi } @@ -101,7 +106,7 @@ case "$1" in log_end_msg 0 ;; 2) - log_progress_msg "failed" + log_failure_msg "failed" log_end_msg 1 ;; esac @@ -114,7 +119,7 @@ case "$1" in log_end_msg 0 ;; 2) - log_progress_msg "failed" + log_failure_msg "failed" log_end_msg 1 ;; esac @@ -134,16 +139,16 @@ case "$1" in log_end_msg 0 ;; *) - log_progress_msg "failed" + log_failure_msg "failed" log_end_msg 1 ;; esac else - log_progress_msg "$NAME is NOT running. Unable to stop" + log_failure_msg "$NAME is NOT running. Unable to stop" log_end_msg 1 fi else - log_progress_msg "$NAME is NOT running. Unable to stop" + log_failure_msg "$NAME is NOT running. Unable to stop" log_end_msg 1 fi ;; @@ -155,13 +160,14 @@ case "$1" in reload) log_daemon_msg "Reloading $NAME" do_start + sleep 1 case "$?" in 0|1) log_progress_msg "done" log_end_msg 0 ;; 2) - log_progress_msg "failed" + log_failure_msg "failed" log_end_msg 1 ;; esac @@ -169,7 +175,7 @@ case "$1" in restart) log_daemon_msg "Restarting $NAME" do_stop - sleep 1 + sleep 6 do_start case "$?" in 0|1) @@ -177,7 +183,7 @@ case "$1" in log_end_msg 0 ;; 2) - log_progress_msg "failed"; + log_failure_msg "failed"; log_end_msg 1 ;; esac diff --git a/utilities/lutim.service b/utilities/lutim.service index ebb4f12..32b16d8 100644 --- a/utilities/lutim.service +++ b/utilities/lutim.service @@ -5,10 +5,12 @@ Requires=network.target After=network.target [Service] -Type=simple +Type=forking +User=www-data +RemainAfterExit=yes WorkingDirectory=/var/www/lutim/ PIDFile=/var/www/lutim/script/hypnotoad.pid -ExecStart=/usr/local/bin/carton exec hypnotoad -f script/lutim +ExecStart=/usr/local/bin/carton exec hypnotoad script/lutim ExecStop=/usr/local/bin/carton exec hypnotoad -s script/lutim ExecReload=/usr/local/bin/carton exec hypnotoad script/lutim diff --git a/utilities/lutim_upstart.conf b/utilities/lutim_upstart.conf index 2f5274c..197300a 100644 --- a/utilities/lutim_upstart.conf +++ b/utilities/lutim_upstart.conf @@ -14,10 +14,15 @@ script echo "LDIR variable is empty, please fill it in /etc/default/lutim" exit 0 fi + if [ -z $USER ] + then + echo "USER variable is empty, please fill it in /etc/default/lutim" + exit 0 + fi else echo "Missing /etc/default/lutim file" exit 0 fi cd $LDIR - carton exec hypnotoad script/lutim -f + su $USER -c "carton exec hypnotoad -f script/lutim" end script