When my ubuntu server boots up, tomcat7 does not run (I cannot open localhost:8080)
When I ssh into my server, I am able to open localhost:8080
When I close my ssh connection, tomcat stops working again
I have this startup script in the init.d:
export JAVA_HOME=/usr/lib/jvm/java-7-oracle
export CATALINA_HOME=/home/knowroaming/apache-tomcat-7.0.34
/etc/init.d/tomcat7.sh start
I also have symbolic links to this script in the /etc/ (rc1.d to rc5.d) directories.
Any ideas?
The following is from howtogeek.com and relates to tomcat 6 but I've used the instructions with tomcat7
http://www.howtogeek.com/howto/linux/installing-tomcat-6-on-ubuntu/
Automatic Starting
To make tomcat automatically start when we boot up the computer, you can add a script to make it auto-start and shutdown.
sudo vi /etc/init.d/tomcat
Now paste in the following:
# Tomcat auto-start
#
# description: Auto-starts tomcat
# processname: tomcat
# pidfile: /var/run/tomcat.pid
export JAVA_HOME=/usr/lib/jvm/java-6-sun
case $1 in
start)
sh /usr/local/tomcat/bin/startup.sh
;;
stop)
sh /usr/local/tomcat/bin/shutdown.sh
;;
restart)
sh /usr/local/tomcat/bin/shutdown.sh
sh /usr/local/tomcat/bin/startup.sh
;;
esac
exit 0
You’ll need to make the script executable by running the chmod command:
sudo chmod 755 /etc/init.d/tomcat
The last step is actually linking this script to the startup folders with a symbolic link. Execute these two commands and we should be on our way.
sudo ln -s /etc/init.d/tomcat /etc/rc1.d/K99tomcat
sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat
Tomcat should now be fully installed and operational.
Related
I have a very peculiar case of ASP.NET Core APIs running on my Linux.
I have two environments
PROD - https://somesite.com - UI and it's API endpoint - https://somesite.com/api
DEV - https://somesite-dev.com - UI and it's API endpoint - https://somesite-dev.com/api
Both UIs are served by nginx on port 80 and 443 and their respective APIs are using nginx reverse proxy to port 5000 and 1880 since they are .NET Core API on the same AWS EC2 instance
Now I have all my command required to restart these two .NET Core APIs - DEV and PROD - in rc.local
Following is my rc.local content:
#!/bin/sh
REM This script will be executed *after* all the other init scripts.
REM You can put your own initialization stuff in here if you don't
REM want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
sudo service nginx stop
REM DEV -------------------------------------------
REM Removing previous Error and Output files.
sudo rm /etc/somesite/somesite_dev/Output2.out
sudo rm /etc/somesite/somesite_dev/Error2.err
REM Starting the BG process.
sudo nohup /etc/somesite/somesite_dev/somesite_core_api_dev >
/etc/somesite/somesite_dev/Output2.out 2> /etc/somesite/somesite_dev/Error2.err < /dev/null &
REM Changing Error and Output files permission and Ownership.
sudo chmod 777 /etc/somesite/somesite_dev/Output2.out
sudo chmod 777 /etc/somesite/somesite_dev/Error2.err
sudo chown ec2-user:ec2-user /etc/somesite/somesite_dev/Output2.out
sudo chown ec2-user:ec2-user /etc/somesite/somesite_dev/Error2.err
REM ----------------------------------------------
REM PROD -----------------------------------------
REM Removing previous Error and Output files.
sudo rm /etc/somesite/somesite_prod/Output3.out
sudo rm /etc/somesite/somesite_prod/Error3.err
REM Starting the BG process.
sudo nohup /etc/somesite/somesite_prod/somesite_core_api_prod >
/etc/somesite/somesite_prod/Output3.out 2>
/etc/somesite/somesite_prod/Error3.err < /dev/null &
REM Changing Error and Output files permission and Ownership.
sudo chmod 777 /etc/somesite/somesite_prod/Output3.out
sudo chmod 777 /etc/somesite/somesite_prod/Error3.err
sudo chown ec2-user:ec2-user /etc/somesite/somesite_prod/Output3.out
sudo chown ec2-user:ec2-user /etc/somesite/somesite_prod/Error3.err
REM ----------------------------------------------
REM Force Stoping and Starting nginx
sudo service nginx start
When the system reboot I see the API running as a BG process but I get 400 Bad request
But When I start the same API from the terminal using the same command in the file i.e
For PROD -sudo nohup /etc/somesite/somesite_prod/somesite_core_api_prod > /etc/somesite/somesite_prod/Output3.out 2> /etc/somesite/somesite_prod/Error3.err < /dev/null &
For DEV - sudo nohup /etc/somesite/somesite_dev/somesite_core_api_dev > /etc/somesite/somesite_dev/Output2.out 2> /etc/somesite/somesite_dev/Error2.err < /dev/null &
The APIs work fine the I get 200
I am not sure what I am missing here, if anyone can help.
Thanks
REM is the comment command for DOS. In Linux, you start a comment with # . In Linux, REM is an unknown command and will cause the script to abort. Have you looked in the syslog for errors?
rc.local runs as root. None of those sudos are necessary. And rc.local doesn't run in a terminal, so the nohup lines are not needed.
Don't make text files executable. Do chmod 644, not chmod 777.
There's no need to remove the previous log files. Your redirects will overwrite them. Plus, your "rm" will fail if the files don't already exist.
Don't start nginx that way. I don't know what distribution you're using, but there are well-defined ways to say "nginx must start at boot time". That's what you should be using to start somesite_core_api_dev, but we can let that go.
I am a new Ubuntu user.
Recently, I try to set up a server on Ubuntu.
I am wondering how to write a automatically script to run a series of script one by one.
For example, I need to install squid first, after that I need to make a copy of config file then modify the file. The following are the steps that I write in the command console. I wonder how to make a script to run that automatically.
sudo apt-get install squid -y;
cd /etc/squid3;
sudo cp squid.conf squid.conf.bak;
sudo rm -rf squid.conf;
sudo nano squid.conf
Just add a shebang, place everything in a ".sh" file, make the file executable, and run it...
Save this as test.sh
#!/bin/bash
sudo apt-get install squid -y;
cd /etc/squid3;
sudo cp squid.conf squid.conf.bak;
sudo rm -rf squid.conf;
sudo nano squid.conf
Make it executable chmod +x test.sh
Run it... ./test.sh
To edit the file from a terminal
Get a terminal on the box where you want the script to live. Probably you will SSH into it.
Then just cd to the path you want the script to live and do the following...
nano test.sh This opens the nano terminal text editor.
Copy the above test.sh commands, make sure to get the shebang (#!/bin/bash).
Paste the script into the nano editor, you'll need to use ctrl+v or cmd+v.
Hit the key combination of ctrl + o, hit the enter key.
Hit the key combination of ctrl + w. This exits nano. Proceed with the abov instructions.
I suggest you read up on nano so you can get more familiar with its abilities as it can save a lot of time!
I have wrote some script for my VPS and this is a example for Squid3
#!/bin/bash
function add_user () {
while true; do
echo -e "\nInsert a name for the Squid3 user (0=exit): \c"
read utente
case "$utente" in
0)
echo -e "\nGoodbye $USER!\n"
exit 0
;;
*\ *)
echo -e "\nYou can't use spaces in the name!"
sleep 2
continue
;;
*)
break
;;
esac
done
if [ ! -e '/etc/squid3/.passwd' ]; then
sudo htpasswd -c /etc/squid3/.passwd $utente
else
sudo htpasswd /etc/squid3/.passwd $utente
fi
}
function installer () {
sudo apt-get install squid3 apache2-utils -y
sudo bash -c "echo 'here
you
must
paste
your
configuration
file' > /etc/squid3/squid.conf"
sudo service squid3 restart
}
if ! [ "$(sudo which squid3)" ]; then
installer
add_user
else
add_user
fi
First run it install squid3 and apache2-utils (for htpasswd) and after make a new user.
If you run it again you can add more users.
I have a game server on my VPS, but i have a strong problem. When it reboots(for technical reasons or something) the game server doesn't start automatically. I use this script, which is located in /home/steam/csgo-ds:
#!/bin/sh
ln -s /home/steam/csgo-ds/csgo/*.dem /var/www/html/
ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock
cd /home/steam/csgo-ds
chmod 777 * -R
screen -S "CS:GO Server" ./srcds_run -game csgo -usercon +game_type 0 +game_mode 0 -tickrate 64 -maxplayers 24 -maxplayers_override 24 +ip 188.116.46.148 -port 27015 +sv_setsteamaccount "XXXXX" -exec server.cfg +tv_enable 1 +tv_maxclients 0 +tv_port 27020 +tv_advertise_watchable 0 +map jb_dust2_final2
I have tried adding it to crontab, startup files and a lot more and nothing worked.
Operating system on the VPS is Ubuntu Server 64-bit 14.04 upgraded to 16.04
Ubuntu 16.04 uses systemd as init system, Follow these steps:
chmod 744 /path/to/script
Now create a unit file:
vim /etc/systemd/system/csgo.service
[Unit]
Wants=network-online.target
After=network-online.target
[Service]
ExecStart=/path/to/script
[Install]
WantedBy=default.target
Set permissions:
chmod 664 /etc/systemd/system/csgo.service
Reload and enable the service:
systemctl daemon-reload
systemctl enable csgo.service
Now reboot and test it out.
there are different ways of doing this , the easiest way is to put 5 line of your code in :
/etc/rc.local
it will be executed automatically on each os boot
you should put your lines of code under this line:
exit 0
This is the code I'm using for chef to create a group tomcat in a vm and then a user tomcat but i would like for tomcat to be an unprivileged user and not have a home directory.
I see it has a home directory when i run the command "cat /etc/passwd"
execute "groupadd tomcat" do
end
execute "sudo useradd tomcat -g tomcat -m -s /bin/bash" do
end
Is there something i need to add or take away from this?
When I run a script such as this:
ssh -t root#10.10.10.10 '/tmp/somescript.sh'
where the script is defined as:
#!/bin/sh
mkdir -p /data/workday/cred
chown -R myuser:myuser /data
su myuser - # <------- NOTICE THIS ! ! ! !
rpm -Uvp --force --nodeps --prefix /data/place /data/RPMs/myrpm.rpm
Notice the above su command.
If I comment-out the su command, the script runs remotely and then my shell prompt returns to where I came from ( same server where I ran the ssh command above )
But leaving the script as listed above, causes the script to complete successfully but the shell prompt stays on the remote server.
How can I prevent that ? Making sure that the issuer of the rpm command is a different user than root just a listed ?
But leaving the script as listed above, causes the script to complete successfully but the shell prompt stays on the remote server.
Not exactly. The script is running up to the su command, which spawns a new subshell, and stopping there until you exit the shell. Until you exit that shell, the rpm command never runs, and when it does, it runs as root.
If you want to run the rpm command as a non-root user, you'd need to do something a little different, like:
sudo -u myuser rpm -Uvp ...
add 'exit' at the end of your script