2015-02-24 53 views
1

我已經給了一個任務來爲python twistd應用程序編寫systemd單元文件並創建它的rpm。該應用程序是開源的,你可以找到它here爲python twistd應用程序編寫systemd單元文件和spec文件

自己編寫單元文件爲:

[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 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 

我知道它有點怪異的應用程序不使用setuptools的。

它們也有一個init.d script和一個使用它的cron job。你可以使用鏈接找到它們。

他們安全地刪除?如果是的話,怎麼樣?

我做得好嗎?我怎樣才能讓它變得更好?任何指針和建議將不勝感激。

回答

0

在您的服務文件中使用PIDFile毫無意義,因爲您使用的類型很簡單。

PIDFILE當你的業務類型爲分叉是唯一有用的(如下):

[Service] 
Type=forking 
相關問題