I've been running my Crystal webapp by building it, and then running the executable. However, it always listens on port 3000.
How do I build/run Crystal webapps listening on 80 and 443?
I'm using Kemal as well. Here is my sample app.
require "kemal"
get "/" do
"Hello World!"
end
Kemal.run
Building:
crystal build src/myapp.cr
Running:
./myapp
Simply pass a port to Kemal.run:
require "kemal"
get "/" do
"Hello World!"
end
port = ARGV[0]?.try &.to_i?
Kemal.run port
Build:
crystal build src/myapp.cr
Run:
./myapp # default port 3000
./myapp 80
./myapp 443
First, make sure you build your binary in release mode:
crystal build --release src/myapp.cr
To overwrite the port and binding (e.g. 0.0.0.0), you can use this example configuration:
Kemal.config.port = (ENV["PORT"]? || 8080).to_i
Kemal.config.host_binding = ENV["HOST_BINDING"]? || "127.0.0.1"
Kemal.config.env = "production"
Kemal.config.powered_by_header = false
Notes:
Instead of overwriting Kemal.config.env, you can also enable production mode by setting KEMAL_ENV=production ./myapp.
Disabling powered_by_header is optional. It is not a security risk in itself, but revealing what kind of server you are running could help an attacker. Thus, the recommendation is to avoid all unnecessary information. It will also slightly reduce traffic to omit the header. However, when troubleshooting a system, including the header can be beneficial.
Related
I am trying to do this on CentOS-7. So why will this not work when I use the command 'source filename' where filename is the following file under another name:
!/usr/bin/csh
## setting aliases for IC tool installation path
## setenv CDSHOME /path/to/cadence/installs/ICADVM181
##The following line is from the InstallScape instructions
##setenv CDSHOME /home/administrator/cadence/installs/IC618/
##If you are using the C shell, use the following command:
##setenv PATH $PATH:installation_path/vacpp/bg/12.1/bin/
##setenv CDSHOME $PATH:home/administrator/cadence/installs/IC618/
setenv CDSHOME "/home/administrator/cadence/installs/IC618/"
## Below setting is for license server, serverA and serverB are hostnames of the license server machines, and 5280 and 5281 are ports
#setenv CDS_LIC_FILE 5280#serverA:5281#serverB
## setting path in your environment
set path = ($CDSHOME/tools/bin $CDSHOME/tools/dfII/bin $path)
If I go to terminal, engage 'csh', then use 'source filename', I can then use the 'which virtuoso' to make sure that the path can be found to virtuoso. This works.
I know some basic things about Linux, bash, and csh from reading and various videos. I don't see what I'm missing here. Everything I read says you should be able to engage csh, bash, or sh with a shebang line at the beginning of a file.
My long term goal is have this string of commands load upon logging into a number of workstations or activated by double clicking a desktop icon.
This is for the Cadence software package, so I will have to do something similar depending upon what is installed. I'm not ready to worry about the licensing server issue, but that's next after being able to run 'virtuoso' executable.
I have the newest (2020.3 EAP ATM) version of CLion and I currently use it to remote debug a program on an embedded target (linux-mipsel).
Everything works as expected, after a bit of configuration, using self-built cross-toolchain and gdbserver.
My only problem is hitting the "red square" to stop execution will neither kill the running program nor gdbserver itself.
This means next iteration of edit-compile-debug cycle I will have two copies of both (I can get more, if I insist) which will not work as each tries to open the same resources (e.g.: a serial port) concurrently.
I have to manually log into target and kill the offending processes.
Am I missing something, is it a known bug or what?
Small update:
gdbserver is actually killed (does not show in ps ax) but underlying program (debugee) is still there. I am unsure why I was convinced otherwise, my bad.
This is a known issue and will hopefully be fixed soon.
Here is the link to the youtrack issue: https://youtrack.jetbrains.com/issue/CPP-20346
You could try the suggested workarounds:
Add pre-deploy configuration which kills running instances of the program
Follow the instructions for the gdb configuration in the comments:
GDB Server: /bin/bash
GDB Server args: -c "gdbserver :1234 /home/pi/myapp; pkill -e myapp"
The second config did not work for me, so I added the execution of an external tool where I run in /bin/bash the command -c "pkill -e myapp || true". The true is mandatory to avoid errors if the program is not running.
Im trying to attach DDD to gdb on a remote machine. I have configured rsh to not require a pass for my machine & username.
ddd opens with "rtx5:1234: not found" and a pop-up with "GDB could not be started". From calling ddd --host rtx5:2159 --trace --no-exec-window /home/murray/beer-process
# Running GDB (pid 2826, tty /dev/pts/1)...
# Current language: C/C++
# Searching "vsllib/ddd.vsl"...
# Trying "/home/murray/.ddd/vsllib/ddd.vsl"
# Trying "/usr/share/ddd-3.3.12/vsllib/ddd.vsl"
# Searching "vsllib/ddd.vsl"..."/usr/share/ddd-3.3.12/vsllib/ddd.vsl".
<- "sh: line 0: exec: rtx5:2159: not found\n"
# Running GDB (pid 2826, tty /dev/pts/1)...Exit 127.
The PID of GDB started by ddd from the trace logs are 4-digits. However, all the PIDs that I can see from the rtx(target) are 8-digit. I can not see gdb as a process yet the trace log indicates otherwise. Is the documentation out of date and I am invoking it incorrectly? How could I test if ddd is correctly rsh-ing?
I have addressed the caveats of the docs 2.4.1:
Beer-process binary is in the home dir of my username on the target.
Checked the path of gdb in /usr/bin/gdb
rtx5 does not have xterm therefore include --no-exec-window flag
Thanks in advance
TLDR: Had a firewall on the host interfering only with ddd's rsh connection. I also had to substitute "rtx5" for "'rsh rtx5'". It wont find the program I pass it, even though its in the home directory of the remote target. I can however use ddd-gui to find, load, and debug it.
I could rsh to rtx5 without a password, then call gdb.
I could not do "rsh rtx5 gdb" and have gdb start. This is due to rsh. When rsh is called without a command it operates out of 514. If rsh in called with a command it communicates and attempts to move to a different port number. This is where my firewall was blocking it.
Wireshark showed me from local to target after rsh connection:
destination unreachable (host administratively protected)
ddd still has issues primarily that I can not load a binary which is in my remote home directory. This extends problem extends to attaching to running processes on the remote host. In both cases I can load/connect via the gui once the connection is established.
Furthermore I have to call ddd with 'rsh ' prepended to the remote-host name. This seems wrong. I'll update when I have more.
I am trying to start / stop CAN boards or to update their baudrate using SocketCAN from userspace. My tests are performed on PeakSystem and IXXAT USB-to-CAN V1/V2 boards.
My first attempt was to use visudo and to enable NOPASSWD to "ip link set ...", and then to call "sudo ip link set ..." in my C++ code.
Complete visudo line is:
%sudo ALL=(ALL:ALL) NOPASSWD: /bin/ip link set can[0123456789]* type can bitrate [0123456789]*, /bin/ip link set can[0123456789]* up, /bin/ip link set can[0123456789]* down
Then, I tried with Linux capabilities by adding capabilities to /bin/ip. That allows me to call "ip link set ..." from my C++ code which was even better.
Add capabilities command:
sudo setcap cap_net_raw,cap_net_admin+ep /bin/ip
But then I discovered libsocketcan which is a far better approach than calling command lines from C++. However when calling "can_set_bitrate" or "can_do_start", I have an error "RTNETLINK: Operation not permitted". But things are working fine when my program is launched as root. Other functions like can_get_state are working fine in userspace (actually, they are returning : 4 -> CAN_STATE_STOPPED).
I tried to adding capabilities to my program without any success ""sudo setcap cap_net_raw,cap_net_admin+ep ./myprogram".
How can I allow my program to use libsocketcan in userspace?
Thanks for your help!
sudo setcap cap_net_raw,cap_net_admin+ep your_executable is the solution. You may need to compile with -Wl,-rpath so your program finds its shared libraries (also see this answer)
I'm using an embedded PC which has a Vortex86-SG CPU, Ubuntu 10.04 w/ kernel 2.6.34.10-vortex86-sg. Unfortunately we can't compile a new kernel, cause we don't have any source code, not even drivers or patches.
I have to run a small project written in C++ with OpenFrameworks. The framework compiles right each script in of_v0071_linux_release/scripts/linux/ubuntu/install_*.sh.
I noticed that in order to compile against Vortex86/Ubuntu 10.04, the following options must be added in every config.make file:
USER_CFLAGS = -march=i486
USER_LDFLAGS = -lGLEW
In effects, it compiles without errors, but the generated binary doesn't start at all:
root#jb:~/openframeworks/of_v0071_linux_release/apps/myApps/emptyExample/bin# ./emptyExample
Illegal instruction
root#jb:~/openframeworks/of_v0071_linux_release/apps/myApps/emptyExample/bin# echo $?
132
Strace last lines:
munmap(0xb77c3000, 4096) = 0
rt_sigprocmask(SIG_BLOCK, [PIPE], NULL, 8) = 0
--- SIGILL (Illegal instruction) # 0 (0) ---
+++ killed by SIGILL +++
Illegal instruction
root#jb:~/openframeworks/of_v0071_linux_release/apps/myApps/emptyExample/bin#
Any idea to solve this problem?
I know I am a bit late on this but I recently had my own issues trying to compile the kernel for the vortex86dx. I finally was able to build the kernel as well. Use these steps at your own risk as I am not a Linux guru and some settings you may have to change to your own preference/hardware:
Download and use a Linux distribution that runs on a similar kernel version that you plan on compiling. Since I will be compiling Linux 2.6.34.14, I downloaded and installed Debian 6 on virtual box with adequate ram and processor allocations. You could potentially compile on the Vortex86DX itself, but that would likely take forever.
Made sure I hade decencies: #apt-get install ncurses-dev kernel-package
Download kernel from kernel.org (I grabbed Linux-2.6.34.14.tar.xz). Extract files from package.
Grab Config file from dmp ftp site: ftp://vxmx:gc301#ftp.dmp.com.tw/Linux/Source/config-2.6.34-vortex86-sg-r1.zip. Please note vxmx user name. Copy the config file to freshly extracted Linux source folder.
Grab Patch and at ftp://vxdx:gc301#ftp.dmp.com.tw/Driver/Linux/config%26patch/patch-2.6.34-hda.zip. Please note vxdx user name. Copy to kernel source folder.
Patch Kernel: #patch -p1 < patchfilename
configure kernel with #make menuconfig
Load Alternate Configuration File
Enable generic x86 support
Enable Math Emulation
I disabled generic IDE support because I will using legacy mode(selectable in bios)
Under Device Drivers -> Ethernet (10 or 100Mbit) -> Make sure RDC R6040 Fast Ethernet Adapter Support is selected
USB support -> Select Support for Host-side USB, EHCI HCD (USB 2.0) support, OHCI HCD support
safe config as .config
check serial ports: edit .config manually make sure CONFIG_SERIAL_8250_NR_UARTS = 4 (or more if you have additional), CONFIG_SERIAL_8250_RUNTIME_UARTS = 4(or more if you have additional). If you are to use more that 4 serial ports make use config_serail_8250_MANY_PORTs is set.
compile kernel headers and source: #make-kpkg --initrd kernel_image kernel_source kernel_headers modules_image