linux deploy, kali, start an app service after its boots up - linux

Hi there does anybody knows how to make an apache2 service to run at startup?
After Kali linux boots up,
I have tried editing rc.local, rc.init and rc file.
Adding
service apache start
command I have also made bash script, giving its permissions to run it with chmod +x b.sh - placed in bin folder for ability to run in anywhere in command line.
I am able to run it in terminal, it does what I need. But can't get it running on start up.
Also I tried:
update-rc.d mystartup.sh defaults 100
still no success. Any ideas?
Thanks.

Place your script inside init /etc/init.d/ , then place a link to it inside /etc/rc5.d/ (be sure to get your accurate run-level)...
Start the second link with the string S71 like S71apastart
I.e do the following:
Place the text:
#!/bin/bash
sudo service apache start
inside /etc/init.d/apaStart (a new file created by you)
Then
sudo chmod +x /etc/init.d/apaStart
sudo ln -s /etc/init.d/tomcat /etc/rc5.d/S71apaStart (change rc5.d to rc3.d if needed depending on your runlevel)
I won't suggest this method but it'll work with your situation.

Related

How to run a sudo command on startup?

I'm trying to connect to my vpn on startup. I normally enter protonvpn c -f into command line.
I have tried the method of creating an rc.local file however it didn't work.
This is the code I have inside of it (I got this from a post about a similar issue):
#!/bin/sh -e
/usr/local/bin/protonvpn c CH-NL#1
exit 0
I also made the file executable with chmod +x.
Im running Kali 2020.1 if that helps.
How do I fix this?
create a file ==> /etc/rc.local
Open and Edit rc.local like below,
replace your command with apt-get update below
#!/bin/sh -e
apt-get update
exit 0
save the edit with Crtl+X
after that
sudo chmod +x /etc/rc.local
then do a reboot and check
It should 100% work like a charm
This solution should work for ubuntu systems.
https://askubuntu.com/a/290107/1051584
Kali is debian based so I believe this will probably work as well.

Command without sudo works but requires sudo

I have already solved this problem but I do not know why this solves the problem and I don't like not knowing what went wrong. I'm using the terminal on Ubuntu
Here was the issue...
If I run $ ngm -args it runs but fails because it requires sudo
If I run $ sudo ngm -args I get the error like ngm not found
If I run $ sudo /usr/local/lib/ngm -args it runs with sudo and works perfectly.
I don't understand why the 3 works and 2 doesn't work.
When trying to run $ ngm -args, the shell will look for the executable in it's $PATH variable, and it finds it. When trying to run the executable it finds that it has to be sudo and exits.
When you run $ sudo ngm -args, the shell will look for the executable in the $PATH environment of the Root user, and it can't find it.
When running it like the last option, the shell doesn't need to look in the $PATH of the root user, because it finds it in the path that you specified /usr/local/lib/ngm, so both issues are gone.
This might be a starting point in order to understand the PATH

cgMiner Auto-Start on Raspbian

I am trying to make cgMiner auto-start when my Raspberry Pi (Raspbian Linux) starts.
Edited the rc.local file:
sudo nano /etc/rc.local
and added this line:
nohup ./cgminer-3.1.1/cgminer --config /home/pi/cgminer.conf -S /dev/ttyUSB0 -S /dev/ttyUSB1 >/dev/null 2>&1&
and cgMiner doesn't start. If I type in terminal the exact same line with sudo in front it works perfectly.
sudo nohup ./cgminer-3.1.1/cgminer --config /home/pi/cgminer.conf -S /dev/ttyUSB0 -S /dev/ttyUSB1 >/dev/null 2>&1&
What can I do?
I think it is related to the path or better the current working directory.
You are using ./cgminer and not a full path. So either use the full path or first cd to the directory containing the cgminer program.
Also have a look at the following page over at adafruit doing the exact same thing you are trying to accomplish
http://learn.adafruit.com/piminer-raspberry-pi-bitcoin-miner/configure-auto-start
Adafruit has the following code in /etc/rc.local
cd /home/pi/PiMiner
python PiMiner.py &
cd ..
nohup ./cgminer-3.1.1/cgminer --config /home/pi/cgminer.conf -S /dev/ttyUSB0 -S /dev/ttyUSB1 >/dev/null 2>&1&
The first and third line (the cd commands) ensure that the folder containing the folder containing the cgminer command is the current directory.
From the two cd commands adding the following command before the line containing the cgminer command would solve your issue
cd /home/pi
I seem to have found the solution for this problem, assuming it is the same as for bfgminer.
After spending a full day playing with init.d scripts, I found the simplest way is to make sure your cgminier.conf file has all the arguments in then add the following to the end of /etc/rc.local
cd /home/YOURNAME/bfgminer
sudo ./bfgminer
It ran without the sudo part, but didn't start up my block erupter without it.
I also managed to get it running from init.d, but had issues with it preventing system rebooting when done that way.
Hope that helps

About setting permissions for scripts

I have a set of update commands that I need to run periodically as per compliance with my university's policies on security. These are the commands :
sudo apt-get clean
sudo apt-get update
sudo apt-get -y --purge dist-upgrade
Now what I want to do is to automate this process. The way I would go about this is to
Set up all these commands as a shell script.
Run the script as a cronjob everyday at 6AM in the morning.
I wrote a shell script named "update_script.sh" and saved it in the home folder. Inside the script was the three commands without the sudo option. Then I changed the ownership of the script to root.
Next I modified the visudo file to allow this script to run without a password.
(I followed the steps in this link)
Now my problem is this :
When I am trying to run this update script as "sh update_script.sh" it cannot run it. Only when I do "sudo sh update_script.sh" it does the job.
Where did I mess up in the setup ?
Well the way you describe it, you have allowed yourself to execute
update_script.sh
with sudo.
Which means that you need to call the script (by your users crontab as I understand it) with
sudo update_script.sh
That means that the script is executed by root, and all the commands within the scripts are executed as root as well.
If you just want to execute the script itself without sudo, but allowing yourself to execute the commands withing the script as root (the apt-get commands in your case), you have to add the commands (again the apt-get in your case) to the sudoers-file. But as I see it, in your case you should just call the whole script with sudo instead.

Running a file as nonroot from a root bash script

Okay, I currently use an eggdrop IRC bot on my server. I want to make a bash script to start it up as well as a few other scripts at the same time. All that's left is to make it start, but it won't run as root.
However, I also need to be in the current directory of the file to run it, or it displays an error.
For example:
/home/eggdrop/eggdropbot/eggdrop will display an error, so to run it I need to
cd /home/eggdrop/eggdropbot and then ./eggdrop
So I can't just use "sudo -u eggdrop /home/eggdrop/eggdropbot/eggdrop" and as you probably know, sudo won't cd, either, since that would be pointless.
Any suggestions?
Why not just cd first and then sudo -u ./eggdrop .?
What about doing the cd, and, only then, launch the command with sudo ?
I suppose something like this should do the trick :
cd /home/eggdrop/eggdropbot && sudo -u eggdrop ./eggdrop
You can cd to the directory as the root user and then use sudo -u to invoke the program from the working directory.

Resources