add: deploy script

This commit is contained in:
kostas 2024-06-19 17:40:33 +02:00
parent 3e1e69354c
commit 57131ec668
1 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,60 @@
#!/bin/bash
csproj="SchneiderMeterDriver.csproj"
exe="SchneiderMeterDriver"
remote="10.2.4.155"
platform="linux-arm"
netVersion="net6.0"
config="Release"
host="root@$remote"
dir="/opt/innovenergy/$exe"
log_dir="/var/log/SchneiderMeterDriver"
set -e
# Publish the project locally
dotnet publish "$csproj" -c $config -r $platform -p:SuppressTrimmAnalysisWarnings=true -p:PublishSingleFile=true -p:PublishTrimmed=true -p:DebugType=None -p:DebugSymbols=false --self-contained true
# Sync the published files to the remote server
rsync -av "bin/$config/$netVersion/$platform/publish/" "$host:$dir"
# Execute commands on the remote server
ssh "$host" << 'EOF'
set -e
# Remount the root filesystem with read and write permissions
mount -o remount,rw /
# Create service and log directories
mkdir -p /opt/innovenergy/SchneiderMeterDriver/service
mkdir -p /opt/innovenergy/SchneiderMeterDriver/service/log
mkdir -p /var/log/SchneiderMeterDriver
# Create the service run script
cat << 'EOL' > /opt/innovenergy/SchneiderMeterDriver/service/run
#!/bin/sh
exec 2>&1
exec softlimit -d 200000000 -s 2000000 -a 200000000 /opt/innovenergy/SchneiderMeterDriver/SchniederDriver
EOL
chmod +x /opt/innovenergy/SchneiderMeterDriver/service/run
# Create the log run script
cat << 'EOL' > /opt/innovenergy/SchneiderMeterDriver/service/log/run
#!/bin/sh
exec 2>&1
exec multilog t s25000 n4 /var/log/SchneiderMeterDriver
EOL
chmod +x /opt/innovenergy/SchneiderMeterDriver/service/log/run
# Create the symbolic link for the service
ln -sf /opt/innovenergy/SchneiderMeterDriver/service /service/SchneiderMeterDriver
# Wait a bit for the symlink to be recongnized
sleep 2
# Start the service
start SchneiderMeterDriver
EOF
echo "Deployment and service setup completed successfully."