1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/movim_ynh.git synced 2024-09-03 19:46:19 +02:00

new init script (not tested)

This commit is contained in:
src386 2015-08-31 17:42:30 +02:00
parent 062e121eab
commit 588b28659d

View file

@ -5,97 +5,71 @@
# Required-Stop: $remote_fs $syslog # Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5 # Default-Start: 2 3 4 5
# Default-Stop: 0 1 6 # Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time # Short-Description: Movim
# Description: Enable service provided by daemon. # Description: Kickass social network
### END INIT INFO ### END INIT INFO
dir="YHDIR" PATH=/sbin:/bin:/usr/sbin:/usr/bin
cmd="php daemon.php https://YHURL YHPORT"
user="movim"
name=`basename $0`
pid_file="/var/run/$name.pid"
get_pid() {
cat "$pid_file"
}
is_running() {
[ -f "$pid_file" ] && ps `get_pid` > /dev/null 2>&1
}
. /lib/lsb/init-functions . /lib/lsb/init-functions
NAME=movim
DESC="Movim PHP Daemon"
MOVIMPID=/var/run/movim.pid
check_status()
{
if [ ! -r "$MOVIMPID" ]; then
test "$1" != -v || echo "$NAME is not running."
return 3
fi
if read pid < "$MOVIMPID" && ps -p "$pid" > /dev/null 2>&1; then
test "$1" != -v || echo "$NAME is running."
return 0
else
test "$1" != -v || echo "$NAME is not running but $MOVIMPID exists."
return 1
fi
}
case "$1" in case "$1" in
start) start)
if is_running; then log_daemon_msg "Starting $DESC" "$NAME"
echo "Already started" start-stop-daemon --start --quiet --pidfile $MOVIMPID \
else --exec /usr/bin/php5 -- YHDIR/daemon.php YHURL YHPORT
echo "Starting $name" sleep 2
cd "$dir"
if [ -z "$user" ]; then
log_failure_msg "user \"$user\" does not exist"
else
sudo -u "$user" $cmd >> log_daemon_msg 2>> log_failure_msg 1 &
fi
status=$?
log_end_msg $status
echo $! > "$pid_file" if check_status -q; then
if ! is_running; then log_end_msg 0
log_failure_msg "Unable to start, see syslog" else
log_failure_msg "check syslog for diagnostics."
log_end_msg 1
exit 1 exit 1
fi fi
fi
;; ;;
stop) stop)
if is_running; then log_daemon_msg "Stopping $DESC" "$NAME"
echo -n "Stopping $name.." start-stop-daemon --stop --quiet --pidfile $MOVIMPID
kill `get_pid` log_end_msg $?
for i in {1..10} rm -f "$MOVIMPID"
do
if ! is_running; then
break
fi
echo -n "."
sleep 1
done
echo
if is_running; then
echo "Not stopped; may still be shutting down or shutdown may have failed"
exit 1
else
echo "Stopped"
if [ -f "$pid_file" ]; then
rm "$pid_file"
fi
fi
else
echo "Not running"
fi
;; ;;
restart) restart | force-reload)
test_config
$0 stop $0 stop
if is_running; then sleep 2
echo "Unable to stop, will not attempt to start" $0 start
if [ "$?" != "0" ]; then
exit 1 exit 1
fi fi
$0 start
;; ;;
status) status)
if is_running; then echo -n "Status of $DESC: "
echo "Running" check_status -v
else exit "$?"
echo "Stopped"
exit 1
fi
;; ;;
*) *)
echo "Usage: $0 {start|stop|restart|status}" echo "Usage: $0 {start|stop|restart|force-reload|status}"
exit 1 exit 1
;;
esac esac
exit 0 exit 0