### How To Schedule Package Execution and Delivery

Everserve can take advantage of  the operating system's interface to schedule package delivery or execution. All packages are delivered immediately following the execution of a deliver command on a publisher in the community. Packages are executed immediately after the peer receives them. This document describes the use of OS commands, specifically AT commands in both Windows and Unix environments to schedule Everserve deliveries.

### Scheduled package delivery

The timed delivery of packages is a valuable feature. For example, a delivery could be scheduled to run after regular office hours when the network is not busy. Additionally, there is the case where a package should be scheduled for execution on a regular basis. On a Solaris Unix system the cron daemon and crontab file could be employed for execution of the same package on a regular basis. The Windows Task Scheduler can accomplish this as well. Both operating systems provide an AT command that can be used with Everserve.

### Scheduling execution of a package on the receiving peer

AT commands inside a package spec enable Everserve to execute the package at a certain time. The Everserve package spec can consist of AT commands that encapsulate commands to be executed at a specific time rather than at the time of delivery. However, the results of these scheduled commands cannot be stored by Everserve into receipts. Output from the commands that are scheduled with AT will not be recorded and returned in Everserve receipts to the publisher.  Instead, the return receipt will contain confirmation that the scheduling using the AT command was successful.

What follows is a sample package that uses AT commands to manage Everserve maintenance. The package-spec allows you to pause the Everserve community temporarily while the publisher or community manager is taken off line. It also schedules the execution of commands to restart Everserve.

For a Windows based community:

<?xml version="1.0" ?>
<!DOCTYPE spec-container SYSTEM "package_spec.dtd">
<spec-container name="restart" version="false" delta="false" >
<spec-version version="1.0" earliest="1.0"/>
<command-spec commandline="AT 6:05am cmd /c everserve resume" /> <!-- This first command-spec schedules a command to resume Everserve. Alternate commands telling everserve to stop and restart are included in this comment
<command-spec commandline="AT 6:00am net stop everserve " />
<command-spec commandline="AT 6:05am net start everserve" /> --> <!-- The AT command by itself will provide output to show that the jobs were scheduled. The package receipt seen on the publisher after delivery will show that these commands are scheduled -->
<command-spec commandline="AT" />
<!-- the last command pauses Everserve to makes the target system unavailable. Receipts are delivered by each peer despite the pause command -->
<command-spec commandline="everserve pause" />
</spec-container >

Note: In a Windows environment, the Task Scheduler Service must be running in order for the AT commands to be accepted and to work

A Unix environment package:

<?xml version="1.0" ?>
<!DOCTYPE spec-container SYSTEM "package_spec.dtd">
<spec-container name="restart" version="false" delta="false" >
<spec-version version="1.0" earliest="1.0"/>
<command-spec commandline="at 6:00am everserve resume" />
<command-spec commandline="atq" />
<command-spec commandline="everserve pause" />
</spec-container >

Note: In all cases the AT commands will execute according to the time set on the local system

AT commands executed by these packages  will not report any problems with the scheduled command in an Everserve receipt. If it is important to capture the results of the execution of the commands wrapped in AT, additional steps would be required. For example, the output from execution of the command scheduled by AT could be redirected into a file. A second package, delivered after execution of the AT command, can then output the file contents using "cat" or "type". Alternatively, the output could be emailed to the Everserve administrator. Another option is to execute the commands from a script that captures the output in an appropriate way.

A good practice, as seen in this example, is to follow up the delivery with a package that executes AT (Windows) or atq (Unix). The output sent as a receipt to the publisher will validate that the commands are correctly scheduled.

### Synchronous delivery of web content, another example of scheduling

A situation that might prompt an administrator to schedule package execution is the delivery of files or directories to a public web site at a particular time. Consider the case where a pricing scheme is going to change on an e-commerce site with multiple load balanced web servers. All of the web servers should be updated simultaneously. This modification should happen on each of the servers at exactly the time when the pricing policy change occurs.

In this example, AT commands are once again used to support publication of the html in a timely fashion. File-spec and directory-spec commands are used to deliver the content to a temporary location. The package also contains move or copy commands (copy or move wrapped by AT) to relocate the content at the appropriate time.

For a Windows based community:

<?xml version="1.0" ?>
<!DOCTYPE spec-container SYSTEM "package_spec.dtd">
<spec-container name="schedex" version="false" delta="false" >
<spec-version version="1.0" earliest="1.0"/>
<!-- the files that will be deployed synchronously
are copied with a single recursive directory spec command -->
<directory-spec source="c:\web" target="c:\temp\web" recurse="true" />
<!-- command to move files Monday morning -->
<command-spec commandline="AT 1am /next:Monday move /y c:\temp\web c:\web" />
</spec-container >

A Unix environment package:

<?xml version="1.0" ?>
<!DOCTYPE spec-container SYSTEM "package_spec.dtd">
<spec-container name="schedex" version="false" delta="false" >
<spec-version version="1.0" earliest="1.0"/>
<directory-spec source="/web" target="/tmp/web" recurse="true" />
<!-- command to move files at the beginning of 2002-->
<command-spec commandline="at 2001-12-31 23:59 mv /tmp/web /web" />
</spec-container >
{"extraction_info": {"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.8515879511833191, "perplexity": 6953.719723940447}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2020-05/segments/1579250594603.8/warc/CC-MAIN-20200119122744-20200119150744-00289.warc.gz"}