How to configure a separate folder for CGI scripts with Cheyenne? - webserver

I have a web application contained in the following structure:
/app-root
+-- /html ; root files
/cgi-bin ; cgi scripts
/app ; application files
/cheyenne ; Cheyenne binary and config
My initial config is:
default [
root-dir %../html
]
How do I configure Cheyenne so that when I go to http://site/cgi-bin/foo.cgi it will look for foo in app-root/cgi-bin and not app-root/html/cgi-bin?

Related

Visual Studio Code clangd Find all references only works for local folder

I have a project with source files in multiple folders. I am using clangd as my language server. I have a single cmake file at the top of my source folder (I actually don't use cmake to build my project, I only use it to generate the compile_commands.json to allow clangd to know the include directories and the other files in the project). My cmake file looks like this:
cmake_minimum_required (VERSION 2.12)
project (Template)
# Generate compile commands database
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
add_library (Template_Lib afw/afw_can_manager.c
afw/can_router.c
afw/can_router_config.c
afw/hw_user.c
afw/VIN_check.c
afw/model_wrapper.c
app_config/output_table.c
model/Model_ert_rtw/Model.c
model/Model_ert_rtw/Model_data.c
constant_data/codegen_source/constant_data.c
application/j1939_data_integrity.c
application/service.c
application/user_interface.c
MTCT/J1939_var.c
MTCT/rtU_rtY.c
MTCT/Rx_gen.c
MTCT/RX_sig.c
MTCT/Tx_gen.c
MTCT/DM1_table.c
MTCT/nvam_config.c)
target_include_directories (CM2723_Template_Lib PUBLIC pfw
application
app_config
afw
constant_data/codegen_source
model
model/Model_ert_rtw
MTCT)
From the CMakeLists.txt, you can see the project structure. You can also see that there is no other build files in the subdirectory. When opening a file in a subdirectory (e.g. application/user_interface.c), the include files are found in the other directories so the generated command_compile.json located at the top level of the source directories. But if I try a Find all references for a function, it will find the function references in files located in the same directory but it won't find the ones in other directories (e.g. afw directory).
command_compile.json looks like this (removed paths and replaced with ...):
[
{
"directory": ".../source/build",
"command": "C:\\PROGRA~2\\MIB055~1\\2022\\BUILDT~1\\VC\\Tools\\Llvm\\x64\\bin\\clang.exe -I.../source/pfw -I.../source/application -I.../source/app_config -I.../source/afw -I.../source/constant_data/codegen_source -I.../source/model -I.../source/model/Model_ert_rtw -I.../source/MTCT -O3 -DNDEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrt -o CMakeFiles\\Template_Lib.dir\\afw\\afw_can_manager.c.obj -c ...\\source\\afw\\afw_can_manager.c",
"file": "...\\source\\afw\\afw_can_manager.c"
},
{
"directory": ".../source/build",
"command": "C:\\PROGRA~2\\MIB055~1\\2022\\BUILDT~1\\VC\\Tools\\Llvm\\x64\\bin\\clang.exe -I.../source/pfw -I.../source/application -I.../source/app_config -I.../source/afw -I.../source/constant_data/codegen_source -I.../source/model -I.../source/model/Model_ert_rtw -I.../source/MTCT -O3 -DNDEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrt -o CMakeFiles\\Template_Lib.dir\\afw\\can_router.c.obj -c ...\\source\\afw\\can_router.c",
"file": "...\\source\\afw\\can_router.c"
},
...
]
As an example, when looking for all the references to the function application_specific_initialize from the file application/user_interface.c, I get:
But when I search for the function name as a string, it is also found in afw/model_wrapper.c which is a valid function call but in a different folder (disregard the wrong matches):
To include the other directories in the search, add their absolute paths (${workspaceFolder} is a predefined variable in VS Code) to either your user (ctrl+,) or workspace (.vscode/settings.json) settings via clangd.fallbackFlags:
{
"clangd.fallbackFlags": [
"-I",
"${workspaceFolder}/afw",
// etc...
]
}
Then restart the clangd language server.

Linking to multiple subdirectories using :repo_tree

My repository is set up similar to the following:
repo_base
- artwork
- app
- designsystem
- api
Since each of the other folders in the repo (e.g. app, api, designsystem) depend on artwork, I have symlinks in place when running locally. This is working fine, as the path for images in the designsystem subdirectory is something like ../../artwork. When you check out the repository, the entire tree is checked out, so the symlinks are pointing to the correct directory.
However, when I deploy with capistrano, I use :repo_tree to only deploy a portion of the overall monorepo. For example, the deploy.rb script for the designsystem folder looks like:
# config valid for current version and patch releases of Capistrano
lock "~> 3.11.0"
set :application, "designsystem"
set :repo_url, "git#gitlab.com:myuser/mymonorepo"
set :deploy_to, "/var/www/someplace.net/designsystem.someplace.net"
set :deploy_via, "remote_cache_with_project_root"
set :repo_tree, 'designsystem'
set :log_level, :error
before 'deploy:set_current_revision', 'deploy:buildMonolith'
The problem, of course, is that this only ends up deploying the designsystem subdirectory. Thus, the symlinks aren't valid, and are actually skipped in the building (buildMonolith step).
I'm wondering how I might go about having capistrano check out another subdirectory, artwork, and placing it somewhere in the repository source tree.
I was able to solve this by adding a capistrano task called assets.rb:
require 'pathname'
##
# Import assets from a top level monorepo directory into the current working
# directory.
#
# When you use :repo_tree to deploy a specific directory of a monorepo, but your
# asset repository is in a different directory, you need to check out this
# top-level directory and add it to the deployment path. For example, if your
# monorepo directory structure looks something like:
#
# - /app
# - src/
# - assets -> symlink to ../../assets
# - /assets
# - /api
#
# And you want to deploy /app, the symlink to the upper directory won't exist if
# capistrano is configured to use :repo_tree "app". In order to overcome this,
# this task checks out a specified piece of the larger monorepo (in this case,
# the assets directory), and places it in the deployment directory at a
# specified location.
#
# Configuration:
# In your deploy/<stage>.rb file, you will need to specify two variables:
# - :asset_path - The location within the deployment directory where the
# assets should be placed. Relative to the deployment working
# directory.
# - :asset_source - The location of the top-level asset folder in the
# monorepo. Relative to the top level of the monorepo (i.e.
# the directory that would be used as a deployment if
# :repo_tree was not specified).
#
# In the above example, you would specify:
#
# set :asset_path, "src/assets"
# set :asset_source, "assets"
#
namespace :deploy do
desc "Import assets from a top-level monorepo directory"
task :import_assets do
on roles(:all) do |host|
within repo_path do
final_asset_location = "#{release_path}/#{fetch(:asset_path)}"
asset_stat_result = capture "stat", "-t", "#{final_asset_location}"
asset_stat_result = asset_stat_result.split(" ")
if asset_stat_result[0] == "#{final_asset_location}"
info "Removing existing asset directory #{final_asset_location}..."
execute "rm", "-rf", "#{final_asset_location}"
end
source_dir = Pathname.new(final_asset_location).parent.to_s
info "Importing assets to #{source_dir}/#{fetch(:asset_source)}"
execute "GIT_WORK_TREE=#{source_dir}", :git, "checkout", "#{fetch(:branch)}", "--", "#{fetch(:asset_source)}"
info "Moving asset directory #{source_dir}/#{fetch(:asset_source)} to #{final_asset_location}..."
execute :mv, "#{source_dir}/#{fetch(:asset_source)}", "#{final_asset_location}"
end
end
end
end
It would be nice if I could somehow link into the git scm plugin, rather than calling git from the command line directly.

How to auto-reload (start) docker container with supervisor

I'm stuck with a problem where I can't perfectly start my container via supervisor.
I have a mongodb container, which I want to run under supervisor.
Supervisor config itself:
; supervisor config file
[unix_http_server]
file=/var/run/supervisor.sock ; (the path to the socket file)
chmod=0700 ; sockef file mode (default 0700)
[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP)
; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket
; The [include] section can just contain the "files" setting. This
; setting can list multiple files (separated by whitespace or
; newlines). It can also contain wildcards. The filenames are
; interpreted as relative to this file. Included files *cannot*
; include files themselves.
[include]
files = /etc/supervisor/conf.d/*.conf
and mongodb container conf file:
[program:mongo]
command=/usr/bin/docker start b1b -DFOREGROUND
autostart=true
autorestart=true
startretries=10
exitcodes=0
startsecs=0
When I do "supervisorctl restart mongo" it will start container, but after I stop it it will not relaunch it automatically.
Any advice on it?
Docker already has the facility to restart stopped/failed containers, you do not need supervisor.
docker run --restart=always nginx

In Magento2 how to create custom less file for particular store?

In Magento2, how to create custom.less file for a particular store ?
i created custom themes like theme1, theme2 and theme3 in magento2
and also i created custom.less file only in theme but when i hit the command to compile this less file but is generated in all themes folders
i am only create this custom.less file in theme
these steps i follow to compile
step 1 : i am created custom.less file
step 2 : i am run these command to generate from custom.less to csutom.css
- php bin/magento setup:static:content:deploy -f
- php bin/magento cache:clean
conculsion : but this custom.css file generated in all themes.
i have created multistore websites. i have created custom.less file in first store theme but after executed all the commands css file is generated in all stores.
Working with LESS in magento 2 specific store
step1 : Go in your custom theme > web > css > source > there is _soucrces.less
file if it is not there then copy this file from magento-blank-theme.
step2 : After copied that file type code for import your file eg. <#import 'CustomCss.less';> here CustomCss.less is your file name
step3: now create one less file in following path ( web > css > source > CustomCss.less ) yourfile name name starts should be underscore ( CustomCss )
step4 : Now declare your custom variables in _variables.less file , you can find this file in following path (web > css > source )
file if it is not there then copy this file from magento-blank-theme. ( optional step ) or you can declare variables in same LESS file
step5 : After creating this files write css rules and also use variables which you are created.
step5: in your theme default_head_block.xml
add your css file in head section
result: code which in the less files it is added in customCss.css

How to run custom php script from doc root in magento2

I wanted to add custom php script to magento2 root folder and run from the browser.I tried to add it in magento2 root folder but it redirects to 404 page.
I also tried to add it in pub folder but no success.
Also cleared cache and empty generation folder.
I am using nginx server
If you are using nginx configuration that comes with magento you need to put a file inside pub folder to allow access to it from the browser as pub is the document root of the vhost. Magento root dir is one level up. Second of all default config for nginx allows only to access index.php, get.php, static.php, report.php, 404.php and 503.php files. Any other are not processed by the php. You can see this in line with location ~ (index|get|static|report|404|503)\.php$ { in nginx.conf.sample. If you are not using it check your config for similar rule. To allow another file to be accessible from browser simple add another name after 503 or change entire brackets with location ~* \.php$ {
Source: https://magento.stackexchange.com/a/97290/1883
For example you can get product name in custom script by this step
step 1: create index.php at root of magento 2
magento2/test/index.php
<?php
require __DIR__ . '../../app/bootstrap.php';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$app = $bootstrap->createApplication('customScript');
$bootstrap->run($app);
step 2: create customScript.php
magento2/test/customScript.php
<?php
class customScript
extends \Magento\Framework\App\Http
implements \Magento\Framework\AppInterface {
public function launch()
{
$this->_state->setAreaCode('frontend'); //Set area code 'frontend' or 'adminhtml
$id = 12;
$_product = $this->_objectManager->create('\Magento\Catalog\Model\Product')->load($id);
echo $_product->getName();
return $this->_response;
}
public function catchException(\Magento\Framework\App\Bootstrap $bootstrap, \Exception $exception)
{
return false;
}
}
Now you can run this custom script by
http://10.16.16.196/magento2/test/
As stated by #Ranjit, the /pub folder must be your Magento root folder.
The correct way to run a standalone php script on Magento would be:
On nginx:
Locate location ~ ^/(index|get|static|errors/report|errors/404|errors/503|health_check)\.php$ { and add your file there.
I.e:
location ~ ^/(index|get|static|errors/report|errors/404|errors/503|health_check|myphp)\.php$ {
Then you can access yourstore.com/myphp.php.
On Apache:
Simply add the file under /pub folder. I.e.: /pub/myphp.php.
Apache rewrites rule will redirect to index.php if the file or folder doesn't exist.
In my case on Apache (cPanel) the problem was that file permissions of .php files should not be writable by group or others to be served directly, else Magento's 404 would open.
So in my case to serve file directly I had to set file permission to -rw-r--r-- (on Linux).
This is the mostly issue with servers using suPHP.
Putting this here in case someone runs into same situation...