I have given a task to write the systemd unit file for a python twistd application and create rpm of it. 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:
%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.
They also have a init.d script and a cron job which uses it. 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 is only useful when your service type is forking (as follows):
[Service]
Type=forking