我已经完成了为python twistd应用程序编写systemd单元文件并创建它的rpm的任务。该应用程序是开源的,您可以找到它here。
我已将单位文件写为:
[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 specfile编写为:
%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 script和cron job使用它。你可以使用链接找到它们。
它们可以安全移除吗?如果有,怎么样?
我做得好吗?我怎样才能让它变得更好?任何指针和建议都将受到高度赞赏。
答案 0 :(得分:0)
在您的服务文件中使用PIDFile是没有意义的,因为您使用的是简单类型。
PIDFile仅在您的服务类型分叉时有用(如下所示):
[Service]
Type=forking