为python-twistd应用程序编写systemd单元文件和specfile



我给了一个任务,为python twistd应用程序编写systemd单元文件并创建它的rpm。该应用程序是开源的,你可以在这里找到它。

我已经把单位文件写成:

[Unit]
Description=ECManaged Agent for monitoring and deployment
[Service]
Type=simple
PIDFile=/opt/ecmanaged/ecagent/twistd.pid
#ExecStart=/usr/bin/twistd -y /opt/ecmanaged/ecagent/ecagentd.tac
ExecStart=
/bin/twistd 
--nodaemon 
--pidfile=/opt/ecmanaged/ecagent/twistd.pid 
--no_save 
--python=/opt/ecmanaged/ecagent/ecagentd.tac
WorkingDirectory=/opt/ecmanaged/ecagent
[Install]
WantedBy=multi-user.target

我已将rpmbuild规范文件写成:

%define name      ecmanaged-ecagent
%define ename     ecagentd
%define pname     ecmanaged
Name:           %{name}
Version:        2.1.2       
Release:        109%{?el#}
Summary:        ECManaged  Agent - Monitoring and deployment agent
Group:          Applications/System
License:        GPLv3+
URL:            www.ecmanaged.com
Source0:        ecmanaged-ecagent.tar.gz
BuildArch:      noarch
Requires:       python2
Requires:       python-twisted-core
Requires:       python-twisted-web
Requires:       python-protocols
Requires:       python-configobj
Requires:       python-twisted-words
Requires:       python-psutil
Requires:       libxml2-python
Requires:       python-simplejson
Requires:       rpm-python
Requires:       python-crypto
Requires:       python-httplib2
BuildRequires:      systemd
Provides:       ecmanaged-ecagent
%description
ECManaged  Agent - Monitoring and deployment agent
%prep
%setup -qn %{name}
%build

%install
rm -rf %{buildroot}
mkdir -p %{buildroot}/opt//ecmanaged/ecagent
mkdir -p %{buildroot}/etc
mkdir -p %{buildroot}/etc/rc.d/init.d
mkdir -p %{buildroot}/etc/cron.d
mkdir -p %{buildroot}%{_unitdir}/
rsync -av --exclude '*build*' %{_builddir}/%{name}/* %{buildroot}/opt/ecmanaged/ecagent/
install -m 750 %{_builddir}/%{name}/build/redhat/etc/init.d/ecagentd %{buildroot}/etc/rc.d/init.d
install -m 644 %{_builddir}/%{name}/build/redhat/etc/cron.d/ecmanaged-ecagent $RPM_BUILD_ROOT/etc/cron.d
cp %{_builddir}/%{name}/build/redhat/etc/systemd/system/ecagentd.service %{buildroot}%{_unitdir}/

rm -rf %{_builddir}/%{name}/build
%clean
#rm -rf %{_buildroot}%{name}
#rm -rf %{_source_path}%{name}
%post
systemctl daemon-reload
systemctl enable ecagentd.service
systemctl daemon-reload
systemctl start ecagentd.service >/dev/null 2>&1
%preun
systemctl stop ecagentd.service >/dev/null 2>&1
systemctl disable ecagentd.service
systemctl daemon-reload
%files
%defattr(-,root,root,-)
%attr(750,root,root) /etc/rc.d/init.d/ecagentd
%attr(750,root,root) /usr/lib/systemd/system/ecagentd.service
%attr(644,root,root) /etc/cron.d/ecmanaged-ecagent
%attr(755,root,root) /opt/ecmanaged/ecagent/
%attr(700,root,root) %config /opt/ecmanaged/ecagent/config
%attr(400,root,root) %config /opt/ecmanaged/ecagent/config/ecagent.init.cfg
%exclude /opt/ecmanaged/ecagent/plugins/*.pyc
%exclude /opt/ecmanaged/ecagent/plugins/*.pyo
%exclude /opt/ecmanaged/ecagent/examples/*.pyc
%exclude /opt/ecmanaged/ecagent/examples/*.pyo
%exclude /opt/ecmanaged/ecagent/ecagent/*.pyc
%exclude /opt/ecmanaged/ecagent/ecagent/*.pyo
%exclude /opt/ecmanaged/ecagent/ecagent/*.pyc
%exclude /opt/ecmanaged/ecagent/ecagent/*.pyo
%changelog

我知道这个应用程序不使用setuptools有点奇怪。

它们还有一个init.d脚本和一个使用它的cron作业。您可以使用链接找到它们。

移除它们安全吗?如果是,如何?

我做得好吗?我怎样才能让它变得更好?任何指示和建议都将不胜感激。

在服务文件中使用PIDFile没有意义,因为您使用的是简单的类型。

PIDFile只有在您的服务类型为分叉时才有用(如下所示):

[Service]
Type=forking

相关内容

  • 没有找到相关文章