Knowledge Base

Command Line Publish

Last Modified:
30 Apr 2019
User Level:
Administrator

You can bypass logging into TERMINALFOUR interface to initiate publishes by using the Command Line Interface (CLI).

Setting up your local environment

Before you can use command line publish you will need to ensure that your local environment can run the commands. To do this, first ensure that Java is installed (this is required for running the script file).

You can check for your the Supported Systems documentation for your version here. Then, configure JAVA_HOME

After you do this, run java -version

If it returns bash java command not found or similar, try the following:

Edit the bashrc and profile files

vi ~/.bash_profile
vi ~/.bashrc

Add two lines to each (you may need to update the path based on your where Java is installed)

export JAVA_HOME=/usr/local/java
export PATH=$JAVA_HOME/bin:$PATH

Reload the files

. ~/.bash_profile
. ~/.bashrc

Using the Command Line Publish

The following steps have been tested on CentOS Server.

Create the following directory structure:
/usr/local/terminalfour/scripts/cmd_line_publish/WEB-INF/lib

Copy the three files included in the zip file below:

  • script.sh
  • context.xml
  • connection.properties

Edit the context.xml file and change the values to match your installation. The part you need to edit is below the comment:

<!-- ###### SAMPLE COMMAND LINE DATA SOURCE DEFINITION ##### --> 
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/sm8" />
<property name="username" value="sm8" /><property name="password" value="password" />
<property name="initialSize" value="5"/><property name="maxActive" value="50"/>
</bean>

<bean id="eventNotificationExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="5" />
<property name="maxPoolSize" value="10" />
</bean>

You will need to change driver (if using a database other than MySQL), URL, Username and Password

Edit the connection.properties file and change the values to match your installation settings:

url=jdbc:mysql://localhost/sm8?jdbcCompliantTruncation=false&zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8
driver=com.mysql.jdbc.Driver
username=sm8
password=password
database.factory=com.terminalfour.database.mysql.MySQLDBFactory

Edit the script.sh file to run on your server:

TOMCAT_HOME=/usr/share/tomcat7
SM_CONTEXT=terminalfour
CHANNEL_ID=1
java -cp .:"$TOMCAT_HOME/lib/*":"$TOMCAT_HOME/webapps/$SM_CONTEXT/WEB-INF/lib/*" com.terminalfour.publish.AutoPublisher -c $CHANNEL_ID -s context.xml -d com.terminalfour.database.mysql.MySQLDBFactory -v "$TOMCAT_HOME/webapps/$SM_CONTEXT/WEB-INF/sm-structure.xml"

To execute the script use the following command:

./script.sh
If you get a Permission denied error when running the script, run the following command:
chmod +x script.sh

Parameters

The following parameters can be modified:

  • -a Include archived Sections as part of the publish
  • -c <arg> List of Channels to be published
  • -d <arg> Database query factories to be loaded
  • -f Process all fulltext files, even if they're outside the display period
  • -m <arg> List of Microsites to be published
  • -p Output the pending version of the selected Channels where possible
  • -s <arg> spring context configuration XML file
  • -t <arg> Number of threads to use to process page contents
  • -v <arg> Location of sm-structure.xml, which defined the expected database structure
  • -w <arg> Number of file write threads to use

You can restrict Command Line Publish to a single Channel by defining the CHANNEL_ID in a variable or manually set in the script; the example above uses a defined variable.

Once the publish debug output stops, check the publish output directory and you should see the Channel published files.

Other scenarios to run the Command Line Publish

Command line publish for multiple Channels

Edit the script.sh file to list the channel id's you wish to publish (replacing the $CHANNEL_ID variable):

TOMCAT_HOME=/usr/share/tomcat7
SM_CONTEXT=terminalfour
java -cp .:"$TOMCAT_HOME/lib/*":"$TOMCAT_HOME/webapps/$SM_CONTEXT/WEB-INF/lib/*" com.terminalfour.publish.AutoPublisher -c 1, 2 -s context.xml -d com.terminalfour.database.mysql.MySQLDBFactory -v "$TOMCAT_HOME/webapps/$SM_CONTEXT/WEB-INF/sm-structure.xml"

Once the publish debug output stops, check the publish output directories for the specified Channels.

Command line publish for all Channels

Edit the script.sh file and use the word "all" instead of the Channel IDs:

TOMCAT_HOME=/usr/share/tomcat7
SM_CONTEXT=terminalfour
java -cp .:"$TOMCAT_HOME/lib/*":"$TOMCAT_HOME/webapps/$SM_CONTEXT/WEB-INF/lib/*" com.terminalfour.publish.AutoPublisher -c all -s context.xml -d com.terminalfour.database.mysql.MySQLDBFactory -v "$TOMCAT_HOME/webapps/$SM_CONTEXT/WEB-INF/sm-structure.xml"

Once the publish debug output stops, check the publish output directories for all Channels.

Publish Microsites

To publish Microsites, you can do this by listing the IDs of the Microsites with the argument -m:

TOMCAT_HOME=/usr/share/tomcat7
SM_CONTEXT=terminalfour
java -cp .:"$TOMCAT_HOME/lib/*":"$TOMCAT_HOME/webapps/$SM_CONTEXT/WEB-INF/lib/*" com.terminalfour.publish.AutoPublisher -c 1 -m 2 -s context.xml -d com.terminalfour.database.mysql.MySQLDBFactory -v "$TOMCAT_HOME/webapps/$SM_CONTEXT/WEB-INF/sm-structure.xml"

If you are publishing multiple Microsites, separate the IDs with a comma.

Output the pending version of a Channel

Go to System Administration > Set up Sites and Channels > Channels and edit your Channel. In the Pending version output section, enter the location that the pending version will publish to. Edit the script.sh files to add the -p argument:

TOMCAT_HOME=/usr/share/tomcat7
SM_CONTEXT=terminalfour
java -cp .:"$TOMCAT_HOME/lib/*":"$TOMCAT_HOME/webapps/$SM_CONTEXT/WEB-INF/lib/*" com.terminalfour.publish.AutoPublisher -c 1 -p -s context.xml -d com.terminalfour.database.mysql.MySQLDBFactory -v "$TOMCAT_HOME/webapps/$SM_CONTEXT/WEB-INF/sm-structure.xml"

Publish reports for Command Line Publishes

To view a Publish Report for Command Line Publishes enable full/basic reporting for your Channel and run a Command Line Publish.
In System Reports > Publish Reports  you will see a report generated with the Publish type 'Command line':

Screenshot of the Publish Report Command Line Publish

Ownership of published files

If you execute the script as root user, the published files will be owned by user 'root'
If you want the published files to be owned by tomcat (as happens with a publish from TERMINALFOUR), then you should execute the script as user 'tomcat'.

Back to top