-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathorchestrator.spec
149 lines (119 loc) · 3.89 KB
/
orchestrator.spec
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
%define timestamp %(date +"%Y%m%d%H%M%S")
Name: iotp-orchestrator
Version: %{_version}
Release: %{_release}
Summary: IoT Platform Orchestrator
License: AGPLv3
Distribution: noarch
Vendor: Telefonica I+D
Group: Applications/System
Packager: Telefonica I+D
Requires: python
Requires(post): /sbin/chkconfig, /usr/sbin/useradd
Requires(preun): /sbin/chkconfig, /sbin/service
Requires(postun): /sbin/service
autoprov: no
autoreq: no
Prefix: /opt
BuildArch: noarch
%define _target_os Linux
%define python_lib /var/env-orchestrator/lib/python3.11/site-packages
%define __python /usr/bin/python3.11
%description
IoT Platform Orchestrator
# System folders
%define _srcdir $RPM_BUILD_ROOT
%define _service_name orchestrator
%define _install_dir %{python_lib}/iotp-orchestrator
%define _orchestrator_log_dir /var/log/orchestrator
%define _orchestrator_link_dir /opt/orchestrator
# RPM Building folder
%define _build_root_project %{buildroot}%{_install_dir}
%install
mkdir -p $RPM_BUILD_ROOT/%{python_lib}
cp -a %{_root}/src/ $RPM_BUILD_ROOT/%{python_lib}/iotp-orchestrator
find $RPM_BUILD_ROOT/%{python_lib}/iotp-orchestrator -name "*.pyc" -delete
mkdir -p $RPM_BUILD_ROOT/etc/init.d
cp -a %{_root}/bin/orchestrator-daemon.sh $RPM_BUILD_ROOT/etc/init.d/orchestrator
mkdir -p $RPM_BUILD_ROOT/etc/default
cp -a %{_root}/bin/orchestrator-daemon $RPM_BUILD_ROOT/etc/default/orchestrator-daemon
%pre
echo "[INFO] Creating %{_project_user} user"
grep ^%{_project_user}: /etc/passwd
RET_VAL=$?
if [ "$RET_VAL" != "0" ]
then
mkdir -p %{_install_dir}
/usr/sbin/groupadd -f orchestrator
/usr/sbin/useradd -s "/bin/bash" -g orchestrator %{_project_user}
RET_VAL=$?
if [ "$RET_VAL" != "0" ]
then
echo "[ERROR] Unable create %{_project_user} user"
exit $RET_VAL
fi
else
ls %{_install_dir}/settings/dev.py
RET_VAL=$?
if [ "$RET_VAL" == "0" ]
then
cp %{_install_dir}/settings/dev.py /tmp
fi
fi
%post
echo "[INFO] Configuring application"
echo "[INFO] Creating log directory"
mkdir -p %{_orchestrator_log_dir}
chown -R %{_project_user}:%{_project_user} %{_orchestrator_log_dir}
chmod g+s %{_orchestrator_log_dir}
setfacl -d -m g::rwx %{_orchestrator_log_dir}
setfacl -d -m o::rx %{_orchestrator_log_dir}
echo "[INFO] Configuring application service"
cd /etc/init.d
chkconfig --add %{_service_name}
ls /tmp/dev.py
RET_VAL=$?
if [ "$RET_VAL" == "0" ]
then
mv /tmp/dev.py %{_install_dir}/settings/dev.py
fi
echo "[INFO] Link to /opt"
# Remove bad created links
rm -f %{_install_dir}/iotp-orchestrator
rm -f %{_orchestrator_link_dir}/orchestrator/commands/commands
# Create good links
ln -sfn %{_install_dir} %{_orchestrator_link_dir}
ln -sfn %{_orchestrator_link_dir}/orchestrator/commands %{_orchestrator_link_dir}/bin
echo "[INFO] Fix version"
sed -i -e 's/ORC_version/%{_version}/g' %{_install_dir}/settings/common.py
sed -i -e 's/\${project.version}/%{_version}/g' %{_install_dir}/orchestrator/core/banner.txt
echo "[INFO] restart service %{_service_name}"
service %{_service_name} restart &> /dev/null
echo "Done"
%preun
echo "[INFO] stoping service %{_service_name}"
service %{_service_name} stop &> /dev/null
if [ $1 == 0 ]
then
echo "[INFO] Removing application log files"
# Log
[ -d %{_orchestrator_log_dir} ] && rm -rf %{_orchestrator_log_dir}
echo "[INFO] Removing application files"
# Installed files
[ -d %{_install_dir} ] && rm -rf %{_install_dir}
echo "[INFO] Removing application user"
userdel -fr %{_project_user}
echo "[INFO] Removing application service"
chkconfig --del %{_service_name}
rm -Rf /etc/init.d/%{_service_name}
echo "[INFO] Removing orchestrator link"
rm -f %{_orchestrator_link_dir}
echo "Done"
fi
%files
%defattr(755,%{_project_user},%{_project_user},755)
%attr(755,root,root) /etc/init.d/%{_service_name}
%attr(644,root,root) /etc/default/%{_service_name}-daemon
%config /etc/init.d/%{_service_name}
%config /etc/default/%{_service_name}-daemon
%{python_lib}/iotp-orchestrator