I run the server.go file using "iTerm2" software from my macbook pro. But as the server's availability depends upon that "iTerm2" running or not it stops working as soon as my macbook pro goes in sleep mode or the iTerm2 software is interrupted in any way. I need my GoLang Server to run 24x7. What do I do? I tried searching on google and since my English is not good I can not find the right answer.
I have been trying to find a solution for this problem from weeks now.
Please help.
Use tmux or screen put the session run in the background.
Or just run your command &; disown
Otherwise, your computer shutting down or getting into sleep will both interrupt or pause the background process, so in real world 24x7, you need a cloud service unless keeping your computer running 24x7.
Related
I created a robot. The robot is run like this :
import os
while True:
print("RUN Script")
os.system("./trading_bot.py")
print("STOP Scriptt")
Actually, it works on my computer then I can stop it by closing the terminal.
However, I would like to put it on my ODROID (kind of raspberry).
I will need to connect through SSH and run the script. However, I am wondering how to stop this infinite loop, because if I close my computer terminal windows, it will not affect what is ran on the ODROID I think... Same question if I loose SSH connection with ODROID, how to get access back to the running script?
I need some explanation about all this works.
I have my own embedded Linux system on PocketBeagle board. I have developed a simple gpio application in C that issues an on/off command to one of the pins of the connectors of the board. The application is called gpio_aa6 and located at /root.
The first challenge was to find a way to launch my application automatically after booting the board. I found two ways to do that; the first was to add an entry to etc/rcS directory. This entry is a simple script file that launches my application. The second way was to edit /etc/inittab file and add an entry to that file (::respawn:/root/gpio_aa6). In both these ways my application was launched successfully: but I am still not sure if this is the right way to launch my application automatically.
Then I came to the second challenge, how can I stop my running application, as the respawn re-launches the application if it's terminated?
I am communicating with the board in two ways; via a serial communication (using screen terminal) and via web sever (root#192.168.42.2). I have tried to use Ctrl+C, Ctrl+Z, Ctrl+\, but couldn't stop the program from being continue running. Then I used command "killall" with killsignals -9 or -15, it seems that the program is interrupted but it's launched again directly after that.
My application is to run infinitely, but I need to stop it sometimes to update it and re-launch it again.
Is there any suggestion how to overcome this problem?
Thanks.
Both solutions you have used are correct. I personally prefer the option of adding an init script to /etc/init.d though.
I believe the behavior that you observe that you apparently can't kill the program is because you are starting your program from inittab, with the respawn keyword, which precisely tells the init program to restart your application when it exits. If you actually check the PID of your application, you will see that it changes everytime you kill it.
Therefore, I would recommend you to use an init script instead, with which you can implement start and stop actions. See ./package/lldpd/S60lldpd for a basic example in Buildroot.
I built an application using openframeworks that is live 24/7 on a kiosk. Every now and then (every few weeks) it will randomly go unresponsive and I still can't get to the bottom of it because it's so random and infrequent it is hard to debug.
I wrote a ruby script that looks for the application running and if it doesn't exist it will start it up. This works in all cases where the application name doesn't show up in activity monitor. Meaning if the app crashes and completely force quits itself or something. It works just fine.
However, if the app just freezes and goes unresponsive (red highlight in activity monitor) the app doesn't quit out completely unless I force quit manually. Is there some kind of script I can write to look for all "unresponsive apps/processes" every few seconds and force quits them automatically? That way my app launcher script will be able to detect that the app isn't running and boot it up again.
I suggest you look at Monit because it's solid, well tested, well documented, and easy to learn.
If you still want to write your own monitoring script, Monit is a good example to follow.
The most reliable way to detect an unresponsive app is to have a "vital sign" which is a generic term for a signal that an app emit to prove it's healthy. Some people call this a "pulse" or "heartbeat" or "brainwave". Your external script watches the vital sign. If your external script sees the vital sign flatline, then the script takes action to cure the app or restart it.
An alternate way is to have a "ping" which is a generic term for your external script sending a signal to the app or the system, then listening for a reply. You can use tools such as the Unix ps command for processes, or AppleScript Activity Monitor. As far as I know, these do a pretty good job of catching common cases, but have trouble catching apps that are soaking up resources, such as being caught in endless loops.
I have a script that I want to execute daily, which requires an Internet connection in order to properly execute. However, my laptop (where the script resides) is not always on, and is not always connected to the Internet.
I want the script to execute at, say, 8:00am every day. However, if the computer is off or not connected to the Internet at 8:00, I want the script to execute at the next available chance.
How can I achieve this using cron, launchd or some other manager? Bonus points if the answer avoids having to fail the job every, say, 5 seconds once the computer turns back on, and until I connect to the Internet and it properly executes.
If it matters, I'm running OSX Mountain Lion.
anacron is probably your answer. It's usually installed on linuxes but is optional, and can be left off if your system administrator decided not to include it. On OS/X, it's a little more challenging, but there are pages on the internet explaining it better than I have room to here. Anacron running from launchd can be done.
On linux the man page should point you in the right direction.
Additionally you can make your script aware of the internet connection with a wget command and interrogate the results. If it's unsuccessful, go into a loop waiting for an internet connection to work with a timer of 10 minutes or whatever makes sense to you.
Hit me up if you need details of how to accomplish any of these tasks.
I am a windows bod most of the time but now there are macs in the mix and I need to support all the blocked apps our company deems unfit to run on their system. In Windows I used a small app I wrote that runs in the background and just kills any window containing a specified title. Could someone please help with a bit of script that would do the same in OS X?
Can't make a script for you, but maybe it would be helpful to includekillall in your search. "The killall utility kills processes selected by name..."