Carbon 4.0.1 (BAM 2.0) as a Linux daemon - linux

I am currently evaluating some of the WSO2 servers, one of them is the BAM 2.0 (on the carbon 4.0.1).
So far, in the packages was always a daemon.sh file included, which could be installed with chkconfig as a Linux daemon.
Sadly in the latest version of carbon, the daemon.sh is missing.
The startup script wso2server.sh can be used for starting the service, but it can not be installed as a linux daemon.
chkconfig returns:
[xxx#Server ~]$ sudo chkconfig --add wso2
service wso2 does not support chkconfig
I am trying this on a CentOS release 6.2 - 64 Bit.
Tried to find a description of how to install carbon as a linux daemon in the docs and in the forums - without success.
Thanks.

I rolled my own basic init script for BAM 2.0.0. (The following are parts from a file named 'bam'.)
#!/bin/sh
#
# chkconfig: 2345 80 80
#
BAM_HOME=/home/bam/current_bam
BAM_DAEMON=bin/wso2server.sh
START_OPTIONS=start
STOP_OPTIONS=stop
start() {
echo "Starting BAM... (it will take approx 2 mins.)"
su bam -c "cd $BAM_HOME && $BAM_DAEMON $START_OPTIONS > /dev/null 2>&1"
return 0
}
stop() {
echo "Stopping BAM... (it will take approx 10 secs.)"
su bam -c "cd $BAM_HOME && $BAM_DAEMON $STOP_OPTIONS > /dev/null 2>&1"
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?
Then I copied it to /etc/init.d/ and made it executable. Lastly, I chkconfig'd it.
Now I can start the service with:
sudo service bam start

Related

How to convert sysvinit script to systemd on Manjaro

First, please don't consider this post as a systemd review or critic, but only and simply as a request for help.
Since I've not been able to find a solution to this problem with the systemd documentation, I've this question not solved for almost a year and a half that never ever received any answer.
So, here is the context:
I've a program (/opt/myprog) that can be sarted as a deamon service at boot time.
When using previous Debian, LMDE, Mint or Ubuntu OSes, I used SysVinit with the following script (myprog.sh within the /etc/init.d folder):
MYPROG_PATH=/opt/myprog_64
NAME="myprog"
START="-d"
STOP="-k"
TEST=""
VERSION="-v"
SCRIPTNAME=/etc/init.d/$NAME
STARTMESG="\nStarting $NAME in deamon mode.\n"
UPMESG="\$NAME is running.\n"
DOWNMESG="\$NAME is not running!\n"
TESTMESG="\nStarting NAME in client mode.\nHit Ctrl+C (or close the terminal) to stop mprog.\n"
STATUS=`pidof $NAME`
# Exit if myprog is not installed
[ -x "$MYPROG_PATH/$NAME" ] || exit 0
case "$1" in
start)
sleep 3
echo $STARTMESG
cd $MYPROG_PATH
./$NAME $START
;;
stop)
cd $MYPROG_PATH
./$NAME $STOP
;;
status)
if [ "$STATUS" > 0 ] ; then
echo $UPMESG
else
echo $DOWNMESG
fi
;;
restart)
cd $MYPROG_PATH
./$NAME $STOP
echo $STARTMESG
./$NAME $START
;;
version)
cd $MYPROG_PATH
./$NAME $VERSION
;;
test)
cd $MYPROG_PATH
echo $TESTMESG
./$NAME
;;
*)
echo "Usage: $SCRIPTNAME {start|status|restart|stop|version|test}" >&2
exit 3
;;
esac
:
Now, since it's obvious that systemd will be widely adopted to replace SysVinit including with future Debian, Mint and Ubuntu distros as it's with CentOS, Fedroa or Ach and Manjaro, I've tried to adapt my sysVinit script to systemd with the following script that works but is too limited (myprog.service):
Description=myprog
ConditionFileExecutable=/opt/myprog_64
After=NetworkManager.service
[Service]
Type=oneshot
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
ExecStart=/opt/myprog -d
ExecStop=/opt/myprog -k
ExecRestart=/opt/myprog-k : /opt/myprog -d
TimeoutSec=0
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
However, as systemd is advertised as compatible and more flexible than SysVinit, could anyone show me how to add the three following equivalent switches (status, test and version) that I have defined in the myprog.sh sysVinit script without responding with the classic and inelegant answer: "man is your friend" ?
/opt/myprog status to display the myprog status (i.e. running or not)
/opt/myprog test to start myprog not as a deamon
/opt/myprog version to display the release of myprog
Thank you in advance fo your time and help.
systemd does not support custom implementation of arguments to systemctl.
So systemctl status myprog will show the results based the execution of Exec* settings.
systemctl show myprog uses the Description so you can use a version in your description if desired.
If you wan't to run your program not as a daemon, then you can start it outside of systemd.

Can't access tomcat server on centOS VPS

I got VPS (Virtual Private Server). and I want to install apache-tomcat with this server. the server's OS is CentOS 64bit. I installed through beneath steps.
Step 1. Installing JDK
cd /usr/tmp
wget http://download.oracle.com/otn-pub/java/jdk/8u51-b16/jdk-8u51-linux-x64.rpm
rpm -Uvh jdk-8u51-linux-x64.rpm
Step 2. Installing Tomcat
wget http://apache.tt.co.kr/tomcat/tomcat-8/v8.0.24/bin/apache-tomcat-8.0.24.tar.gz
tar xvfpz apache-tomcat-8.0.24.tar.gz
mv apache-tomcat-8.0.24 /usr/local/tomcat
Step 3. Adding tomcat service
wrote beneath shell code and save into /etc/rc.d/init.d/
and change permission by 'chmod 755 /etc/rc.d/init.d/tomcat'
#!/bin/sh
# Startup script for Tomcat
#
# chkconfig: 35 85 15
# description: apache tomcat 6.x
#
# processname: tomcat
#
# Source function library.
export JAVA_HOME=/usr/java/default
export CATALINA_HOME=/usr/local/tomcat
export PATH=$PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin
# See how we were called.
case "$1" in
start)
echo -n "Starting tomcat: "
$CATALINA_HOME/bin/catalina.sh start
echo
;;
stop)
echo -n "Shutting down tomcat: "
$CATALINA_HOME/bin/catalina.sh stop
echo
;;
restart)
$0 stop
sleep 2
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0
Step 4. Run service
chkconfig –add tomcat
service tomcat start
But... I couldn't see cat on server:8080...
So I found some document saying open 8080 port on iptables.
so I adding this quote
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
But things not changed. still I can't access this server at externally.
Even if I stop iptables, iptables6, Can't acess.
Server IP : 168.92.122.39 Domain : 39.vs.woobi.co.kr
FTP 182.162.94.35:53921 -> 192.168.122.39:21
SSH 182.162.94.35:53922 -> 192.168.122.39:22
MYSQL 182.162.94.35:53906 -> 192.168.122.39:3306
I don't know what is problem. I spend so many time with this. please help me!
Instead of using the iptables command you specified, try the firewall-cmd command (CentOS 7) or lokkit (CentOS 6)
# CentOS 6
lokkit -p 8080:tcp
# CentOS 7
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload
Also check the documentation of your VPS provider. It may be that you must open/forward the port in their user interface as well. I know for example that Amazon requires this.

Supervisord on linux CentOS 7 only works when run with root

I am trying to run a process in the background as a deamon but it only works when I use root as user.
This is what I did.
Installed supervisor as told on their website
$ yum -y install python-setuptools
$ easy_install supervisor
created the config folders
$ mkdir -p /etc/supervisor/conf.d
populate with default settings
$ echo_supervisord_conf > /etc/supervisor/supervisord.conf
add a new user
$ useradd gogopher
on CentOS 7 to make it start automatically I had to do this
$ vim /usr/lib/systemd/system/supervisord.service
added the code below
[Unit]
Description=supervisord - Supervisor process control system for UNIX
Documentation=http://supervisord.org
After=network.target
[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecReload=/usr/bin/supervisorctl reload
ExecStop=/usr/bin/supervisorctl shutdown
User=gogopher
[Install]
WantedBy=multi-user.target
now I can enable it so that it starts on reboot. this all works fine.
$ systemctl enable supervisord
$ systemctl start supervisord
$ systemctl status supervisord
OK
editing the config file to include files from conf.d folder
$ vim /etc/supervisor/supervisord.conf
adding at the end of file
[include]
files = /etc/supervisor/conf.d/*.conf
adding a simple program
$ vim /etc/supervisor/conf.d/goapp.conf
[program:main]
command=/srv/www/websiteurl.com/bin/main
autostart=true
autorestart=true
startretries=10
user=gogopher
$ systemctl restart supervisord
no error, but the process does not work
if I reboot nothing happens
$ systemctl status supervisord
shows that it supervisord is running but not the daemon program.
if I run
$ supervisorctl reload
I get the error
error: <class 'socket.error'>, [Errno 111] Connection refused: file: /usr/lib64/python2.7/socket.py line: 571
if I run
$ supervisorctl status main
I get the error
http://localhost:9001 refused connection
I have already disabled selinux.
but the weird part is that if I change both of them to root, it works.
The executable is able to be executed by user group and others.
So I have no idea what is going on. I have heard that I should not use
root as user that is running a webserver for security reasons.
For all the people out there having the same problem, this works for me.
cd
echo_supervisord_conf > /etc/supervisord.conf
# content of /etc/supervisord.conf ...
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
[inet_http_server] ; inet (TCP) server disabled by default
port=*:9001 ; (ip_address:port specifier, *:port for all iface) - I had all this wrong from my original config.
username=user
password=passwd
Paste this content into /etc/rc.d/init.d/supervisord ( I´m not the owner of this script, by now i don´t remember where i got it from )
#!/bin/sh
#
# /etc/rc.d/init.d/supervisord
#
# Supervisor is a client/server system that
# allows its users to monitor and control a
# number of processes on UNIX-like operating
# systems.
#
# chkconfig: - 64 36
# description: Supervisor Server
# processname: supervisord
# Source init functions
. /etc/rc.d/init.d/functions
prog="supervisord"
prefix="/usr/local/"
exec_prefix="${prefix}"
prog_bin="${exec_prefix}/bin/supervisord -c /etc/supervisord.conf"
PIDFILE="/var/run/$prog.pid"
start()
{
echo -n $"Starting $prog: "
daemon $prog_bin --pidfile $PIDFILE
sleep 1
[ -f $PIDFILE ] && success $"$prog startup" || failure $"$prog startup"
echo
}
stop()
{
echo -n $"Shutting down $prog: "
[ -f $PIDFILE ] && sleep 1 && killproc $prog || success $"$prog shutdown"
echo
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $prog
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
;;
esac
Make the script executable and register it as a service
sudo chmod +x /etc/rc.d/init.d/supervisord
sudo chkconfig --add supervisord
sudo chkconfig supervisord on
# Start the service
sudo service supervisord start
# Stop the service
sudo service supervisord stop
# Restart the service
sudo service supervisord restart

Unable to use service command with debian 8 (Jessie)

In order to install LibreOffice 4.4 into my Debian 8 (Jessie), I just got all my bash scripts from my Debian 7.5 and run them into the same way into the D8 one.
I know there was several changes into the new version but I'm not able to use my service like this anymore :
sudo service libreoffice start
When doing this doesn't start anything and I have to start it using :
sudo /etc/init.d/libreoffice start
And strange thing, when doing (bad parameter) :
sudo service libreoffice dzedjiodjzedj
...the script is perfectly executed and it displays my catched error
Here is my /etc/init.d/libreoffice file :
#
# libreoffice This shell script takes care of starting and stopping the LibreOffice Daemon
#
# chkconfig: - 80 20
#
### BEGIN INIT INFO
# Provides: libreofficedaemon
# Required-Start: $network $syslog
# Required-Stop: $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Init.d script to run a LibreOffice Daemon
# Short-Description: start and stop LibreOffice Daemon
### END INIT INFO
NAME="LibreOffice Service"
LIBREOFFICE_HOME=/opt/libreoffice4.4
LIBREOFFICE_USER=libreoffice
export LIBREOFFICE_HOME LIBREOFFICE_USER
start() {
echo -ne "Starting $NAME. \n"
su $LIBREOFFICE_USER -c "$LIBREOFFICE_HOME/start.sh"
}
stop() {
echo -ne "Stopping $NAME. \n"
su $LIBREOFFICE_USER -c "$LIBREOFFICE_HOME/stop.sh"
}
kill() {
echo -ne "Force close of $NAME. "
killall -u $LIBREOFFICE_USER
}
cd $LIBREOFFICE_HOME
case "$1" in
start|stop)
$1;;
restart) stop; start;;
kill) kill;;
*)
echo "Usage: /etc/init.d/libreoffice {start|stop|restart|kill}"
exit 1
;;
esac
exit 0
And I just run that issue with tomcat8 service yesterday, I just started manually the service and sudo service tomcat8 start worked after that but nothing for libreoffice one..
From the Debian Jessie Release Notes :
When you are asked if any file in the /etc/init.d directory, or the /etc/manpath.config file should be replaced by the package maintainer's version, it's usually necessary to answer “yes” to ensure system consistency
With systemd you now have to use systemctl:
sudo systemctl start libreoffice
Here's some more info

What's the difference? sudo restart

What's the difference between:
sudo /etc/init.d/apache2 restart
and
sudo service apache2 restart
I tried the first one, and it didn't apply my changes, while
sudo service apache2 restart
did uptake my changes.
Here is what is actually happening when you run sudo /etc/init.d/apache2 restart:
if ! $APACHE2CTL configtest > /dev/null 2>&1; then
$APACHE2CTL configtest || true
log_end_msg 1
exit 1
fi
if check_htcacheclean ; then
log_daemon_msg "Restarting web server" "htcacheclean"
stop_htcacheclean
log_progress_msg apache2
else
log_daemon_msg "Restarting web server" "apache2"
fi
PID=$(pidof_apache) || true
if ! apache_wait_stop; then
log_end_msg 1 || true
fi
if $APACHE2CTL start; then
if check_htcacheclean ; then
start_htcacheclean || log_end_msg 1
fi
log_end_msg 0
else
log_end_msg 1
fi
As you can see; first a config test is run, if this is successful the server is stopped and then started.
I find it hard to believe that running this command did not apply your changes if they were properly saved and valid. I only use this command and have never had that issue.
/usr/bin/service is described as:
# A convenient wrapper for the /etc/init.d init scripts.
And it does the following:
SERVICEDIR="/etc/init.d"
# Otherwise, use the traditional sysvinit
if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
exec env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" ${ACTION} ${OPTIONS}
else
echo "${SERVICE}: unrecognized service" >&2
exit 1
fi
So the commands are basically identical, sudo service apache2 restart is just a wrapper for sudo /etc/init.d/apache2 restart.
You may also use sudo /etc/init.d/apache2 reload, this reloads the config without restarting the server. This only works if you have changed config, it will not load modules that you have enabled, for that you need to restart Apache.
Edit: This code is from a Debian system.
In general, whether these two commands are identical or not depends on your Linux distribution.
The first one requires the existence of a traditional SysV-style init script. Until a few years ago that was practically the only way to control services and the service script was just a simple wrapper that basically added the init script path.
These days many Linux distributions have switched to alternative service management systems such as upstart or systemd. Therefore, the service wrapper may also make use of these systems, providing a certain degree of compatibility.
Bottom line: depending on the specifics of your Linux distribution, the /etc/init.d/apache2 may not exist at all, it may just use service itself, or it may do nothing at all. My Mageia Linix system, for example, launches Apache using a systemd service file and has no SysV init script at all for it.
You are generally better off just using service <service> <command>....

Resources