
# Deployment Notes
1) Deploying MarketData
  a) Stop the cron sevice. sudo service cron stop
  b) Check that MarketData is not running any tasks... ps xa | grep MarketData.  mks might be running but that should be all
  b) Open Folder ARM64 and do dotnet clean followed by dotnet build
  c) Locate the build files in /home/pi/ARM64/MarketData/MarketData/bin/Debug/net8.0 
  d) Dackup the /opt/MarketData/MarketData files into /opt/MarketData/MarketData_Rollback
  e) Delete all but the logs folder from the /opt/MarketData/MarketData folder
  f) Copy files from /home/pi/ARM64/MarketData/MarketData/bin/Debug/net8.0 into /opt/MarketData/MarketData
  g) Restart cron service..  sudo service cron restart
  h) Ensure that cron is running sudo service cron status

2) Deploying MarketDataService
  a) Disable the service  sudo systemctl disable mks
  b) Stop the service.  sudo systemctl stop mks  This might take 30 seconds
  c) Copy all files from /opt/MarketData/MarketDataServer to /opt/MarketData/MarketDataServer_Rollback
  d) Delete all but the logs folder from /opt/MarketData/MarketDataServer
  e) Copy files from /home/pi/ARM64/MarketDataServer/bin/Debug/net8.0 into /opt/MarketData/MarketDataServer
  f) Enable the service sudo systemctl enable mks
  g) Start the service sudo systemctl restart mks
  h) Ensure that the service running systemctl status mks


3) Deploying IPMonitor
   a) Stop the cron service.  sudo service cron stop
   b) Check that IPMonitor is not running.  ps xa | grep ipmonitor    notes: crontab -e shows the process in lower case
   c) Delete all but the ipaddress and logs folders from /opt/MarketData/IPMonitor
   d) Copy files from /home/pi/ARM64/IPMonitor/bin/Debug/net8.0 into /opt/MarketData/IPMonitor
   e) Restart the cron service.  sudo service cron restart
   f) Ensure that cron cron is running sudo service cron status



# ARM64 Version of MarketData Feeds designed to run on Raspbian system on a PI 5 16G RAM, 256Gig U30 SD Card.

TO-DO
1) MariaDb online
2) MarketDataServer 
  dotnet add package Microsoft.AspNet.WebApi.SelfHost --version 5.3.0
  dotnet add package System.ServiceModel.Primitives  --version 4.0.0

Git Delete Remote Branch
git push <remote_name> --delete <branch_name>
git push origin --delete <branch_name>
git branch -r
git branch -l

You can use the following commands to update the list of local branches from remote:
git fetch --prune


3) IPMonitor
4) Models

MarketDataService
/etc/systemd/system
sudo nano mks.service

Place the following into the file

[Unit]
Description=Market Data Server Service
After=network-online.target
Wants=network-online.target

[Service]
User=pi  # Or the user your executable runs as
WorkingDirectory=/opt/MarketData/MarketDataServer
ExecStart=/opt/MarketData/MarketDataServer/mks
Restart=always
RestartSec=5  # Seconds to wait before restarting (optional)
KillMode=process # Ensures the service is killed gracefully
Environment=DOTNET_ROOT=/opt/dotnet
StandardOutput=null

[Install]
WantedBy=multi-user.target


Enable the service: sudo systemctl enable mks.service. 
Start the service: sudo systemctl start mks.service. 
Check the status: sudo systemctl status mks.service

******************************************************************************************************
Adding notes on MariaDb as I plan to migrate the MySql over to one of the Raspberry PI 4 B's 
https://hevodata.com/learn/mysql-to-mariadb/

Notes on HttpClient
https://josef.codes/you-are-probably-still-using-httpclient-wrong-and-it-is-destabilizing-your-software/


*******************************************************************************************************

ARM version of marketdata libraries.
sudo truncate syslog -- size 0
more on syslog and journal
https://ubuntuforums.org/showthread.php?t=2495218
https://stackoverflow.com/questions/16995425/how-does-cmd-dev-null-21-work

journalctl --disk-usage   # See log file disk use
  sudo journalctl --vacuum-size=200M    # Drop log file size to 200M, if possible.
  sudo journalctl --vacuum-time=10d     # Drop logs, over 10 days old
  
DEV NULL  
ping a.b.c > /dev/null 2>&1 

  
CRON SCHEDULE
sudo crontab -e

** THE LATEST AND GREATEST IS ALWAYS AT THE BOTTOM

Also note that 1>/dev/null is synonymous to, but more explicit than >/dev/null



Here is the official latest crontab.  Adding the monthly jobs to run on the 17th
Notice that the monthly jobs will all run on the 15th of the month at 00:00  (zero hour and zero minute=midnight)
CalcSticker will also start on the 15th but 15 seconds past midnight.  It will wait for the completion of the specified processes

crontab is...
(minute) (hour) (day of month) (month) (day of week)


The following is the production crontab.  you can directly copy these lines into the cron schedule...
1) Stop the cron service.  sudo service cron stop
2) Copy/Paste daya ...  sudo crontab -e     and then copy the below lines
3) Restart cron sudo service cron restart
4) Ensure cron is running sudo service cron status

# sudo service cron reload , sudo service cron restart
# cron helper app here -> https://cron.help/#*/5_9-17_*_*_1-5
# m h  dom mon dow   command
# sudo service cron reload , sudo service cron restart
# cron helper app here -> https://cron.help/#*/5_9-17_*_*_1-5
DOTNET_ROOT=/opt/dotnet
CRON_DIR=/opt/MarketData/MarketData
CRON_DIR_IPMONITOR=/opt/MarketData/IPMonitor
*/15 6-16 * * 1-5 cd $CRON_DIR ; /opt/MarketData/MarketData/mk LOADHEADLINESWATCHLIST /WATCHLIST:Valuations > /dev/null 2>&1
*/5 5-16 * * 1-5 cd $CRON_DIR ; /opt/MarketData/MarketData/mk LOADPREMARKETDATA > /dev/null 2>&1
*/5 9-16 * * 1-5 cd $CRON_DIR ; /opt/MarketData/MarketData/mk UPDATEINTRADAYPRICING > /dev/null 2>&1
*/30 9-16 * * 1-5 cd $CRON_DIR ; /opt/MarketData/MarketData/mk UPDATELATESTANALYSTRATINGS > /dev/null 2>&1
0 19 * * 1-5 cd $CRON_DIR ; /opt/MarketData/MarketData/mk UPDATEDAILY2 /DATE:$(date -d"-0 days" +\%m-\%d-\%Y) > /dev/null 2>&1
0 0 15 * * cd $CRON_DIR ; /opt/MarketData/MarketData/mk UPDATEFINANCIALSTATEMENTS > /dev/null 2>&1
0 0 15 * * cd $CRON_DIR ; /opt/MarketData/MarketData/mk UPDATEFUNDAMENTALS > /dev/null 2>&1
0 0 15 * * cd $CRON_DIR ; /opt/MarketData/MarketData/mk UPDATEHISTORICAL > /dev/null 2>&1
15 0 15 * * cd $CRON_DIR ; /opt/MarketData/MarketData/mk CALCSTICKER /WAITFORCOMPLETION:UPDATEFINANCIALSTATEMENTS,UPDATEFUNDAMENTALS,UPDATEHISTORICAL > /dev/null 2>&1
0 18 * * Sun cd $CRON_DIR ; /opt/MarketData/MarketData/mk OPTIMIZEDB > /dev/null 2>&1
0 * * * * cd $CRON_DIR_IPMONITOR ; /opt/MarketData/IPMonitor/ipmonitor IPMONITOR /FORCE:true > /dev/null 2>&1 
10,20,30,40,50 * * * * cd $CRON_DIR_IPMONITOR ; /opt/MarketData/IPMonitor/ipmonitor > /dev/null 2>&1

