Capistrano creating task to change current symlink - deployment

I am trying to setup Capistrano deployment for my website, I have got the deploy working, all authentication fine, but I host with Media temple so the default symlink will not work as apache won't have access to the path specified for current to the latest release.
I am trying to make a task that will unlink the current symlink, then recreate it with a relative path, however the Capistrano documentation is severely lacking and I cannot find any more information anywhere of how exactly to set this up.
I have tried using sh, but that seems to run the commands on my computer rather than on the server, run command is not found, and I tried execute but cannot find the right format to do things like rm, or ln, etc...
Currently I am trying the following:
namespace :deploy do
desc "Change HTML Symlink to relative path"
task :create_symlink do
#latest_release_relative = relative_path(deploy_to, release_path + '/html')
#sh "rm -f #{current_path} && ln -s #{latest_release_relative} #{current_path}"
#sh "echo #{File.basename release_path}"
info "echo Modifying symlink to be relative"
#run "rm -d #{current_path}"
#run "ln releases/#{File.basename release_path} #{current_path}"
#execute :rm, '-d', #{current_path}
end
desc "Create environment file"
task :create_env_conf
file 'env.conf' do |t|
sh "touch env.conf"
end
end
after :deploy, "deploy:create_symlink", "deploy:create_env_conf"

After a huge amount of trial and error, I found that the issue was that;
Need to use execute in cap v3
Need to cd then chain command with && for running directory specific commands
Capistrano needs more documentation...
This is how I got mine working, I think there is a better way of doing it with Capistrano 3 but I could not find adequate documentation describing how anywhere.
#config valid only for Capistrano 3.1
lock '3.1.0'
set :application, 'prism-credentials'
set :repo_url, 'REPO URL'
# Default deploy_to directory is /var/www/my_app
set :deploy_to, 'DEPLOY FOLDER'
# Default value for keep_releases is 5
set :keep_releases, 5
set :branch, "master"
if ENV['branch']
set :branch, ENV['branch']
end
namespace :deploy do
desc "Change HTML Symlink to relative path"
task :create_symlink do
on roles(:app) do
#execute "ls -l"
info "Modifying symlink to be relative"
execute "rm -d #{current_path}"
info "Deleted current symlink"
execute "cd ../DEPLOY FOLDER && ln -s ./releases/#{File.basename release_path} current"
info "Created relative current symlink"
execute "cd ~/../DEPLOY FOLDER && touch env.conf && echo 'live' >> env.conf"
info "Created environment file"
end
end
end
after :deploy, "deploy:create_symlink"

Related

Failed to load dynamic library 'libtensorflowlite_c.so': dlopen failed: library "libtensorflowlite_c.so" not found

When I tried to call
/// runs and transforms the data 🤖
this._interpreter.run(input, output);
this._interpreter = await Interpreter.fromAsset('mobilefacenet.tflite',
options: interpreterOptions);
Got this error
Failed to load dynamic library 'libtensorflowlite_c.so': dlopen failed: library "libtensorflowlite_c.so" not found
For Windows users:
Copy all these lines on notepad:
#echo off
setlocal enableextensions
cd %~dp0
set TF_VERSION=2.5
set URL=https://github.com/am15h/tflite_flutter_plugin/releases/download/
set TAG=tf_%TF_VERSION%
set ANDROID_DIR=android\app\src\main\jniLibs\
set ANDROID_LIB=libtensorflowlite_c.so
set ARM_DELEGATE=libtensorflowlite_c_arm_delegate.so
set ARM_64_DELEGATE=libtensorflowlite_c_arm64_delegate.so
set ARM=libtensorflowlite_c_arm.so
set ARM_64=libtensorflowlite_c_arm64.so
set X86=libtensorflowlite_c_x86_delegate.so
set X86_64=libtensorflowlite_c_x86_64_delegate.so
SET /A d = 0
:GETOPT
if /I "%1"=="-d" SET /A d = 1
SETLOCAL
if %d%==1 CALL :Download %ARM_DELEGATE% armeabi-v7a
if %d%==1 CALL :Download %ARM_64_DELEGATE% arm64-v8a
if %d%==0 CALL :Download %ARM% armeabi-v7a
if %d%==0 CALL :Download %ARM_64% arm64-v8a
CALL :Download %X86% x86
CALL :Download %X86_64% x86_64
EXIT /B %ERRORLEVEL%
:Download
curl -L -o %~1 %URL%%TAG%/%~1
mkdir %ANDROID_DIR%%~2\
move /-Y %~1 %ANDROID_DIR%%~2\%ANDROID_LIB%
EXIT /B 0
Save the file as install.bat and put the file in root directory of your project.
Open in explorer and open a command window there.
Type install.bat and press Enter. Use install.bat -d (Windows) instead if you wish to use GpuDelegateV2 and NnApiDelegate.
For Linux/Mac users:
Copy all these lines on notepad
#!/usr/bin/env bash
cd "$(dirname "$(readlink -f "$0")")"
# Available versions
# 2.5, 2.4.1
TF_VERSION=2.5
URL="https://github.com/am15h/tflite_flutter_plugin/releases/download/"
TAG="tf_$TF_VERSION"
ANDROID_DIR="android/app/src/main/jniLibs/"
ANDROID_LIB="libtensorflowlite_c.so"
ARM_DELEGATE="libtensorflowlite_c_arm_delegate.so"
ARM_64_DELEGATE="libtensorflowlite_c_arm64_delegate.so"
ARM="libtensorflowlite_c_arm.so"
ARM_64="libtensorflowlite_c_arm64.so"
X86="libtensorflowlite_c_x86_delegate.so"
X86_64="libtensorflowlite_c_x86_64_delegate.so"
delegate=0
while getopts "d" OPTION
do
case $OPTION in
d) delegate=1;;
esac
done
download () {
wget "${URL}${TAG}/$1" -O "$1"
mkdir -p "${ANDROID_DIR}$2/"
mv $1 "${ANDROID_DIR}$2/${ANDROID_LIB}"
}
if [ ${delegate} -eq 1 ]
then
download ${ARM_DELEGATE} "armeabi-v7a"
download ${ARM_64_DELEGATE} "arm64-v8a"
else
download ${ARM} "armeabi-v7a"
download ${ARM_64} "arm64-v8a"
fi
download ${X86} "x86"
download ${X86_64} "x86_64"
Save the file as install.sh name and put the file in root directory of your project.
Open a command window there.
Type sh install.sh and press Enter. Use sh install.sh -d instead if you wish to use GpuDelegateV2 and NnApiDelegate.
You need to add a file in the root directory in the app found in
tflite_flutter package. tflite_flutter. You can also find it here.
just download the file and place it into the root directory in your app and double click to install the needed information. (For Windows)
I had the same error. Hopefully this is helpful to someone.
After using the install.sh file, that error showed (only on Android, iOS worked fine). But I had changed the wget to curl in the install file and it had downloaded a redirect html page.
The replacement that worked for me was:
# wget "${URL}${TAG}/$1" -O "$1" # Replaced with the below line
curl -L "${URL}${TAG}/$1" -o "$1"
Try to confirm that the files you have downloaded are the correct files. You can inspect these files in <projectdirectory>/android/app/src/main/jniLibs. They should be binary files that begin with ^?ELF, not html files like what I had.

Postgresql Auto backup using powershell and task scheduler

I am running attached script to backup postgresql database by using task scheduler. Script is executed successfully but backup is not happening. Same script i have run on powershell and it's working fine.enter image description here
I want to schedule daily backup on windows server. Please help me or suggest any alternative to automate the backup.
Regards
Sadam
Try this script, it will create a backup file with a name consisting of a timestamp:
First, create a backup.bat file and just run it (set your credentials and database name):
echo off
echo 'Generate backup file name'
set CUR_YYYY=%date:~10,4%
set CUR_MM=%date:~4,2%
set CUR_DD=%date:~7,2%
set CUR_HH=%time:~0,2%
if %CUR_HH% lss 10 (set CUR_HH=0%time:~1,1%)
set CUR_NN=%time:~3,2%
set CUR_SS=%time:~6,2%
set BACKUP_FILE=%CUR_YYYY%-%CUR_MM%-%CUR_DD%_%CUR_HH%-%CUR_NN%-%CUR_SS%.custom.backup
echo 'Backup path: %BACKUP_FILE%'
echo 'Creating a backup ...'
set PGPASSWORD=strongpas
pg_dump.exe --username="postgres" -d AdventureWorks --format=custom -f "%BACKUP_FILE%"
echo 'Backup successfully created: %BACKUP_FILE%'
As a result, you should see such a picture, and a file with the extension .custom.backup should appear in the directory
If you get an error that the executable file "pg_dump.exe" was not found, then specify the full path to this file, something like "C:\Program Files\PostgreSQL\12\bin\pg_dump.exe", or add a directory with binaries PostgreSQL to environment variables (more details here)
-
To schedule regular execution, you can use the windows task scheduler
Press win + r and enter taskschd.msc
Select Create Basic Task
Then follow the steps of the wizard, specify the schedule, and in the "Action" section, specify "Start a program" and then the path to the backup.bat file
To check that everything is correct, find the task in the list and select Run
You can read more about Postgresql backups on Windows here

PATH in shell getting mysterious entry (fish shell, ubuntu system)

I am using fish shell on a Ubuntu sytem. This question is about redundancy in $PATH that I am setting unintentionally.
When I type echo $PATH, I get:
/opt/anaconda3/bin/ /opt/anaconda3/etc/fish/conf.d/ /opt/anaconda3/bin/ /opt/anaconda3/etc/fish/conf.d/ /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin /usr/games /usr/local/games .
Multiple annoyances with this: /opt/anaconda3/bin showing up twice, showing some non-existant directories: /usr/local/games /usr/games.
My /etc/login.defs reads:
ENV_PATH PATH=/usr/local/bin:/usr/bin:/bin
So the redundancy is not coming from there. Of course, my PATH in config.fish is set as:
set -gx PATH /opt/anaconda3/bin/ (/opt/anaconda3/bin/conda info --root)/etc/fish/conf.d/ $PATH .
My Question: where does fish get its PATH from, other than what is set in my environment and what is handed to it by: /etc/login.defs?
UPDATE: I changed to using fish_user_paths variable, per documentation which got rid of /opt/anaconda3/bin added twice. Still the /usr/games/ and /usr/local/games are getting added automagically (and those directories don't exist on my system!).
After looking around on the Internet, this is not a shell related issue: fish shell or any other shell. It's a Linux issue. The kernel, somewhere before forking the init, reads the:
/etc/environment file and sets the system wide default path.
In a single user environment, we could just edit that file - if we insist. Personally, I added lines to my fish profile to purge the non-existant directories from the path :
if set -l index (contains -i -- /usr/local/games $PATH)
set --erase PATH[$index]
end
if set -l index (contains -i -- /usr/games $PATH)
set --erase PATH[$index]
end

Including some SFTP commands in a Makefile

I use a Makefile to create pdfs of papers I'm working on. I'd also like to use make to upload the latest version to my website, which requires sftp. I though I could do something like this (which words on the command line) but it seems that in make, the EOF is getting ignored i.e., this
website:
sftp -oPort=2222 me#mywebsite.com << EOF
cd papers
put research_paper.pdf
EOF
generates an error message
cd papers
/bin/sh: line 0: cd: papers: No such file or directory
which I think is saying "papers" doesn't exist on your local machine i.e., the 'cd' is being executed locally, not remotely.
Couple of ideas:
use ncftp which every Linux distro as well as brew should have: it remembers 'state' so the cd becomes unnecessary
use scp instead of sftp if possible
write a trivial shell script doing the EOF business and call that
For what it is worth, here is my script to push tarballs to the CRAN winbuilder -- and takes target directory and script as arguments to ncftpput.
#!/bin/bash
function errorexit () {
echo "Error: $1"
exit 1
}
if [ "$#" -lt 1 ]; then
errorexit "Need to specify argument file"
fi
if [ ! -f ${1} ]; then
errorexit "File ${1} not found, aborting."
fi
ncftpput win-builder.r-project.org /R-release ${1}
ncftpput win-builder.r-project.org /R-devel ${1}
I then just do wbput.sh foo_1.2-3.tar.gz and off it goes...
You cannot (normally) put a single command on multiple lines in a Make recipe, so here documents are a no-go. Try this instead:
website: research_paper.pdf
printf 'cd papers\nput $<\n' \
| sftp -oPort=2222 me#mywebsite.com
The target obviously depends on the PDF, so I made it an explicit dependency, as well.

rake directory command silently fails?

I'm a newbie to rake so there's probably a simple explanation. I wanted to create some directories and copy in some files for a simple install script e.g.
task :default => ['mktd1', 'mktd2' ] do
end
task :mktd1 do
mkdir "testdata"
cp "x.tmp", "testdata/x.tmp"
end
task :mktd2 do
directory "testdata1"
cp "x.tmp", "testdata1/x.tmp"
end
mkdir works as long as the testdata directory doesnt already exist, but "directory" silently fails (i.e. does nothing) leading to a rake abort because the directory isn't there for the cp command.
Have I misunderstood what directory directive is supposed to do?
So the answer was I had misunderstood how rake is supposed to work. To achieve what I wanted I needed to declare a task that had a dependency on the testdata1 directory. e.g.
task :default => [ 'testdata1/x.tmp' ] do
end
directory "testdata1"
file "testdata1/x.tmp" => ["testdata1"] do
cp "x.tmp", "testdata1/x.tmp"
end
This of course creates a file_creation task x.tmp which depends on the testdata1 directory, and a default task that depends on the x.tmp file creation task. I feel dumb.