systemd: wait for shutdown-service to complete

Reindl Harald h.reindl at thelounge.net
Tue Dec 13 22:16:58 UTC 2011


hi

i am trying to suspend / start my VMware-Workstation machines automatically
below my systemd-unit and the two shell-scripts
start works like a charme (yes i use a seperated user for VM's)

shutdown works on a machine with one small VM
on my homeserver i see that it is executed (script output)
but systemd does not wait until all machines are compleltly suspended
seeing boot-messages and partially fscheck in the guests

has anybody an idea how i can make sure that systemd waits to finish
"/scripts/vmware/vm-suspend-all.sh" before shutdown the next process
(in this case vmware.service)  and finally the system?

yes, the suspend script called directly works fine, adn yes it would be
possible to call the script manually before reboot/shtdown but i like
systems which works perfectly at boot/shutdown without manual interaction

[root at srv-rhsoft:~]$ cat /etc/systemd/system/vmware-default.service
[Unit]
Description=VMware-Default-Machines
After=vmware.service
[Service]
Type=oneshot
ExecStart=/bin/su -c "/scripts/vmware/vm-default-start.sh" vmware
ExecStop=/scripts/vmware/vm-suspend-all.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target


[root at srv-rhsoft:~]$ cat /scripts/vmware/vm-default-start.sh
#!/bin/bash
if [ "$HOSTNAME" == "srv-rhsoft.rhsoft.net" ]; then
 /usr/bin/vmrun -T ws start '/mnt/data/fileserver/vmware/arrakis/arrakis.vmx' nogui
 /usr/bin/vmrun -T ws start '/mnt/data/fileserver/vmware/testserver/config.vmx' nogui
 /usr/bin/vmrun -T ws start '/mnt/data/fileserver/vmware/Buildserver32/config.vmx' nogui
 /usr/bin/vmrun -T ws start '/mnt/data/fileserver/vmware/Buildserver64/config.vmx' nogui
 /usr/bin/vmrun -T ws start '/mnt/data/fileserver/vmware/centos/centos.vmx' nogui
fi
if [ "$HOSTNAME" == "rh.thelounge.net" ]; then
 /usr/bin/vmrun -T ws start '/mnt/data/fileserver/vmware/backup-flow/config.vmx' nogui
fi


[root at srv-rhsoft:~]$ cat /scripts/vmware/vm-suspend-all.sh
#!/bin/bash
if [ -x /usr/bin/vmrun ] ; then
 for i in `pidof vmware-vmx` ; do
  VMX_PATH=`ps -p $i -f | sed -ne '/vmware/s/.* \(\/.*\.vmx\)/\1/p'`
  MY_DATE=$(/bin/date +%d-%m-%Y)
  MY_TIME=$(/bin/date +%H:%M:%S)
  echo "$MY_DATE $MY_TIME  SUSPEND: $VMX_PATH"
  /usr/bin/logger -t vmware "SUSPEND: $VMX_PATH"
  /usr/bin/vmrun suspend `ps -p $i -f | sed -ne '/vmware/s/.* \(\/.*\.vmx\)/\1/p'` 2> /dev/null
  MY_DATE=$(/bin/date +%d-%m-%Y)
  MY_TIME=$(/bin/date +%H:%M:%S)
  echo "$MY_DATE $MY_TIME  SUSPENDED: $VMX_PATH"
  /usr/bin/logger -t vmware "SUSPENDED: $VMX_PATH"
 done
fi

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 262 bytes
Desc: OpenPGP digital signature
URL: <http://lists.fedoraproject.org/pipermail/users/attachments/20111213/0ea2e4fa/attachment.sig>


More information about the users mailing list