-1

We have an application and to get that started we need to do steps each time the server gets security patches. I wonder if it is possible to start the application automatic each time the server boots.

Currently we are doing this: Login in to the server with putty sudo su - user

Now is the tricky point, during this "sudo su - user", the .profile of user is loaded and in this .profile this is done: export JAVA_HOME="/opt/java" . /opt/application/config/profile umask 077

And then we start the applications: /opt/tomcat/bin/startup.sh /opt/config/start /opt/config/start-base prod

Does anybody know if this is possibe? The last three steps are no problem but I don't know about the step that is done about loading the extra profile that is in the .profile of the user "user".

Is it possible to put this all into a script, so that we only have to execute the script during the startup of the server?

fabje
  • 29
  • 1
  • 7
  • 1
    What distribution do you have? – KamilCuk Nov 19 '19 at 12:03
  • 1
    This is possible by creating a service that runs your process. The service starts as root, so you can setup your environment as needed, and then sudo into the respective user and run the java application. Research the use of Linux's systemd services – Shloim Nov 19 '19 at 12:03
  • @KamilCuk We are using Red Hat 3.10.0-1062.4.1.el7.x86_64 – fabje Nov 19 '19 at 12:40
  • Red Hat has toooons of documentation, see it first. Ex. my 30 second google search result https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/5/html/installation_guide/s1-boot-init-shutdown-run-boot – KamilCuk Nov 19 '19 at 12:42
  • @KamilCuk I think I need to create a file /opt/startup.sh with this: ``#!/bin/bash /opt/tomcat/bin/startup.sh & /opt/config/start & /opt/config/start-base prod & exit 0`` Then I create a file here: /etc/systemd/system/application.service with: ``[Unit] Description=Application After=network.target StartLimitIntervalSec=0 [Service] Type=simple Restart=always RestartSec=1 User=user Group=group ExecStart=/usr/bin/bash /opt/startup.sh [Install] WantedBy=multi-user.target`` But what about the JAVA_HOME and ``. /opt/application/config/profile`` how can I add those? – fabje Nov 19 '19 at 13:06
  • `how can I add those? ` - just add it to your /opt/startup.sh file. Your service is not `Type=simple`, rather `Type=forking`. It would be way-way better to do one service per service file and also properly model dependencies between them. [systemd.service](https://www.freedesktop.org/software/systemd/man/systemd.service.html) has much help and big documentation and you should find many resources online. Also you could from systemd service `Environment= JAVA_HOME=something` and `EnvironmentFile= /opt/application/config/profile` depending on your needs and what you actually want to do. – KamilCuk Nov 19 '19 at 13:10

1 Answers1

-1

Try to use cron daemon.

sudo corntab -e 

This will open a kind of editor, then, you have to write these lines:

@reboot  /opt/tomcat/bin/startup.sh
@reboot  /opt/tomcat/bin/startup.sh
@reboot  /opt/config/start-base prod
  • You are missing this part that is needed, before starting the rest:`` export JAVA_HOME="/opt/java" . /opt/application/config/profile umask 077`` – fabje Nov 19 '19 at 12:42