0849.html 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <!DOCTYPE html>
  2. <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>Schedule Proxmox VM Startup and Shutdown with Cron</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <meta charset="UTF-8">
  7. <meta name="keywords" content="Browser Based,Home Lab,Home Lab Ideas,Hypervisor,Web Based,Web Based Tools,Proxmox,VM,Virtual Machine,Virtualization,Linux,Proxmox Step By Step,Proxmox Tutorial,Proxmox VE,Schedule,Scheduling,CRON,Schedule VM Startup,Schedule VM Shutdown,How To,Tutorial,i12bretro">
  8. <meta name="author" content="i12bretro">
  9. <meta name="description" content="Schedule Proxmox VM Startup and Shutdown with Cron">
  10. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  11. <meta name="revised" content="12/30/2022 07:35:14 AM" />
  12. <link rel="icon" type="image/x-icon" href="includes/favicon.ico">
  13. <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  14. <script type="text/javascript" src="includes/js/steps.js"></script>
  15. <link href="css/steps.css" rel="stylesheet" type="text/css" />
  16. </head>
  17. <body>
  18. <div id="gridContainer">
  19. <div class="topMargin"></div>
  20. <div id="listName" class="topMargin">
  21. <h1>Schedule Proxmox VM Startup and Shutdown with Cron</h1>
  22. </div>
  23. <div></div>
  24. <div id="content">
  25. <h2>What is Cron?</h2>
  26. <blockquote><em>The cron daemon is a background process that runs particular programs at particular times (for example, every minute, day, week, or month), as specified in a crontab. By default, users may also create crontabs of their own so that processes are run on their behalf. -<a href="https://packages.debian.org/stable/cron" target="_blank">https://packages.debian.org/stable/cron</a></em></blockquote>
  27. <ol>
  28. <li>Log into Proxmox VE either via SSH or the web based shell</li>
  29. <li>Run the following commands in the terminal
  30. <div class="codeBlock"># verify the location of qm<br />
  31. # should output /usr/sbin/qm<br />
  32. which qm<br />
  33. # list the configured vms<br />
  34. qm list</div>
  35. </li>
  36. <li>Note the VMID of the target VM(s)</li>
  37. <li>Determine the startup and shutdown schedule requirements for each target VM</li>
  38. <li>Convert the startup and shutdown schedules to cron format, <a href="https://crontab.guru/" style="font-size: inherit; vertical-align: unset;" target="_blank">https://crontab.guru/</a> is a great utility to visualize them</li>
  39. <li>Continue with the following commands in the terminal
  40. <div class="codeBlock"># edit the cron table file<br />
  41. crontab -e<br />
  42. # if prompted, select nano from the list of editors</div>
  43. </li>
  44. <li>At the bottom of the file, add an entry for the start and stop of each target VM in the following format
  45. <p>&lt;%cron schedule%&gt; /usr/sbin/qm &lt;%start|shutdown%&gt; &lt;%VMID%&gt;<br />
  46. 55 6 * * * /usr/sbin/qm start 100<br />
  47. 5 23 * * * /usr/sbin/qm shutdown 100</p>
  48. </li>
  49. <li>Press CTRL+O, Enter, CTRL+X to write the changes and close nano</li>
  50. <li>In the example above, VM 100 will be started at 6:55 AM and shutdown at 11:05 PM everyday</li>
  51. <li>Cron schedules can be extremely flexible with some creativity, some examples:
  52. <p><a href="https://crontab.guru/#55_6_*_*_1-5" style="font-size: inherit;" target="_blank">6:55 AM only on weekdays</a><br />
  53. 55 6 * * 1-5 /usr/sbin/qm start 100<br />
  54. <a href="https://crontab.guru/#0_9_*_*_6,0" style="font-size: inherit;" target="_blank">9:00 AM only on weekends</a><br />
  55. 0 9 * * 6,0 /usr/sbin/qm start 100<br />
  56. <a href="https://crontab.guru/#0_7_*_*_1,3,5" style="font-size: inherit;" target="_blank">7:00 AM only on Monday, Wednesday and Friday</a><br />
  57. 0 7 * * 1,3,5 /usr/sbin/qm start 100</p>
  58. </li>
  59. <li>Linux Containers (lxc) can be controlled via the pct command
  60. <p>55 6 * * 1-5 /usr/sbin/pct start 103<br />
  61. 0 9 * * 6,0 /usr/sbin/pct start 103<br />
  62. 0 7 * * 1,3,5 /usr/sbin/pct start 103</p>
  63. </li>
  64. </ol> </div>
  65. </div>
  66. </body>
  67. </html>