-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathopencpu-server.postinst
112 lines (90 loc) · 3.46 KB
/
opencpu-server.postinst
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
#!/bin/sh
# TODO: do not hardcode 'www-data'
set -e
case "$1" in
configure)
:
# Adding OpenCPU User.
echo "Adding opencpu user account"
# On Debian we need to generate locales manually
localedef -i en_US -f UTF-8 en_US.UTF-8 || true
# The --system flags disables interactive login. We want to use that for rstudio now.
# The user will still be disabled for login until it gets a passwd
useradd opencpu -g www-data -N -m -d/home/opencpu -c"OpenCPU Server" || true
# useradd opencpu --system -g www-data -d/tmp -c"OpenCPU Server" || true
# Legacy fixes for OpenCPU 1.0 installations
usermod -g www-data opencpu || true
mkdir -p /home/opencpu || true
chown opencpu /home/opencpu || true
# Create opencpu site-library
mkdir -p /usr/local/lib/opencpu/site-library
chown opencpu /usr/local/lib/opencpu/site-library
echo "R_LIBS_USER='/usr/local/lib/opencpu/site-library'" > /home/opencpu/.Renviron
echo "Creating log files..."
touch /var/log/opencpu/access.log
touch /var/log/opencpu/error.log
# Note: maybe not needed for each update?
echo "Taking ownership of system directories..."
chown -f opencpu /var/log/opencpu/*
chgrp -f www-data /var/log/opencpu/*
# Commented out: these should only be writable by apt/root?
#chown -Rf opencpu /etc/opencpu
#chgrp -Rf www-data /etc/opencpu
#chown -Rf opencpu /usr/lib/opencpu
#chgrp -Rf www-data /usr/lib/opencpu
# Set writable for both apache as well as admin user 'opencpu'
mkdir -p /usr/local/lib/opencpu/apps
chown -f opencpu /usr/local/lib/opencpu/apps
chgrp -f www-data /usr/local/lib/opencpu/apps
chmod g+ws /usr/local/lib/opencpu/apps
echo "Making scripts executable..."
chmod +x /usr/lib/opencpu/scripts/*.sh
#In Apache 2.4 we need to make sure mpm_prefork is enabled
if command -v a2query >/dev/null 2>&1; then
if a2query -q -m mpm_event; then
a2dismod mpm_event || true
fi
if a2query -q -m mpm_worker; then
a2dismod mpm_worker || true
fi
if a2query -q -m mpm_itk; then
a2dismod mpm_itk || true
fi
a2enmod mpm_prefork || true
fi
#setup rstudio proxy
a2enmod proxy 2>&1 >/dev/null | grep -i 'error' || true
a2enmod proxy_http 2>&1 >/dev/null | grep -i 'error' || true
a2ensite rstudio 2>&1 >/dev/null | grep -i 'error' || true
#try to enable ssl site
a2enmod ssl 2>&1 >/dev/null | grep -i 'error' || true
a2ensite default-ssl 2>&1 >/dev/null | grep -i 'error' || true
#enable opencpu site
echo "Enabling opencpu in apache..."
a2ensite opencpu 2>&1 >/dev/null | grep -i 'error' || true
#reload apparmor
echo "Reloading apparmor..."
service apparmor reload 2>&1 >/dev/null | grep -i 'error' || true
echo "Restarting apache..."
service apache2 restart 2>&1 >/dev/null | grep -i 'error' || true
#done
echo "Installation done!"
#remove opencpu 1.0 remenants
rm -f /etc/cron.d/opencpu-* || true
systemctl disable opencpu 2>/dev/null || true
update-rc.d -f opencpu remove || true
#enable ocpucleanup.timer in systemd
if [ -e "/bin/systemctl" ]; then
systemctl daemon-reload || true
systemctl start cleanocpu.timer || true
systemctl restart systemd-tmpfiles-clean || true
fi
;;
abort-upgrade | abort-remove | abort-deconfigure)
:
;;
*) echo "$0: didn't understand being called with \`$1'" 1>&2
exit 1;;
esac
#DEBHELPER#
exit 0