Execute script at each boot - OpenWRT - openwrt

I want to start a shell-script every startup of the openWRT Rooter. But moving it in the etc/init.d directory seems not to work. Want to delete one line in a specific file at every startup. But it does not work.
#!/bin/sh /etc/rc.common
START=80
STOP=85
start(){
grep -vwE "password" /etc/config/glconfig > /etc/config/glconfig
}
What shall i do to execute this (and other) scripts at startup?
Thx for help

In openwrt if you want to run a script on boot you should do:
/etc/init.d/cust_script enable
then reboot the device, it will be effect after reboot.

Related

Docker Compose down. Can I run a command before the actual stop?

I have a setup with docker-compose which creates a screen and runs a process in it.
That's because when I use the docker-compose with -d it will run the process in the background and attaching to the shell will actually give me a new shell.
What I need is the shell with the actual process...
So when I use my docker-compose script I use screen to run the process in a screen instance.
When I open a shell I can connect to the shell of the running process using the screen -r <screen_name> command
But because it is running in a screen the docker-compose down command won't actually stop properly and will stuck while trying to stop. Instead, I need to force the stop and this is not what I want because this is not the proper way of ending the process I have.
So I thought I need a way to define a stop command before the actual stopping happens.
Any tips are appreciated.
PS: Yes, it's Minecraft
EDIT 1: After the comment of Calum Halpin I don't need a screen anymore. So that I now only need a way to pipe something like "exit" to stdin.
EDIT 2: I guess I still need screen. When attaching to the shell I cant escape from there without killing the terminal session and therefore the process...

How to stop/start Neo4j server via .bat script in windows

When running the neo4j server in Linux, we have several commands - start, stop, restart, etc - to control it via the command line.
In windows, the manual simply says:
Usage - Windows
Neo4j.bat
Double-clicking on the Neo4j.bat script will start the server in a console. To quit, just press control-C in the console window.
But how do I stop it if I've started it by executing neo4j.bat from a .bat file of my own, and thus don't have a console window?
For context: I'm working on an unmanaged extension, so I need to rebuild my jar, move it into the plugins directory and restart the server each time I make a change. It'd be a pain in the ass to do this manually, so (when when I was working in Linux) I had Intellij rebuild the artifact and execute a .sh script that moved the resultant jar into /plugins and restarted neo4j.
'/path/to/neo4j/bin/neo4j' stop
rm /path/to/neo4j/plugins/api.jar
mv /project/path/artifacts/graphapi.jar /path/to/neo4j/plugins/api.jar
'/path/to/neo4j' start
How do I do the same in windows using a .bat file?
I've tried this:
del "C:/path/to/neo/plugins/api.jar
move "C:/project/path/artifacts/api.jar" "C:/path/to/neo/plugins/api.jar"
C:/neo/bin/Neo4j.bat
hoping that simply calling Neo4j.bat again would stop the current process and start another, but apparently that's not the case.
If you're on Windows you can stop Neo4j server by executing: neo4j.bat stop
Let me show it in details for those who might be new to the command line:
We need to know where Neo4j is located. If you remember where did you extract it - good, you can skip this step. For others: open Task Manager and look for Commons Daemon Service Runner here how it looks like right mouse click, open Properties and look for its Location path. Find this path in your file manager. We are looking for bin folder with neo4j.bat file.
Open command line and write cd and then paste your path, hit enter. You should jump to that folder with neo4j.bat file.
Stop the server: Type neo4j.bat stop and execute. It will ask for your permission .
after that, you can double check and type 'neo4j.bat status` t be sure it's stopped.
P.S. After Windows reboot neo4j server will be automatically restarted. If you don't want this (it consumes up to 500Mb of memory, at least in my DB ~64k records) you should uninstall the service.
Execute neo4j.bat uninstall-service in that directory.
Cheers!

Starting Erlang service at boot time (using Relx for creating release)

I have a server written in Erlang, compiled with Rebar, and I make a release with Relx. Starts nicely with
/root/rel/share3/bin/share3 start
The next step is to start when the server boots.
I have tried different approaches, the last one is using the /etc/init.d/skeleton where I changed the following
NAME=share3
DAEMON=/root/rel/share3/bin/share3
DAEMON_ARGS="$1"
After that, I run update-rc.d, but I have not gotten it too work. (Ubuntu 14.04)
The service runs until the machine reboots, and I need to login and start it again.
For Windows, it is really elegant, since it can create the Windows service.
Ubuntu uses upstart as init system, so you could try something like that:
description "Start my awesome service"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
exec /root/rel/share3/bin/share3
You have to place this script in /etc/init/ directory with '.conf' extension like '/etc/init/share3.coinf'. To start it invoke sudo start share3.
At last, I solved it!
I have told to relx to place the result at /home/mattias/rel. The script from relx is /home/mattias/rel/share3/bin/share3
Replace the row
SCRIPT_DIR="$(dirname "$0")"
by (you need to fix the path /home/mattias/rel)
HOME=/home/mattias
export HOME
SCRIPT_DIR="/home/mattias/rel/share3/bin"
Copy the file to /etc/init.d/share3 using
sudo cp ~/rel/share3/bin/share3 /etc/init.d/
Test that it works using
/etc/init.d/share3 start
and
/etc/init.d/share3 stop
In order to make it start at boot, install sysv-rc-conf
sudo apt-get install sysv-rc-conf
Enable boot at start using
sudo sysv-rc-conf share3 on
and disable
sudo sysv-rc-conf share3 off
Alternatives are welcome.

Run new ant target without killing previous target

I've got an ant target ant server that runs a Java application which logs to the console. I need to run a new ant target ant server-gui which also logs to the console. But when I run ant server the logging prevents me from running any new ant targets.
When I enter ^c (which is the only way I know of to get out of situations like that) it kills the Java application. I need both to run. What keystroke will get me out of that "input" mode and able to run new terminal commands?
UPDATE: I haven't found a direct solution to getting out of that mode I mentioned, but opening a new tab/window in terminal does the trick. I can run as many any commands as I'd like that way. Still looking for a good solution to get out the "input" mode, though!
UPDATE 2: #abcdef pointed out another post that has an even more elegant solution.
There are a few ways to do this, assuming you are on *nix
1) Run the ant command with a & at the end to tell *nix to run the command in the background
2) Run the command with nohup at the beginning (https://en.wikipedia.org/wiki/Nohup)
3) when the process is running press ctrl-z then enter the command bg. This manually forces the command to run in the background
I hope this helps you out

Run ruby script in background without using screen

I have a two scripts in the Rails environment which have to run 24/7. I'm working on a remote server, so I need to start the scripts using ssh, which means I need to keep the ssh windows open all the time.
I'm searching for a simple way to run these scripts in the background so they aren't canceled as soon as I close the ssh connection.
I don't want to use screen. I think there must be simpler way to handle this. Isn't there?
I think the most basic solution would be nohup:
nohup myscript &> /dev/null &
You can disown a script:
ruby script.rb &!
STDOUT/STDERR are still attached to the current shell, but the ruby process isn't a child of the shell anymore, so it won't get killed if you close the terminal.
Check Daemons. It's a toolkit for converting a script to a controllable daemon.
You can use
runit
supervisord
For daemonizing
Or some ruby stuff: https://www.ruby-toolbox.com/#Background_Processing for background processing

Resources