I have created the init.d script below for my C# windows service to be executed on an Amazon Linux EC2 Instance. I hope Amazon linux is based on fedora linux.
I have below init.d script and I googled and found the script.
but if I start the service using the following command:
sudo service amaziersysd start
I am getting below error message:
cat: /tmp/amaziersysd.lock: No such file or directory
Pls note : I am newbie in setting up mono, and I am running mono 3.2.3 built from source.
#!/bin/sh
daemon_name=amaziersysd
if [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
. /etc/rc.d/init.d/functions
else
exit 0
fi
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/mono/mono-service2
NAME=amaziersysd
DESC=amaziersysd
MONOSERVER=$(which mono-service2)
MONOSERVER_PID=$(cat /tmp/amaziersysd.lock)
case "$1" in
start)
stat_busy "Starting amaziersysd"
if [ -z "${MONOSERVER_PID}" ]; then
${MONOSERVER} -l:/tmp/amaziersysd.lock /etc/amazierlb/sysdaemon/Amazier.CollectSysStat.exe
stat_done
else
echo "amaziersysd is already running!"
stat_fail
fi
;;
stop)
stat_busy "Stopping amaziersysd"
if [ -n "${MONOSERVER_PID}" ]; then
kill ${MONOSERVER_PID}
rm /tmp/amaziersysd.lock
stat_done
else
echo "amaziersysd is not running"
stat_fail
fi
;;
restart)
$0 stop
sleep 1
$0 start
stat_done
;;
*)
echo "usage: $0 {start|stop|restart}"
esac
exit 0
Related
The second day I beat my head against the wall and can not figure it out.
How it is possible to implement this dll, any mistakes constantly jump out.
I tried many different options that are on the Internet. Nothing helped.
Help me figure out how to solve the problem.
How to implement Newtonsoft.Json in my project via ILMerge?
Thank you in advance.
Error:
leave command
""C:\Users\User\Desktop\FastFoodDemo\ILMerge\merge_all.bat"
"C:\Users\User\Desktop\FastFoodDemo\"
"C:\Users\User\Desktop\FastFoodDemo\FastFoodDemo\bin\Debug\RCC.exe"
Debug" with code 1. FastFoodDemo
Event final assembly:
"$(SolutionDir)\ILMerge\merge_all.bat" "$(SolutionDir)" "$(TargetPath)" $(ConfigurationName)
merge_all.bat
#ECHO OFF
rem # set .NET version and output folder name
set net="v4, C:\Windows\Microsoft.NET\Framework\v4.0.30319"
set output=Output
rem # process arguments
set ILMergeSolution=%1ILMerge\ILMerge.exe
rem # determine programm files of x86 for 32 and 64 Platform
IF EXIST "%PROGRAMFILES(x86)%" set prorgammFiles=%PROGRAMFILES(x86)%
IF NOT EXIST "%PROGRAMFILES(x86)%" set prorgammFiles=%PROGRAMFILES%
rem # if ILMerge.exe not in the $(SolutionDir)ILMerge\
rem # then try to use installed in prorgammFiles
IF EXIST %ILMergeSolution% set ILMerge="%ILMergeSolution%"
IF NOT EXIST %ILMergeSolution% set ILMerge=%prorgammFiles%\Microsoft\ILMerge\ILMerge.exe
set target_path=%2
set target_file=%~nx2
set target_dir=%~dp2
set ConfigurationName=%3
rem # set output path and result file path
set outdir=%target_dir%%output%
set result=%outdir%\%target_file%
rem # print info
#echo Start %ConfigurationName% Merging %target_file%.
#echo Target: %target_path%
#echo target_dir: %target_dir%
#echo Config: %ConfigurationName%
rem # recreate outdir
IF EXIST "%outdir%" rmdir /S /Q "%outdir%"
md "%outdir%"
rem # run merge cmd
#echo Merging: '"%ILMerge%" /wildcards /targetplatform:%net% /out:"%result%" %target_path% "%target_dir%*.dll"'
"%ILMerge%" /wildcards /targetplatform:%net% /out:"%result%" %target_path% "%target_dir%*.dll"
rem # if succeded
IF %ErrorLevel% EQU 0 (
rem # clear real output folder and put there result assembly
IF %ConfigurationName%==Release (
del %target_dir%*.*
del %target_dir%*.dll
del %target_dir%*.pdb
del %target_dir%*.xml
del %target_dir%*.*
copy %result% %target_dir%
rmdir /S /Q %outdir%
set result=%target_path%
#echo Result: %target_file% "-> %target_path%"
) ELSE (
#echo Result: %target_file% "-> %result%" )
set status=succeded
set errlvl=0
) ELSE (
set status=failed
set errlvl=1
)
#echo Merge %status%
exit %errlvl%
I have a batch file that calls C# program. This C# program makes call to SQL Server database.
Sometimes it is unable to connect to the database and the exception handler prints stack trace and exits c# program. I want to try to run this program maximum of 5 times.
If it succeeds (before 5 tries) then go to next step (CheckStatus) else Error out and quit.
When I run this, It is printing %ERRORLEVEL% as zero even when C# program has an error.
#ECHO OFF
SET Header=-----------------------------------------------------
SET Logfile=C:\LOG\log.txt
set %ERRORLEVEL% = 0
echo %header%
ECHO Running the batch file >> %Logfile%
if '%1' == '' goto usage
if '%2' == '' goto usage
if '%1' == '/?' goto usage
if '%1' == '-?' goto usage
if '%1' == '?' goto usage
if '%1' == '/help' goto usage
SET SQLServer=dbsql\production
SET SQLUser=user1
SET SQLPass=pwd1
SET SQLCommandMaster=osql -S%SQLServer% -n -U%SQLUser% -P%SQLPass% -b -i
GOTO %1%
:Start
Set count=0
:RunCSharpProgram
set /a count+=1
ECHO starting RunCSharpProgram count >> %Logfile%
timeout /t 10
SET RunningStep="RunCSharpProgram"
start "" "C:\CSharpProject\GetData\GetData\bin\Debug\GetData.exe"
ECHO %ERRORLEVEL% >> %Logfile%
IF %ERRORLEVEL% ==1 and count LEQ 5 (GOTO RunCSharpProgram)
IF %ERRORLEVEL% ==1 and count EQ 5 (GOTO error)
IF %ERRORLEVEL% ==0 (GOTO CheckStatus)
:CheckStatus
ECHO Check Status of tables >> %Logfile%
REM %SQLCOMMANDMASTER% /Q "EXEC TestDB.dbo.CheckStatus"
goto end
:usage
echo Usage: %0 'start step' 'end step'
goto end
:error
REM ---------------------------------------------------------------------
ECHO ERROR RUNNING BatchFileTest.BAT >> %Logfile%
:end
echo %header% >> %Logfile%
echo END >> %Logfile%
Not sure what is wrong with this batch file.
Thanks
MR
When you use start, it would start a new shell to run your program.
Official documentation
Starts a separate Command Prompt window to run a specified program or command.
Since it is a separate command prompt you will NOT get back the error codes. So, simple solution do not use the start
instead of
start "" "C:\CSharpProject\GetData\GetData\bin\Debug\GetData.exe"
you can just use
"C:\CSharpProject\GetData\GetData\bin\Debug\GetData.exe"
I started bash (cygwin) from C# and I for that purpose created a new process from C:\\cygwin64\\bin\\bash.exe with the arguments --login -i. I've also redirected its output.
Bash runs, but the output contains unexpected characters like [0m[37;1m or [0m> or [K> or even > (there is an ESC character before all of these but stackoverflow does not seem to let it be displayed). This is unexpected cause I don't seem to see any of these characters from the mintty program.
Why is this happening? Where are these characters coming from? How can I prevent them from appearing?
The unexpected characters are escape sequences used to format text output (concerning the terminal emulator). (See Wikipedia: terminal emulator for more about this.)
In detail, the output of prompt may be configured using certain bash variables, namely PS1, PS2, PS3, PS4. In How to change bash prompt color based on exit code of last command?, the effect of modifying them (just for fun) is shown.
In your case, the call of bash should source a special script which re-defines them simply without any escape sequence. Thus, you could get rid of the undesired formatting. This may help: SO: Running a custom profile file on remote host but this seems also promising: Is it possible to start a bash shell with a profile at a custom location, in a one liner command?.
Writing this, I remembered that certain commands (e.g. ls) support colored output also. As I was not sure I tried this:
$ mkdir test ; cd test ; touch test1 ; ln -s test1 test2 ; mkdir test3 ; touch test4 ; chmod a+x test4
$ ls --color
test1 test2 test3 test4
$
I do not know how to format it with colors here but, on my xterm, it's looking like Mardi Gras. Thus, I use hexdump to show the effect:
$ ls --color | hexdump -c
0000000 t e s t 1 \n 033 [ 0 m 033 [ 0 1 ; 3
0000010 6 m t e s t 2 033 [ 0 m \n 033 [ 0 1
0000020 ; 3 4 m t e s t 3 033 [ 0 m \n 033 [
0000030 0 1 ; 3 2 m t e s t 4 033 [ 0 m \n
0000040
As you can see: ls does use terminal escape sequences also. Then I remembered the variable TERM. This link The TERM variable mentions the terminfo or termcap also which are probably part of the game.
Thus, in addition to the re-definition of PS1 ... PS4, it could be useful to redefine TERM also:
$ TERM=
$ ls --color | hexdump -c
0000000 t e s t 1 \n t e s t 2 \n t e s t
0000010 3 \n t e s t 4 \n
0000018
$
Btw. I recognized that the bash prompt is still colored. Thinking twice this becomes obvious: The escape sequences in PS1 ... PS4 are "hard-coded" i.e. does not consider the setting of TERM.
Update:
To test this I wrote a sample script mybashrc:
PS1="> "
PS2=">>"
PS3=
PS4="++ "
TERM=
and tested it with bash in cygwin on Windows 10 (64 bit):
$ bash --init-file mybashrc -i
> echo "$PS1 $PS2 $PS3 $PS4"
> >> ++
> exit
exit
$
Btw. I noticed that the [Backspace] key works somehow strange in my sample session: It still has the intended effect but the output is wrong. Output is instead of deleting the last character although the internal buffer seems to handle this correctly:
$ bash --init-file mybashrc -i
> echo "Ha ello"
Hello
> echo "Ha ello" | hexdump -c
0000000 H e l l o \n
0000006
> exit
exit
$
(In both cases, I typed [Backspace] once after echo "Ha.) The reason is possibly the missing terminal emulation.
Thus, I believe if the console (in your application) handles backspaces in the output channel of the bash appropriately then it should be less confusing.
In windows, pretty easy to send pipe via cmd.exe, I simply write
.FileName = "cmd.exe"; and
.Arguments = "d:\ifme\addons\ffmpeg\ffmpeg -i d:\Videos\sata.mp4 -pix_fmt yuv420p -f yuv4mpegpipe - 2> nul | d:\ifme\addons\x265\x265lo -p medium --crf 28 -f 523 -o d:\ifme\temp\video.hevc --dither --y4m -";
but in Linux (Ubuntu 14.04.1) I write:
.FileName = "/bin/bash";
.Arguments = "-c /home/anime4000/Desktop/ifme/addons/ffmpeg/ffmpeg -i /home/anime4000/Videos/sata.mp4 -pix_fmt yuv420p -f yuv4mpegpipe - 2> /dev/null | /home/anime4000/Desktop/ifme/addons/x265/x265lo -p medium --crf 28 -f 523 -o /home/anime4000/Desktop/ifme/temp/video.hevc --dither --y4m -";
I got FFmpeg error which is no command specified...
I use create file method:
System.IO.File.WriteAllText("cmd.sh", "/home/anime4000/Desktop/ifme/addons/ffmpeg/ffmpeg -i /home/anime4000/Videos/sata.mp4 -pix_fmt yuv420p -f yuv4mpegpipe - 2> /dev/null | /home/anime4000/Desktop/ifme/addons/x265/x265lo -p medium --crf 28 -f 523 -o /home/anime4000/Desktop/ifme/temp/video.hevc --dither --y4m -");
.FileName = "sh";
.Arguments = "cmd.sh";
I got an error which is x265lo file not exist, but file was there with execute permission
So, how to get proper pipe command with C# Mono?
Note: x265lo is a 8 bit BPP build, x265hi is a 16 bit BPP build, because contain two x265 with different BPP
(Sorry, this should be a comment but I don't have enough reputation here.)
I don't know what's wrong specifically, but you should be able to determine how Mono calls your shell by doing something like this:
strace -fv -s4096 -e trace=execve /path/to/your/program args-to-your-program
Once you have done this, please update your question with the relevant execve() lines.
I would love to have a little problem solved. I know that it's not the best way to debug a piece of code with possible warnings, but I love to debug all the time when I have a little break between to ideas. I just found out about mono and the possibility to compile C# code running on Mac OS X Mountain Lion. I integrated it in the CodeRunner app, and it works without any problems. However, if there appears a warning in the code, it does not work.
For example, I tried to compile a code that creates one integer (nothing more than that) and it was not debugging because of that warning. I'm getting this error message:
Untitled.cs(9,29): warning CS0219: The variable `test' is assigned but its value is never used
Cannot open assembly 'Compilation succeeded - 1 warning(s)
Untitled.exe': No such file or directory.
Someone may know how to deal with that. I know it's not an essential feature, but I would love to debug the code even with some unused variables.
The content of the compilation script file:
#!/bin/bash
enc[4]="UTF8" # UTF-8
enc[10]="UTF16" # UTF-16
enc[5]="ISO8859-1" # ISO Latin 1
enc[9]="ISO8859-2" # ISO Latin 2
enc[30]="MacRoman" # Mac OS Roman
enc[12]="CP1252" # Windows Latin 1
enc[3]="EUCJIS" # Japanese (EUC)
enc[8]="SJIS" # Japanese (Shift JIS)
enc[1]="ASCII" # ASCII
rm -rf "$4"/csharp-compiled
mkdir "$4"/csharp-compiled
#mcs is the Mono CSharp Compiler
file="$1"
length=${#file}
first=`expr $length - 3`
classname=`echo "$file" | cut -c 1-"$first"`
#echo -out:"$4"/csharp-compiled/"$classname".exe "$1"
dmcs -out:"$4"/csharp-compiled/"$classname".exe "$1"
status=$?
if [ $status -ne 0 ]
then
exit $status
fi
#echo "$4"/csharp-compiled/
currentDir="$PWD"
cd "$4"/csharp-compiled/
files=`ls -1 *.exe`
status=$?
if [ $status -ne 0 ]
then
exit 1
fi
cd "$currentDir"
for file in $files
do
mv -f "$4"/csharp-compiled/$file "$file"
done
# Otherwise output the name of the input file without extension (this should be the same as the class name)
file="$1"
length=${#file}
first=`expr $length - 3`
classname=`echo "$file" | cut -c 1-"$first"`
echo $classname".exe"
exit 0
dmcs -out:"$4"/csharp-compiled/"$classname".exe "$1"
dmcs puts some messages on stdout, and some on stderr. CodeRunner expects stdout to only contain the output file name, nothing else, so to make that happen, >&2 can be used to redirect everything else to stderr.
dmcs -out:"$4"/csharp-compiled/"$classname".exe "$1" >&2
This worked for me on Sierra with current Mono and CodeRunner versions:
Language compile script:
file=$CR_FILENAME
/Library/Frameworks/Mono.framework/Versions/Current/bin/mcs "$CR_FILENAME" >&2
status=$?
if [ $status -ne 0 ]
then
exit $status
fi
echo $file | sed -e "s/\.cs/.exe/"
exit 0
Run command:
PATH="/Library/Frameworks/Mono.framework/Versions/Current/bin:$PATH"; mono $compiler
In MS compiler thre is a way to hide warnings
Pragma Warning Preprocessor Directive
#pragma warning disable 219
var test = "";
#pragma warning restore 219
It might help you.