Apache Ace as a Service - apache

I am trying to setup/configure Apache ACE for the first time. It seems like I got everything running correctly but I would like to have ACE startup automatically when the Linux box starts. I created the init.d script below which does starts up ACE however it drops me in an OSGI console and when I leave the console ACE shuts down.
Is there a way to start ACE without having the OSGI console so I do not have to keep my session open to keep ACE running?
#! /bin/bash
BIN_DIR=/opt/ace-current/server-allinone
PATH=/bin:/usr/bin:/sbin:/usr/sbin
JAVA_HOME=/usr/lib/jvm/default-java
if [ `id -u` -ne 0 ]; then
echo "You need root privileges to run this script"
exit 1
fi
. /lib/lsb/init-functions
if [ -r /etc/default/rcS ]; then
. /etc/default/rcS
fi
case $1 in
start)
cd $BIN_DIR
java -Dorg.apache.ace.server=localhost:11868 -Dorg.osgi.service.http.port=11868 -Dorg.apache.ace.obr=localhost:11868 -jar server-allinone.jar
;;
stop)
pid=`ps aux | grep server-allinone | awk '{print $2}'`
kill -9 $pid
;;
restart)
$0 stop
$0 start
;;
esac
exit 0

java -Dgosh.args=--nointeractive -jar server-allinone.jar
Will disable the local shell.

Related

micro:bit & /dev/ttyACM*on GNU/Linux systems

I have micro:bit attached to my laptop on which running Xubuntu 18.04.4 LTS.
After I attached micro:bit an icon appeares on XFCE4 Desktop which can
to use to mount this device to
/media/MyUserName/MICROBIT/
This way I can pair the device 'BBC micro:bit CMSIS-DAP' and my laptop
by using https://python.microbit.org/v/2.0 in my Google Chrome browser.
But in mu-editor I can't do this, can't use neither REPL, nor FILE
because I get this message box:
"Colud not find an attached device
Please make sure the device is plugged into this computer.
It must have a version of MicroPython (or CircuitPython) flashed onto it
before the REPL will work.
Finally, press the device's reset button and wait a few seconds before
trying again."
$ lsusb
ID 0d28:0204 NXP LPC1768
This line above is for the micro:bit attached.
$ ls /dev/ | grep tty
In the output of the command above there is not a /dev/ttyACM0
or other ACM* device out there.
Why is not there such a device /dev/ttyACM* out there?
I suspect mu-editor does not find the device because there is no such
device /dev/ttyACM* out there.
How can I solve the problem for mu-editor?
I use Debian Linux. There are two things you may need to do:
I had to update the firmware on the micro:bits recently to be able to continue using the mu-editor. The instructions on how to do this are here:
[https://microbit.org/get-started/user-guide/firmware/]
Mount the micro:bit. This can be done by double clicking on the 'MICROBIT' shown in e.g. Nautilus, or from the command line using udisksctl. Please find a bash script below called microbit_mount.sh which uses udisksctl to mount and dismount a microbit. To mount a microbit, use the command:
microbit_mount.sh mount
To unmount a microbit, use
microbit_mount.sh unmount
I have these commands aliased to mm amd md.The microbit will appear in /media/MICROBIT. You may need to remount the microbit after each flash.
#!/bin/bash
# microbit_mount.sh
# mount and unmount microbit
# modified from https://askubuntu.com/questions/342188/how-to-auto-mount-from-command-line
BASEPATH="/media/$(whoami)/"
MICRO="MICROBIT"
if [ $# -eq 0 ]
then
echo "no argument supplied, use 'mount' or 'unmount'"
exit 1
fi
if [ $1 == "--help" ]
then
echo "mounts or unmounts a BBC micro:bit"
echo "args: mount - mount the microbit, unmout - unmount the microbit"
fi
# how many MICRO found in udisksctl dump
RESULTS=$(udisksctl dump | grep IdLabel | grep -c -i $MICRO)
case "$RESULTS" in
0 ) echo "no $MICRO found in 'udkisksctl dump'"
exit 0
;;
1 ) DEVICELABEL=$(udisksctl dump | grep IdLabel | grep -i $MICRO | cut -d ":" -f 2 | sed 's/^[ \t]*//')
DEVICE=$(udisksctl dump | grep -i "IdLabel: \+$DEVICELABEL" -B 12 | grep " Device:" | cut -d ":" -f 2 | sed 's/^[ \t]*//')
DEVICEPATH="$BASEPATH""$DEVICELABEL"
echo "found one $MICRO, device: $DEVICE"
if [[ -z $(mount | grep "$DEVICE") ]]
then
echo "$DEVICELABEL was unmounted"
if [ $1 == "mount" ]
then
udisksctl mount -b "$DEVICE"
exit 0
fi
else
echo "$DEVICELABEL was mounted"
if [ $1 == "unmount" ]
then
udisksctl unmount -b "$DEVICE"
exit 0
fi
fi
;;
* ) echo "more than one $MICRO found"
;;
esac
echo "exiting without doing anything"
I installed Xubuntu 20.04 and on this system mu-editor works in the Files mode and REPL mode with the attached micro:bit.

Is it possible to use the "code" command in SSH'ed terminal to open VS Code on local machine with SSH extension?

Something I love about VS Code is that when I am using a terminal in WSL, I can run code file.txt, and it will open that file with VS Code on my local using the WSL remote extension.
Is it possible to do a similar thing with SSH? I.e., if I am SSH'ed into a remote host, is it possible to set things up so that running code file.txt will open VS Code on my local machine, connected via the remote SSH extension to open that file?
I found much better & simple answer thanks to this post.
Simply create new script file named code with below contents & put file under any folder from $PATH. (echo $PATH to see what folders you can use)
#! /usr/bin/env zsh
local max_retry=10
for i in {1..$max_retry}
do
local script=$(echo ~/.vscode-server/bin/*/bin/remote-cli/code(*oc[$i]N))
if [[ -z ${script} ]]
then
echo "VSCode remote script not found"
exit 1
fi
local socket=$(echo /run/user/$UID/vscode-ipc-*.sock(=oc[$i]N))
if [[ -z ${socket} ]]
then
echo "VSCode IPC socket not found"
exit 1
fi
export VSCODE_IPC_HOOK_CLI=${socket}
${script} $# > /dev/null 2>&1
if [ "$?" -eq "0" ]; then
exit 0
fi
done
echo "Failed to find valid VS Code window"
Bash version
#! /bin/bash
max_retry=10
for i in $(seq 1 $max_retry)
do
recent_folder=$(ls ~/.vscode-server/bin/ -t | head -n$i)
script=$(echo ~/.vscode-server/bin/$recent_folder/bin/remote-cli/code)
if [[ -z ${script} ]]
then
echo "VSCode remote script not found"
exit 1
fi
socket=$(ls /run/user/$UID/vscode-ipc-* -t | head -n$i)
if [[ -z ${socket} ]]
then
echo "VSCode IPC socket not found"
exit 1
fi
export VSCODE_IPC_HOOK_CLI=${socket}
${script} $#
if [ "$?" -eq "0" ]; then
exit 0
fi
done
echo "Failed to find valid VS Code window"
Update
Above script doesn't work with recent updates. I had to change first line to
local script=$(echo ~/.vscode-server/bin/*/bin/remote-cli/code(*oc[1]N))
Update2
Original script may fail if recently opened ssh window is closed, yet there is another SSHed window open. I have enhanced the script to enable retrying the command with recent N(default 10) windows.
You shouldn't have to do anything. VSCode automatically sets the path/PATH to the code in the path/PATH environment variable depending on your shell. See this response. You might be overwriting your path/PATH like I was. I was accidentally overwriting path in ~/.cshrc and PATH in ~/.bashrc and was running into the same issue. After fixing it, I can run code on the command line. which code returns the location of the command.
Until I spent time to figure it out, I was using the two methods mentioned below. Both of which worked for me in bash; you can modify it for your shell as you see fit. But really fix your path/PATH rather than using these methods.
Adding location of code to the PATH in ~/.bashrc
export PATH=${VSCODE_GIT_ASKPASS_NODE%/*}/bin:$PATH
OR
Setting alias to code in ~/.bashrc
alias code="${VSCODE_GIT_ASKPASS_NODE%/*}/bin/code"
More on path vs. PATH here and here
Yes, sort of.
From a VSCode terminal run the command
env | grep VSCODE_IPC_HOOK_CLI
then copy-and-paste that line that line with export into your ssh terminal.
After that, you should be able to run code from your ~/.vscode-server/bin/XXX/bin directory.
VSCode terminal
SSH terminal
Update:
You can to automate this with a .bashrc and .profile to place the IPC code into a temp file, and source that when you do your ssh login.
For example, this works for me...
Append this to ~/.bashrc
#
if [ "$VSCODE_IPC_HOOK_CLI" != "" ]; then
cat >$HOME/.vscode_env.sh <<EOF
#
if [ "\$VSCODE_IPC_HOOK_CLI" = "" ]; then
export VSCODE_IPC_HOOK_CLI="$VSCODE_IPC_HOOK_CLI"
alias code="${VSCODE_GIT_ASKPASS_NODE%/*}/bin/code"
fi
EOF
fi
And append this to your ~/.profile
[ -f $HOME/.vscode_env.sh ] && . $HOME/.vscode_env.sh
(There may be more elegant ways. And you still have to start at least 1 terminal in your remote VSCode session.)
this works to me
if [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then
local script=$(echo ~/.vscode-server/bin/*/bin/remote-cli/code(*oc[1]N))
if [[ -z ${script} ]]
then
echo "VSCode remote script not found"
exit 1
fi
local socket=$(echo /run/user/$UID/vscode-ipc-*.sock(=oc[1]N))
if [[ -z ${socket} ]]
then
echo "VSCode IPC socket not found"
exit 1
fi
export VSCODE_IPC_HOOK_CLI=${socket}
alias code=${script}
fi
Use the below commands to open a folder or a file on the remote terminal.
Note: vscode-server must be already installed on the remote host (It would be, if you have already connected to it). Also the absolute path has to be specified for the file or folder. Use -n to launch in new window,-r to reuse same window.
code --folder-uri <absolute-path>
code --file-uri <absolute-path-file-name>
Example:
code -r --folder-uri /home/myscripts/src
code -n --file-uri /home/myscripts/src/math/sample.py

Why does this fish while loop terminate after a single iteration?

This is a fish function used to upgrade JavaScript packages for a project. Strangely, it terminates after a single iteration with an exit status of 0. Why?
function yarn-upgrade-all --description "Upgrade JavaScript packages"
yarn outdated | sed '1,/^Package/d;/^Done/d' | awk '{print $1, $4}' | while read -l PACKAGE VERSION
echo
set_color brwhite
echo -n "==>"
set_color yellow
echo -n " "$PACKAGE
set_color brblue
echo -n " "$VERSION
set_color brwhite
echo -n " <=="
set_color normal
echo
echo
yarn upgrade --latest $PACKAGE
and yarn run test
and yarn run build
and git commit -am "Upgrade to "$PACKAGE" "$VERSION
or begin
set_color red
echo "last command exited with status $status" >&2
set_color normal
return 1
end
end
end
On the other hand, this second function, which contains only a stub body, runs through all packages piped into the loop.
function yarn-upgrade-all-debug --description "Upgrade JavaScript packages"
yarn outdated | sed '1,/^Package/d;/^Done/d' | awk '{print $1, $4}' | while read -l PACKAGE VERSION
echo $PACKAGE $VERSION
end
end
fish --version
fish, version 3.0.2
You're running fish 3.0.0, and hitting https://github.com/fish-shell/fish-shell/issues/5513 - return from a while doesn't actually set the status correctly.
However, the return still causes it to terminate the while-loop.
Upgrade to 3.0.2.
The loop terminates after a single iteration because the yarn run invocations in the loop body slurp up the rest of stdin. (Credits to #glenn-jackman.)
A possible workaround is to redirect stdin to /dev/null for these commands:
and yarn run test < /dev/null
and yarn run build < /dev/null
The culprit is run-s from the npm-run-all package, which is invoked by both yarn run commands.
https://github.com/mysticatea/npm-run-all/issues/166

cannot kill process in FreeBSD

I have a script in FreeBSD 10.1 release, it's purpose is to monitor another process and keep the process alive.
When I try to kill itself, it always fail.
I try killall [name | pid]; pkill -9 [name]; service watchtas stop, none of them work.
Below is my script, please advise the solution.
#!/bin/sh
. /etc/rc.subr
prog="Thin-Agent WatchDog"
TAS_BIN="/etc/supermicro/tas-freebsd.x86_64"
TAS_LOG="/etc/supermicro/tas_system_crush.log"
monitor=1
name="watchtas"
rcvar=${name}_enable
command=/etc/rc.d/{$name}
start_cmd="watchdog"
stop_cmd="stop_watching"
load_rc_config $name
recover_tas() {
$TAS_BIN -agent start-service
RETVAl=$?
return $RETVAL
}
stop_watching() {
monitor=0
}
watchdog() {
while [ $monitor == 1 ]
do
tas_count=`ps -x | grep tas-freebsd.x86_64 | grep -v grep | wc -l | sed 's/ *//g'`
if [ $tas_count -eq 0 ]; then
timestamp=`date`
echo "[$timestamp]TAS shutdown unexpectedly, restarting TAS now..." >> $TAS_LOG
echo $?
recover_tas
else
sleep 10
fi
done
}
run_rc_command "$1"
Your start-up script fails in a couple of respects. service watchtas start does not return to the command line because the daemon process does not detach. service watchtas stop does not work as required because the variable monitor is local to the executing script.
I would separate the start-up script and the watchdog code into separate files and use daemon(8) to monitor the watchdog.
The /usr/local/etc/rc.d start-up script would look like this:
#!/bin/sh
. /etc/rc.subr
name="watchtas"
rcvar=${name}_enable
pidfile="/var/run/${name}.pid"
command="/usr/sbin/daemon"
command_args="-c -f -P ${pidfile} -r /usr/local/sbin/${name}"
load_rc_config $name
run_rc_command "$1"
The /usr/local/sbin/watchtas watchdog code would look something like this:
#!/bin/sh
TAS_BIN="/etc/supermicro/tas-freebsd.x86_64"
TAS_LOG="/etc/supermicro/tas_system_crush.log"
recover_tas() {
$TAS_BIN -agent start-service
RETVAl=$?
return $RETVAL
}
while true
do
tas_count=`ps -x | grep tas-freebsd.x86_64 | grep -v grep | wc -l | sed 's/ *//g'`
if [ $tas_count -eq 0 ]; then
timestamp=`date`
echo "[$timestamp]TAS shutdown unexpectedly, restarting TAS now..." >> $TAS_LOG
echo $?
recover_tas
else
sleep 10
fi
done
It seems you have a daemon watching a daemon watching a daemon.

glassfish start script fails through crontab

I have a created a script to check to see if my glassfish server is running (installed on a freebsd system), if it isn't, the script attempts to kill the java process to ensure it's not hung, and then issues the asadmin start-domain command
If this script runs from the command line it is successful 100% of the time. When it is run from the cron tab, every line runs except the asadmin start-domain line - it does not seem to execute or at least does not complete, i.e. the server is not running after this script runs.
For anyone not familiar with glassfish or the asadmin utility used to start the server, it is my understanding that a forked process is used. could this be causing a problem via cron?
Again, in all my tests today, the script runs to completion when run from the command line. Once it's executed through the cron, it does not complete... what would be different running this from the crontab???
thanks in advance for any help... i'm pulling my hair out trying to make this work!
#!/bin/bash
JAVA_HOME=/usr/local/diablo-jdk1.6.0/; export JAVA_HOME
timevar=`date +%d-%m-%Y_%H.%M.%S`
process_name='java'
get_contents=`cat urls.txt`
for i in $get_contents
do
echo checking $i
statuscode=$(curl --connect-timeout 10 --write-out %{http_code} --silent --output /dev/null $i)
case $statuscode in
200)
echo "$timevar $i $statuscode okay" >> /usr/home/user1/logfile.txt
;;
*)
echo "$timevar $i $statuscode bad" >> /usr/home/user1/logfile.txt
echo "Status $statuscode found" | mail -s "Check of $i failed" some.address#gmail.com
process_id=`ps acx | grep -i $process_name | awk {'print $1'}`
if [ -z "$process_id" ]
then
echo "java wasn't found in the process list"
else
echo "Killing java, currently process $process_id"
kill -9 $process_id
fi
/usr/home/user1/glassfish3/bin/asadmin start-domain domain1
;;
esac
done
Also, just for completeness, here is the entry in the cron tab:
*/2 * * * * /usr/home/user1/server.check.sh >> /usr/home/user1/cron.log
Ok... found the answer to this on another site, but I thought I'd add the answer in here for future reference.
The problem was the PATH!! even though java_home was set, java itself wasn't in the path for the cron daemon.
A quick test to see what path is available to your cron, add this line:
*/2 * * * * env > /usr/home/user1/env.output
From what I can gather, the PATH initially available to cron is pretty minimal. Since java was in /usr/local/bin, i added that to the path right in the crontab and kaboom! it worked!
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
*/2 * * * * /usr/home/user1/server.check.sh >> /usr/home/user1/cron.log