-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 09 '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 09 '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 09 '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 09 '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 09 '17 at 14:04
  • Explaination of the code is: go to a directory of site AA, execute his solr, answer to the console tell the port to use for that site, go to directory of site BB, execute his solr, answer to the console tell the port to use for site BB. All the lines I required. Server details: Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-79-generic x86_64). Please look to the bottom – steplab Jun 09 '17 at 14:05
  • What does this mean: "answer to the console tell the port to use"? Does this mean that when you execute sudo bash solr that you are prompted for a port to use? Do you have to interact with this script/program? If so what do you enter when prompted? The reason I ask is because you don't want to have to [and can't] interact with the boot process so, if you have to interact with these scripts, you may not be able to automate this. – LJKims Jun 09 '17 at 14:13
  • If I execute the prepared file described below server_solr_start.sh it works correctly and do exactly his job. I miss only the way to tell to the server to execute that file each startup. – steplab Jun 09 '17 at 14:17
  • Do you have any stop procedures or do you just shut down the system and let the processes get killed? – LJKims Jun 09 '17 at 14:31
  • If the server shutdown this process shutdown, when the server startup I have to startup process manually; I do not added a crontab or init script to the server. because I don't know how to do it. – steplab Jun 09 '17 at 14:40

1 Answers1

0

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

lkp111138
  • 123
  • 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 09 '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 09 '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 09 '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 09 '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: https://unix.stackexchange.com/questions/47695/how-to-write-startup-script-for-systemd – LJKims Jun 09 '17 at 14:42