Skip to content

Commit

Permalink
F #865: Add oneshowback compute timer
Browse files Browse the repository at this point in the history
Signed-off-by: Petr Ospalý <[email protected]>
  • Loading branch information
Petr Ospalý committed May 18, 2020
1 parent ec252e2 commit b84849d
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 6 deletions.
36 changes: 32 additions & 4 deletions share/hooks/raft/vip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,29 @@ leader)
sudo -n systemctl start opennebula-gate
fi

if systemctl is-enabled opennebula-hem >/dev/null 2>&1; then
sudo -n systemctl start opennebula-hem
fi
# opennebula.service wants opennebula-hem.service
case "$(LANG=C systemctl is-enabled opennebula-hem 2>&1)" in
masked)
# service was explicitly masked: we will not start it
:
;;
*)
# this is implicit dependency of the opennebula.service...
sudo -n systemctl start opennebula-hem
;;
esac

# opennebula.service wants opennebula-showback.timer
case "$(LANG=C systemctl is-enabled opennebula-showback.timer 2>&1)" in
masked)
# service was explicitly masked: we will not start it
:
;;
*)
# this is implicit dependency of the opennebula.service...
sudo -n systemctl start opennebula-showback.timer
;;
esac
else
if [ -e /usr/lib/one/oneflow/oneflow-server.rb ]; then
sudo -n service opennebula-flow start
Expand All @@ -58,6 +78,7 @@ leader)
if [ -e /usr/lib/one/onehem/onehem-server.rb ]; then
sudo -n service opennebula-hem start
fi
# TODO: showback timer will not work on non-systemd system - crontab?
fi
;;

Expand All @@ -79,11 +100,17 @@ follower)
sudo -n systemctl stop opennebula-gate
fi

if systemctl is-enabled opennebula-hem >/dev/null 2>&1 ||
if systemctl is-enabled opennebula-hem >/dev/null 2>&1 ||
systemctl is-active opennebula-hem >/dev/null 2>&1;
then
sudo -n systemctl stop opennebula-hem
fi

if systemctl is-enabled opennebula-showback.timer >/dev/null 2>&1 ||
systemctl is-active opennebula-showback.timer >/dev/null 2>&1;
then
sudo -n systemctl stop opennebula-showback.timer
fi
else
if [ -e /usr/lib/one/oneflow/oneflow-server.rb ]; then
sudo -n service opennebula-flow stop
Expand All @@ -96,6 +123,7 @@ follower)
if [ -e /usr/lib/one/onehem/onehem-server.rb ]; then
sudo -n service opennebula-hem stop
fi
# TODO: showback timer will not work on non-systemd system - crontab?
fi
;;

Expand Down
8 changes: 8 additions & 0 deletions share/pkgs/services/systemd/opennebula-showback.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Unit]
Description=OpenNebula's periodic showback calculation
[Service]
Group=oneadmin
User=oneadmin
Type=oneshot
ExecStart=/usr/bin/oneshowback calculate
11 changes: 11 additions & 0 deletions share/pkgs/services/systemd/opennebula-showback.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=OpenNebula's periodic showback calculation
After=remote-fs.target

[Timer]
OnCalendar=daily
AccuracySec=1h
Persistent=true

[Install]
WantedBy=default.target
1 change: 1 addition & 0 deletions share/pkgs/services/systemd/opennebula.service
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ After=opennebula-ssh-agent.service
Wants=opennebula-scheduler.service opennebula-hem.service
Wants=opennebula-ssh-agent.service
Wants=opennebula-ssh-socks-cleaner.timer
Wants=opennebula-showback.timer

[Service]
Type=notify
Expand Down
2 changes: 1 addition & 1 deletion share/pkgs/sudoers/centos/opennebula
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Defaults:oneadmin secure_path = /sbin:/bin:/usr/sbin:/usr/bin

Cmnd_Alias ONE_CEPH = /usr/bin/rbd
Cmnd_Alias ONE_FIRECRACKER = /usr/bin/jailer, /usr/bin/mount, /usr/sbin/one-clean-firecracker-domain
Cmnd_Alias ONE_HA = /usr/bin/systemctl start opennebula-flow, /usr/bin/systemctl stop opennebula-flow, /usr/bin/systemctl start opennebula-gate, /usr/bin/systemctl stop opennebula-gate, /usr/bin/systemctl start opennebula-hem, /usr/bin/systemctl stop opennebula-hem, /usr/sbin/service opennebula-flow start, /usr/sbin/service opennebula-flow stop, /usr/sbin/service opennebula-gate start, /usr/sbin/service opennebula-gate stop, /usr/sbin/service opennebula-hem start, /usr/sbin/service opennebula-hem stop, /usr/sbin/arping, /usr/sbin/ip address *
Cmnd_Alias ONE_HA = /usr/bin/systemctl start opennebula-flow, /usr/bin/systemctl stop opennebula-flow, /usr/bin/systemctl start opennebula-gate, /usr/bin/systemctl stop opennebula-gate, /usr/bin/systemctl start opennebula-hem, /usr/bin/systemctl stop opennebula-hem, /usr/bin/systemctl start opennebula-showback.timer, /usr/bin/systemctl stop opennebula-showback.timer, /usr/sbin/service opennebula-flow start, /usr/sbin/service opennebula-flow stop, /usr/sbin/service opennebula-gate start, /usr/sbin/service opennebula-gate stop, /usr/sbin/service opennebula-hem start, /usr/sbin/service opennebula-hem stop, /usr/sbin/arping, /usr/sbin/ip address *
Cmnd_Alias ONE_LVM = /usr/sbin/lvcreate, /usr/sbin/lvremove, /usr/sbin/lvs, /usr/sbin/vgdisplay, /usr/sbin/lvchange, /usr/sbin/lvscan, /usr/sbin/lvextend
Cmnd_Alias ONE_MARKET = /usr/lib/one/sh/create_container_image.sh, /usr/lib/one/sh/create_docker_image.sh
Cmnd_Alias ONE_NET = /usr/sbin/ebtables, /usr/sbin/iptables, /usr/sbin/ip6tables, /usr/sbin/ipset, /usr/sbin/ip link *, /usr/sbin/ip tuntap *
Expand Down
2 changes: 1 addition & 1 deletion share/pkgs/sudoers/debian/opennebula
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Defaults:oneadmin secure_path = /sbin:/bin:/usr/sbin:/usr/bin

Cmnd_Alias ONE_CEPH = /usr/bin/rbd
Cmnd_Alias ONE_FIRECRACKER = /usr/bin/jailer, /bin/mount, /usr/sbin/one-clean-firecracker-domain
Cmnd_Alias ONE_HA = /bin/systemctl start opennebula-flow, /bin/systemctl stop opennebula-flow, /bin/systemctl start opennebula-gate, /bin/systemctl stop opennebula-gate, /bin/systemctl start opennebula-hem, /bin/systemctl stop opennebula-hem, /usr/sbin/service opennebula-flow start, /usr/sbin/service opennebula-flow stop, /usr/sbin/service opennebula-gate start, /usr/sbin/service opennebula-gate stop, /usr/sbin/service opennebula-hem start, /usr/sbin/service opennebula-hem stop, /usr/bin/arping, /sbin/ip address *
Cmnd_Alias ONE_HA = /bin/systemctl start opennebula-flow, /bin/systemctl stop opennebula-flow, /bin/systemctl start opennebula-gate, /bin/systemctl stop opennebula-gate, /bin/systemctl start opennebula-hem, /bin/systemctl stop opennebula-hem, /bin/systemctl start opennebula-showback.timer, /bin/systemctl stop opennebula-showback.timer, /usr/sbin/service opennebula-flow start, /usr/sbin/service opennebula-flow stop, /usr/sbin/service opennebula-gate start, /usr/sbin/service opennebula-gate stop, /usr/sbin/service opennebula-hem start, /usr/sbin/service opennebula-hem stop, /usr/bin/arping, /sbin/ip address *
Cmnd_Alias ONE_LVM = /sbin/lvcreate, /sbin/lvremove, /sbin/lvs, /sbin/vgdisplay, /sbin/lvchange, /sbin/lvscan, /sbin/lvextend
Cmnd_Alias ONE_LXD = /snap/bin/lxc, /usr/bin/catfstab, /bin/mount, /bin/umount, /bin/mkdir, /bin/lsblk, /sbin/losetup, /sbin/kpartx, /usr/bin/qemu-nbd, /sbin/blkid, /sbin/e2fsck, /sbin/resize2fs, /usr/sbin/xfs_growfs, /usr/bin/rbd-nbd, /usr/sbin/xfs_admin, /sbin/tune2fs
Cmnd_Alias ONE_MARKET = /usr/lib/one/sh/create_container_image.sh, /usr/lib/one/sh/create_docker_image.sh
Expand Down
2 changes: 2 additions & 0 deletions share/sudoers/sudoers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def initialize(lib_location)
'systemctl stop opennebula-gate',
'systemctl start opennebula-hem',
'systemctl stop opennebula-hem',
'systemctl start opennebula-showback.timer',
'systemctl stop opennebula-showback.timer',
'service opennebula-flow start',
'service opennebula-flow stop',
'service opennebula-gate start',
Expand Down

0 comments on commit b84849d

Please sign in to comment.