forked from ventor-tech/odoo-install-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
initd.sh
129 lines (116 loc) · 3.12 KB
/
initd.sh
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
127
128
129
#!/bin/bash
#--------------------------------------------------
# ----- Creating debian installation file with all neccessary configs
#--------------------------------------------------
OE_AUTO_SCRIPTS_DIR=$OE_HOME/odoo_install_$OE_VERSION
rm -R $OE_AUTO_SCRIPTS_DIR
mkdir $OE_AUTO_SCRIPTS_DIR
# ---------------------------
# Build Debian package
# ---------------------------
mkdir -p $OE_AUTO_SCRIPTS_DIR/DEBIAN
cat <<EOF > $OE_AUTO_SCRIPTS_DIR/DEBIAN/control
Package: $OE_INIT
Version: $OE_PORT
Architecture: all
Maintainer: Odoo S.A. <[email protected]>
Section: net
Priority: optional
Homepage: http://www.odoo.com/
Description: Odoo description
EOF
cat <<EOF > $OE_AUTO_SCRIPTS_DIR/DEBIAN/postinst
#!/bin/sh
set -e
ODOO_CONFIGURATION_FILE=$OE_CONFIG
ODOO_GROUP=$OE_USER
ODOO_DATA_DIR=$OE_HOME
ODOO_LOG_DIR=$OE_LOG_PATH
ODOO_USER=$OE_USER
# Configuration file
chown \$ODOO_USER:\$ODOO_GROUP \$ODOO_CONFIGURATION_FILE
chmod 0640 \$ODOO_CONFIGURATION_FILE
# Log
chown \$ODOO_USER:\$ODOO_GROUP \$ODOO_LOG_DIR
chmod 0750 \$ODOO_LOG_DIR
# Data dir
chown \$ODOO_USER:\$ODOO_GROUP \$ODOO_DATA_DIR
# Different scripts
chown root:root /etc/init.d/$OE_INIT
chmod 755 /etc/init.d/$OE_INIT
update-rc.d $OE_INIT defaults
EOF
chmod 755 $OE_AUTO_SCRIPTS_DIR/DEBIAN/postinst
#--------------------------------------------------
# Adding init.d script
#--------------------------------------------------
echo -e "* Create init file"
cat <<EOF > $OE_INIT
#!/bin/sh
### BEGIN INIT INFO
# Provides: $OE_INIT
# Required-Start: \$remote_fs \$syslog
# Required-Stop: \$remote_fs \$syslog
# Should-Start: \$network
# Should-Stop: \$network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start odoo daemon at boot time
# Description: Enable service provided by daemon.
# X-Interactive: true
### END INIT INFO
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
VIRTENV=$OE_INSTALL_DIR/env/bin/python
DAEMON=$OE_REPO/$OE_BIN
NAME=$OE_INIT
DESC=$OE_INIT
# Specify the user name (Default: odoo).
USER=$OE_USER
CONFIGFILE="${OE_CONFIG}"
# pidfile
PIDFILE=/var/run/\${NAME}.pid
# Additional options that are passed to the Daemon.
DAEMON_OPTS="-c \$CONFIGFILE"
[ -x \$DAEMON ] || exit 0
[ -f \$CONFIGFILE ] || exit 0
checkpid() {
[ -f \$PIDFILE ] || return 1
pid=\`cat \$PIDFILE\`
[ -d /proc/\$pid ] && return 0
return 1
}
case "\${1}" in
start)
echo -n "Starting \${DESC}: "
start-stop-daemon --start --quiet --pidfile \$PIDFILE \
--chuid \$USER --background --make-pidfile \
--exec \$VIRTENV \$DAEMON -- \$DAEMON_OPTS
echo "\${NAME}."
;;
stop)
echo -n "Stopping \${DESC}: "
start-stop-daemon --stop --quiet --pidfile \$PIDFILE \
--oknodo
echo "\${NAME}."
;;
restart|force-reload)
echo -n "Restarting \${DESC}: "
start-stop-daemon --stop --quiet --pidfile \$PIDFILE \
--oknodo
sleep 10
start-stop-daemon --start --quiet --pidfile \$PIDFILE \
--chuid \$USER --background --make-pidfile \
--exec \$VIRTENV \$DAEMON -- \$DAEMON_OPTS
echo "\${NAME}."
;;
*)
N=/etc/init.d/\$NAME
echo "Usage: \$NAME {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
EOF
echo -e "* Security Init File"
mkdir -p $OE_AUTO_SCRIPTS_DIR/etc/init.d/
mv $OE_INIT $OE_AUTO_SCRIPTS_DIR/etc/init.d/$OE_INIT