dom0/init: implement systemd unit files

They cover standard init.d scripts when system have systemd, so can be placed
both in one package.
This commit is contained in:
Marek Marczykowski 2013-01-27 00:04:40 +01:00
parent fb36ce40d6
commit b8ccfd6e2e
9 changed files with 173 additions and 2 deletions

24
dom0/aux-tools/startup-dvm.sh Executable file
View File

@ -0,0 +1,24 @@
#!/bin/sh
# Setup DispVM things at Qubes system startup
printf "\x00\x00\x00\x00" > /var/run/qubes/dispVM_seq
chown root:qubes /var/run/qubes/dispVM_seq
chmod 660 /var/run/qubes/dispVM_seq
DEFAULT=/var/lib/qubes/dvmdata/default_savefile
DEFAULT_CONFIG=/var/lib/qubes/dvmdata/default_dvm.conf
# setup DispVM files only when they exists
if [ -r $DEFAULT ]; then
ln -s $DEFAULT_CONFIG /var/run/qubes/current_dvm.conf
if [ -f /var/lib/qubes/dvmdata/dont_use_shm ] ; then
ln -s $DEFAULT /var/run/qubes/current_savefile
else
mkdir -m 770 /dev/shm/qubes
chown root.qubes /dev/shm/qubes
cp -a $(readlink $DEFAULT) /dev/shm/qubes/current_savefile
chown root.qubes /dev/shm/qubes/current_savefile
chmod 660 /dev/shm/qubes/current_savefile
ln -s /dev/shm/qubes/current_savefile /var/run/qubes/current_savefile
fi
fi

21
dom0/aux-tools/startup-misc.sh Executable file
View File

@ -0,0 +1,21 @@
#!/bin/sh
# Misc dom0 startup setup
/usr/lib/qubes/fix_dir_perms.sh
xenstore-write /local/domain/0/name dom0
DOM0_MAXMEM=`/usr/sbin/xl info | grep total_memory | awk '{ print $3 }'`
xenstore-write /local/domain/0/memory/static-max $[ $DOM0_MAXMEM * 1024 ]
xl sched-credit -d 0 -w 512
cp /var/lib/qubes/qubes.xml /var/lib/qubes/backup/qubes-$(date +%F-%T).xml
/usr/lib/qubes/cleanup_dispvms
# Hide mounted devices from qubes-block list (at first udev run, only / is mounted)
for dev in `xenstore-list /local/domain/0/qubes-block-devices 2> /dev/null`; do
( eval `udevadm info -q property -n $dev|sed -e 's/\([^=]*\)=\(.*\)/export \1="\2"/'`;
/usr/lib/qubes/block_add_change > /dev/null
)
done

View File

@ -0,0 +1,10 @@
[Unit]
Description=Qubes block device cleaner (xen front/back)
After=qubes-core.service
[Service]
ExecStart=/usr/lib/qubes/block_cleaner_daemon.py
StandardOutput=syslog
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,15 @@
[Unit]
Description=Qubes Dom0 startup setup
# Cover legacy init.d script
[Service]
Type=oneshot
StandardOuptut=syslog
RemainAfterExit=yes
ExecStart=/usr/lib/qubes/startup-misc.sh
ExecStop=/usr/bin/qvm-shutdown -q --all --wait
[Install]
WantedBy=multi-user.target
Also=qubes-block-cleaner.service qubes-meminfo-writer.service qubes-qmemman.service
Alias=qubes_core.service

View File

@ -0,0 +1,12 @@
[Unit]
Description=Qubes DispVM startup setup
After=qubes-core.service
[Service]
Type=oneshot
ExecStart=/usr/lib/qubes/startup-dvm.sh
[Install]
WantedBy=multi-user.target
# Cover legacy init.d script
Alias=qubes_setupdvm.service

View File

@ -0,0 +1,11 @@
[Unit]
Description=Qubes memory information reporter
After=qubes-core.service
[Service]
Type=simple
ExecStart=/usr/lib/qubes/meminfo-writer 30000 100000
StandardOutput=syslog
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,16 @@
[Unit]
Description=Qubes NetVM startup
After=qubes-core.service
[Service]
Type=oneshot
Group=qubes
Environment=DISPLAY=:0
RemainAfterExit=yes
KillMode=none
ExecStart=/bin/sh -c 'NETVM=`qubes-prefs --get default-netvm`; [ -n "$NETVM" ] && qvm-start -q --no-guid $NETVM'
[Install]
WantedBy=multi-user.target
# Cover legacy init.d script
Alias=qubes_netvm.service

View File

@ -0,0 +1,11 @@
[Unit]
Description=Qubes memory management daemon
After=qubes-core.service
[Service]
Type=forking
ExecStart=/usr/lib/qubes/qmemman_daemon.py
StandardOutput=syslog
[Install]
WantedBy=multi-user.target

View File

@ -27,6 +27,12 @@
%{!?version: %define version %(cat version_dom0)}
%if %{fedora} >= 15
%{!?use_systemd: %define use_systemd 1}
%else
%{!?use_systemd: %define use_systemd 0}
%endif
%define _dracutmoddir /usr/lib/dracut/modules.d
%if %{fedora} < 17
%define _dracutmoddir /usr/share/dracut/modules.d
@ -42,6 +48,12 @@ Vendor: Invisible Things Lab
License: GPL
URL: http://www.qubes-os.org
BuildRequires: xen-devel
%if %{use_systemd}
BuildRequires: systemd-units
Requires(post): systemd-units
Requires(preun): systemd-units
Requires(postun): systemd-units
%endif
Requires: python, xen-runtime, pciutils, python-inotify, python-daemon, kernel-qubes-dom0
Requires: qubes-core-libs
Requires: python-lxml
@ -76,10 +88,21 @@ done
cd dom0
%if !%{use_systemd}
mkdir -p $RPM_BUILD_ROOT/etc/init.d
cp init.d/qubes_core $RPM_BUILD_ROOT/etc/init.d/
cp init.d/qubes_netvm $RPM_BUILD_ROOT/etc/init.d/
cp init.d/qubes_setupdvm $RPM_BUILD_ROOT/etc/init.d/
%else
mkdir -p $RPM_BUILD_ROOT/usr/lib/systemd/system
cp systemd/qubes-block-cleaner.service $RPM_BUILD_ROOT%{_unitdir}
cp systemd/qubes-core.service $RPM_BUILD_ROOT%{_unitdir}
cp systemd/qubes-dispvm.service $RPM_BUILD_ROOT%{_unitdir}
cp systemd/qubes-meminfo-writer.service $RPM_BUILD_ROOT%{_unitdir}
cp systemd/qubes-netvm.service $RPM_BUILD_ROOT%{_unitdir}
cp systemd/qubes-qmemman.service $RPM_BUILD_ROOT%{_unitdir}
%endif
mkdir -p $RPM_BUILD_ROOT/usr/bin/
cp qvm-tools/qvm-* $RPM_BUILD_ROOT/usr/bin
@ -119,6 +142,8 @@ cp aux-tools/convert_dirtemplate2vm.sh $RPM_BUILD_ROOT/usr/lib/qubes
cp aux-tools/create_apps_for_appvm.sh $RPM_BUILD_ROOT/usr/lib/qubes
cp aux-tools/remove_appvm_appmenus.sh $RPM_BUILD_ROOT/usr/lib/qubes
cp aux-tools/cleanup_dispvms $RPM_BUILD_ROOT/usr/lib/qubes
cp aux-tools/startup-dvm.sh $RPM_BUILD_ROOT/usr/lib/qubes
cp aux-tools/startup-misc.sh $RPM_BUILD_ROOT/usr/lib/qubes
cp qmemman/server.py $RPM_BUILD_ROOT/usr/lib/qubes/qmemman_daemon.py
cp ../misc/meminfo-writer $RPM_BUILD_ROOT/usr/lib/qubes/
cp ../qrexec/qrexec_daemon $RPM_BUILD_ROOT/usr/lib/qubes/
@ -250,6 +275,18 @@ sed '/^\s*XENCONSOLED_LOG_\(HYPERVISOR\|GUESTS\)\s*=.*/d' -i /etc/sysconfig/xenc
echo XENCONSOLED_LOG_HYPERVISOR=yes >> /etc/sysconfig/xenconsoled
echo XENCONSOLED_LOG_GUESTS=yes >> /etc/sysconfig/xenconsoled
%if %{use_systemd}
systemctl --no-reload enable qubes-core.service >/dev/null 2>&1
systemctl --no-reload enable qubes-netvm.service >/dev/null 2>&1
systemctl --no-reload enable qubes-setupdvm.service >/dev/null 2>&1
# Conflicts with libxl stack, so disable it
systemctl --no-reload disable xend.service >/dev/null 2>&1
systemctl demon-reload >/dev/null 2>&1 || :
%else
chkconfig --add qubes_core || echo "WARNING: Cannot add service qubes_core!"
chkconfig --add qubes_netvm || echo "WARNING: Cannot add service qubes_netvm!"
chkconfig --add qubes_setupdvm || echo "WARNING: Cannot add service qubes_setupdvm!"
@ -262,6 +299,8 @@ chkconfig --level 5 qubes_setupdvm on || echo "WARNING: Cannot enable service qu
service xend stop
chkconfig --level 5 xend off
%endif
HAD_SYSCONFIG_NETWORK=yes
if ! [ -e /etc/sysconfig/network ]; then
HAD_SYSCONFIG_NETWORK=no
@ -326,8 +365,8 @@ mv -f /lib/udev/rules.d/69-xorg-vmmouse.rules /var/lib/qubes/removed-udev-script
%preun
if [ "$1" = 0 ] ; then
# no more packages left
/etc/init.d/qubes_netvm stop
/etc/init.d/qubes_core stop
service qubes_netvm stop
service qubes_core stop
for i in /usr/share/qubes/icons/*.png ; do
xdg-icon-resource uninstall --novendor --size 48 $i
@ -347,9 +386,11 @@ fi
%files
%defattr(-,root,root,-)
%if !%{use_systemd}
/etc/init.d/qubes_core
/etc/init.d/qubes_netvm
/etc/init.d/qubes_setupdvm
%endif
%config(noreplace) %attr(0664,root,qubes) %{_sysconfdir}/qubes/qmemman.conf
/usr/bin/qvm-*
/usr/bin/qubes-*
@ -390,7 +431,17 @@ fi
/usr/lib/qubes/xl-qvm-usb-attach.py*
/usr/lib/qubes/xl-qvm-usb-detach.py*
/usr/lib/qubes/fix_dir_perms.sh
/usr/lib/qubes/startup-dvm.sh
/usr/lib/qubes/startup-misc.sh
%attr(4750,root,qubes) /usr/lib/qubes/qfile-dom0-unpacker
%if %{use_systemd}
%{_unitdir}/qubes-block-cleaner.service
%{_unitdir}/qubes-core.service
%{_unitdir}/qubes-dispvm.service
%{_unitdir}/qubes-meminfo-writer.service
%{_unitdir}/qubes-netvm.service
%{_unitdir}/qubes-qmemman.service
%endif
%attr(0770,root,qubes) %dir /var/lib/qubes
%attr(0770,root,qubes) %dir /var/lib/qubes/vm-templates
%attr(0770,root,qubes) %dir /var/lib/qubes/appvms