forked from zammad/zammad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit-script-normal-user-rvm-fedora
executable file
·127 lines (104 loc) · 3.15 KB
/
init-script-normal-user-rvm-fedora
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
#
# init script build as PoC for
# 1) normal user (non root)
# 2) rvm support
# 3) pid files in user space
# 4) fedora os
# source function library
. /etc/rc.d/init.d/functions
# Get network config
. /etc/sysconfig/network
[ "${NETWORKING}" = "no" ] && exit 0
DAEMON_HOME=/home/kraftvoll/zammad/
#RAILS_ENV=production
RAILS_ENV=test
NAME=zammad
APP_PORT=3000
WS_PORT=6042
ZAMMAD_CONFIG=/etc/sysconfig/zammad
# Read config
[ -f "$ZAMMAD_CONFIG" ] && . "$ZAMMAD_CONFIG"
# Load RVM into a shell session *as a function*
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
# First try to load from a user install
source "$HOME/.rvm/scripts/rvm"
elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
# Then try to load from a root install
source "/usr/local/rvm/scripts/rvm"
else
printf "ERROR: An RVM installation was not found.\n"
exit 1
fi
rvm use ruby-2.0.0
RUBY=$(which ruby)
RAILS=$(which rails)
BUNDLE=$(which bundle)
APP_PIDFILE=$DAEMON_HOME/tmp/pids/puma.pid
WS_PIDFILE=$DAEMON_HOME/tmp/pids/websocket.pid
SCHEDULER_PIDFILE=$DAEMON_HOME/tmp/pids/scheduler_runner.pid
start() {
cd $DAEMON_HOME
# precompile assets
if [ "$RAILS_ENV" = "production" ]; then
echo -n $"Precompile assets for ${NAME}/${RAILS_ENV}"
$BUNDLE exec rake assets:precompile &> /dev/null && echo_success || echo_failure
echo
fi
# start web server
echo -n $"Starting ${NAME}/${RAILS_ENV} application server on port: ${APP_PORT}"
# $RAILS server -d -p $APP_PORT --pid $APP_PIDFILE &> /dev/null
# thin start --threaded -d -p $APP_PORT --pid $APP_PIDFILE
puma --pidfile $APP_PIDFILE -d -p $APP_PORT -e $RAILS_ENV &> /dev/null
sleep 2
status -p $APP_PIDFILE &> /dev/null && echo_success || echo_failure
echo
# start websocket server
echo -n $"Starting ${NAME}/${RAILS_ENV} web socket server on port: ${WS_PORT}"
script/websocket-server.rb start -d -p $WS_PORT -i $WS_PIDFILE &> /dev/null &
sleep 2
status -p $WS_PIDFILE &> /dev/null && echo_success || echo_failure
echo
# start scheduler worker
echo -n $"Starting ${NAME}/${RAILS_ENV} scheduler worker"
script/scheduler.rb start &> /dev/null && echo_success || echo_failure
echo
}
stop() {
# stop scheduler worker
echo -n $"Shutting down ${NAME}/${RAILS_ENV} scheduler worker"
script/scheduler.rb stop &> /dev/null && echo_success || echo_failure
echo
# stop websocket server
echo -n $"Shutting down ${NAME}/${RAILS_ENV} web socket server on port: ${WS_PORT}"
if test -e $WS_PIDFILE; then
killproc -p $WS_PIDFILE
fi
echo
# stop web server
echo -n $"Shutting down ${NAME}/${RAILS_ENV} application server on port: ${APP_PORT}"
if test -e $APP_PIDFILE; then
killproc -p $APP_PIDFILE
fi
echo
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status -p $APP_PIDFILE "${NAME} ${RAILS_ENV} - application server"
status -p $WS_PIDFILE "${NAME} ${RAILS_ENV} - web socket server"
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|status}" >&2
exit 3
;;
esac