-1

Now I'm testing a Linux server; after the boot of the server machine I have to run these commands by SSH connection (with putty):

cd ../var/www/html/tbl/libraries/solr/bin/
sudo bash solr
./solr start -p 8984
cd ../../../../upms/libraries/solr/bin/
sudo bash solr
./solr start -p 8988

These commands must be executed every time the server boot. There is a way to do these commands not manually but automatically when the server start?

I have to do a crontab or create a bash file?

Server details: Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-79-generic x86_64)

  • What's the point of the sudo bash solr commands? – LJKims Jun 9 '17 at 13:42
  • Why that question @LJKims? Is a row of the code I have to execute, I execute a file inside that directory. – steplab Jun 9 '17 at 13:52
  • The following line ./solr start -p 8988 seems like the execution of the same command but now with [possibly] a port specified. It just seemed redundant. Understanding what is happening may help give better direction on how to create a daemon/init for this work. – LJKims Jun 9 '17 at 13:54
  • Sorry don't look that part of the code, can you answer to my question: create an init script or a systemd job as you suggest – steplab Jun 9 '17 at 13:57
  • That's what I'm trying to do but I need to understand what your requirements and limitations are. What distro/version of Linux are you using? Which lines of your code are REQUIRED to make your job work? – LJKims Jun 9 '17 at 14:04
0

Save your commands to a script, then add @reboot /path/to/script. Remember to chmod +x your script.

  • Server answer No command '@reboot' found, ... @reboot: command not found. Server details: Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-79-generic x86_64) – steplab Jun 9 '17 at 10:27
  • My bad. The @reboot shouldn't be added to your script, but your crontab, which can be edited by running crontab -e – lkp111138 Jun 9 '17 at 12:11
  • Why not turn these into an init script? These seem to be system services which would make the most sense as init (or systemd) jobs. – LJKims Jun 9 '17 at 12:57
  • Hi @LJKims how to do an init script? I created a file inside /var/www/html/server_solr_start.sh ` #!/bin/bash cd tbl/libraries/solr/bin/ sudo bash solr ./solr start -p 8984 cd ../../../../upms/libraries/solr/bin/ sudo bash solr ./solr start -p 8988 ` Where i have to move that file, maybe inside /etc/init.d ? So I have to change the code into this?: ` #!/bin/bash cd ../../var/www/html/tbl/libraries/solr/bin/ sudo bash solr ./solr start -p 8984 cd ../../../../upms/libraries/solr/bin/ sudo bash solr ./solr start -p 8988 ` So this will run each startup? Thanks – steplab Jun 9 '17 at 13:37
  • This link may help you. Since you have created script server_solr_start.sh you could create a systemd service file as described here: unix.stackexchange.com/questions/47695/… – LJKims Jun 9 '17 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.