Command in supervisord failing 'stdout_log and system command' - linux

I have a c++ executable which I monitor using supervisord. And I made supervisord as startup process. When I reboot, supervisord and my executable are working fine (functionally). And Stdout_log file is created in tmp (which is also fine). But the log file is empty.
And In my executable I am running few bash scripts which I do it using system(), but It is also failing.
So I have two issues
log file is empty
system() is failing
I can related these issues to some permission, but no clue to fix it. Looking for some suggestion
Thanks

If your executable cannot be run as root itself, run it as as non-privileged user instead.
Either configure all of supervisord to run as another user by setting the [supervisord] user option:
[supervisord]
user = wwwdata
or set a user parameter for your executable in it's [program:x] section:
[program:yourprogram]
user = wwwdata

Related

Autostart a node.js script using init.d in Debian

I have a little node application on a server (node mailer) that I run by going to its source folder and executing npm start. I figured the best way to run this automatically would be to create a my_script.sh file and drop it in the init.d directory of my debian box. Inside the file (below the !#/bin/bash line), the code to execute is
'/opt/mycode/source/npm start'
I save the line to the .sh file and restarted the machine, but so far haven't got it to work. My question is: is this even how you start a script like this (using that command and an .sh file)? It does start normally when I do it manually (when I navigate to it and run npm start in the terminal). I included the single quotes around it because of the space between npm start. Also, if I want to verify that it worked, which process would I look for other than just pinging my smtp mailer? Finally, I know I need to run:
update-rc.d my_script.sh defaults
but I was also confused at to whether I had done this correctly either (is it just the name of the file that goes there or the file plus the extension)?
The script that you leave on the init.d folder should not have any extension and should have functions to start, stop and get the status of the service (your application).
I'll leave a link with an example as well as with some basis in order to build the Linux service script.
I would suggest reloading the daemon with systemctl daemon-reload in order to refresh the Linux service files once you add a new one.

Start script on linux startup

I try to execute a java application at startup in a yocto based linux device. I added a script at /etc/init.d/etic and made it executable. If I call at the shell /etc/init.d/etic start or /etc/init.d/etic stop the application is started an stopped as expected. Then I called on the shell update-rc.d etic defaults and the symlinks were created. According to what I found on the web, this should be enough, but somehow the application is not started. What did I miss? How could I check what is going wrong or is there any minimal example which should work which I can try to extend?
Well, often such issues are due to a different environment when executing the start script by hand, as compared to when it's being run from the init system. For instance, your .profile and .bashrc won't have been sourced, when running from the init system.
You can use eg logger to easily log things from your init-script, and this rather easily find out what goes wrong.

Daemonize a perl script at startup Linux

I have a custom version of CENTOS that I need to run a perl script as a daemon in at all times.
To do this I want to get it to run on startup as a daemon.
When the machine is on I can daemonize the script with the command
daemonize /var/myfolder/myscript.pl
And this works fine.
So I have an rc1 script which has a number of commands that run when the machine starts, and the very last line in it is where I try to daemonize that script. Everything else in the rc1 script runs fine, and the script doesn't output any errors, however when I check to see if the daemon is running on start up, it isn't running.
Is there another way that I can get the script to run on startup? Or any ideas on why this method doesn't work?
Proc::Daemon offers what you're looking for.
See this previously asked question: How can I run a Perl script as a system daemon in linux?
The problem was that #INC hadn't fully loaded all of the modules by the time my script was called, and so my daemon wasn't running. I used the PERL5LIB command to add the appropriate directories.
PERL5LIB='/perl:/custom/lib:/usr/local/lib64/perl5' /var/myfolder/myscript.pl &
where /perl; /custom/lib and /usr/local/lib64/perl5 are the directories which were missing from #INC

How to start application after login on CentOS?

I am trying to start GUI application with upstart script on CentOS. I have test script located /etc/init/ folder.
start on desktop-session-start
stop on desktop-shutdown
respawn
script
export DISPLAY=:0
sleep 5
exec /.1/Projects/UpstartTest/start.sh &
end script
start.sh scripts is running binary files for GUI application.
After reboot my computer. When I typed:
[root#mg-CentOS ~]# initctl status test
test stop/waiting
So my upstart is not runnig. When i type
initctl start test
manually it works fine without any problem.
How can I run this upstart script after user login (desktop started) ? I am trying to find detailed documents for CentOS for upstart but there is no.
For this purpose, you can use the update-rc tool, which is builtin on linux distributions. It basically creates a symbolic link for the script you want to be executed at startup, or some other OS states, on the folder rc.X, where X is the number of the folder that determines a state that you want.
You may want to have a look at this answer: Update-rc.d custom script running too late, and also runs at shutdown
More information about can be found here:
http://www.linux.com/news/enterprise/systems-management/8116-an-introduction-to-services-runlevels-and-rcd-scripts
Detailed information about the CentOS booting process can be found here: https://www.centos.org/docs/5/html/Installation_Guide-en-US/s1-boot-init-shutdown-process.html;
the rc is being explained at this document as well.

Tomcat deploy: make included scripts executable

I'm devellopping a WebApplication (for Tomcat) using netbeans on Windows 7. For the Webapplication to run I need to run a insall-script once.
This script (*.bat for windows and *.sh for linux is included in my war-file (WEB_INF).
Now everytime I deploy the WAR-file and want to run the script on linux I have to call
chmod +x install.sh
first.
Is there a way that this script can be made executable by default? I don't want to have to execute some extra commands after the deploy to make the script executable.
For clarification:
I'm not new to Linux and I know how to set executable-rights on files. That's not the problem. My problem is: What do I have to do, so that this script is executable right after tomcat deployed my *.war-file (unpacked it). If I would be using Linux for development as well, I would try to set the rights according in my sources (maybe I'll try it when I have a little more spare time). But I am using Windows and netbeans.
Are there any attributes I can set to achive my goal, or is it possible to achive this using ant?
By the way: Are there security related issues with this approach? The script looks for java executable and calls a javabased GUI-installer...
Change permissions during initialization of the application, the following:
String [] command = {"/bin/chmod","+x",full_path_to_install.sh};
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec( command );
pr.waitFor();
allows your application to set executable permissions before using the script. It is not executable right after tomcat deployed your war file but just before your application uses it.
Assuming you are invoking the same "install.sh" everytime, you need to set the execute bit only once. Also, the executable bit need to be set only for the user (the command you have provided will set it for everyone).
chmod u+x install.sh

Resources