简体   繁体   English

为python扭曲的应用程序编写systemd单位文件和specfile

[英]writing systemd unit file and specfile for a python twistd application

I have given a task to write the systemd unit file for a python twistd application and create rpm of it. 我给了一个任务,要为python扭曲的应用程序编写systemd单元文件,并为其创建rpm。 The application is open source and you can find it here . 该应用程序是开源的,您可以在这里找到它。

I have written the unit file as: 我将单位文件写为:

[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

I have written the rpmbuild specfile as: 我已经将rpmbuild spec文件编写为:

%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

I know its a bit weird that the application does not use setuptools. 我知道应用程序不使用setuptools有点奇怪。

They also have a init.d script and a cron job which uses it. 他们也有一个init.d脚本和一个使用它的cron作业 you can find them using the links. 您可以使用链接找到它们。

Are they safe to remove? 他们可以安全移除吗? if yes, how? 如果是,如何?

Am I doing it well? 我做得好吗? How can I make it better? 我怎样才能做得更好? any pointer and suggestion will be highly appreciated. 任何指针和建议将不胜感激。

There is no point of using PIDFile in your service file as you are using type as simple. 在服务文件中使用PIDFile是没有意义的,因为您使用的类型非常简单。

PIDFile is only useful when your service type is forking (as follows): PIDFile仅在您的服务类型为分叉时才有用(如下所示):

[Service]
Type=forking

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM