G'day, trying to get an expect script that runs a telnet session to run on shutdown of a VM running in vmware player in a VNC session. It runs just fine when I run systemctl stop by hand, but when I do a shutdown -r now, it doesn't happen.
My service file :
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
Before=shutdown.target reboot.target halt.target
[Service]
Type=forking
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver %i"
PIDFile=/root/.vnc/%H%i.pid
ExecStop=/root/vmware/SCO/stopsco.pl
ExecStop=/usr/bin/sleep 10
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target
It's my understanding that the three ExecStop lines should get run, in order, and they do when I run systemctl stop vncserver@:1.service But when I shutdown the server, they don't get run - the sleep 10 would stop the VNC server going down for 10 seconds, which I should be able to see, but it doesn't, it just goes crunch and the VNC server stops. So the last line is being run, for sure, but the prior two do not seem to be, or if they are, they're not being waited for - the "stopsco" script takes about 60 seconds to run. Can anyone see what I'm missing? I'm new to systemd, this stuff worked fine with rc scripts :)
I've fussed around with the suggestion here : systemd to wait for command to complete before restart/shutdown or killing other processes and added
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
Before=shutdown.target reboot.target halt.target
but it still just slammed the VNC session shut, it certainly didn't wait for 10s when I ran shutdown -r, but again, it works perfectly when run by hand.
Update :
systemctl status vncserver@:1.service
▒ vncserver@:1.service - Remote desktop service (VNC)
Loaded: loaded (/etc/systemd/system/vncserver@:1.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2018-09-12 00:42:04 AEST; 9h ago
Process: 3867 ExecStop=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS)
Process: 3864 ExecStop=/usr/bin/sleep 10 (code=exited, status=0/SUCCESS)
Process: 3831 ExecStop=/root/vmware/SCO/stopsco.pl (code=exited, status=0/SUCCESS)
Process: 3968 ExecStart=/usr/sbin/runuser -l root -c /usr/bin/vncserver %i (code=exited, status=0/SUCCESS)
Process: 3963 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS)
Main PID: 4002 (Xvnc)
CGroup: /system.slice/system-vncserver.slice/vncserver@:1.service
▒ 4002 /usr/bin/Xvnc :1 -auth /root/.Xauthority -desktop tardis.li...
Sep 12 00:42:01 tardis.lilydaleairport.com.au systemd[1]: Starting Remote des...
Sep 12 00:42:04 tardis.lilydaleairport.com.au systemd[1]: Started Remote desk...
Hint: Some lines were ellipsized, use -l to show in full.
[root@tardis system]#
systemd is version
systemctl --version
systemd 219
+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 -SECCOMP +BLKID +ELFUTILS +KMOD +IDN