Click here to Skip to main content
15,122,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, there

I created an windows service file named filewatcher.exe by C# and installed this service to windows server via InstallUtil.exe. I want to add the same file as a service in Ubuntu(cross-platform service).So I've installed mono in my ubuntu and use the command
sudo update-rc.d filewatcher.exe defaults

yes, the filewatcher.exe has been added as a service and started. But it doesn't work.

How can I make the service work OR what should I do to make the service work in both windows and linux?

Thanks
Posted
Updated 25-Nov-20 7:21am
Comments
Fredrik Bornander 8-Aug-13 3:39am
   
In what way does it not work?
Does it crash?
Does it not watch the right files?

Please provide more information.
wusir371 8-Aug-13 3:56am
   
Well. The service will monitor the file change and create a log.txt file on specified folder. But there is not this log.txt file.
I create a windows form executable file with the same function and it works normally on ubuntu as on windows, ie. it does monitor the file change and create a log.txt file.
In one word: Windows form exe file works normally but service exe file doesn't work as expected.
Fredrik Bornander 8-Aug-13 4:02am
   
Yeah I get that, but you still need to provide more information than "doesn't work as expected", it's next to impossible to solve it using only that piece of information.

Can you add logging to your application for example?
Have you tried debugging it on the ubuntu box?
wusir371 8-Aug-13 6:22am
   
"doesn't work as expected" is: The service will watch the file change and add the file change info to log.txt(if have't this file, will create the file), however, when I change the file, nothing happened. No log.txt file created. So I am not sure whether the service watche the file change or not.
I am newbie to ubuntu. I haven't tried debugging it on the ubuntu box -- I don't know how :-)

Try supplying the full path to your program:
sudo update-rc.d /fullpath/here/for/example/filewatcher.exe defaults
   
Comments
wusir371 8-Aug-13 21:19pm
   
Not work because the command sudo update-rc.d always add the path: \etc\init.d before the fullpath you give. for example: if you give a command like:
sudo update-rc.d \home\abc\projects\filewatcher.exe defaults
error message like: \etc\init.d\\home\abc\projects\filewatcher.exe: file doesn't exist
Mehdi Gholam 8-Aug-13 23:58pm
   
Try adding your program to the PATH
wusir371 9-Aug-13 0:43am
   
I have copied the filewatcher.exe to ~/etc/init.d folder and it has started normally as a service. I guess maybe the filewatcher.exe cannot be run itself because it can only be run by right click "Open With | Mono Runtime", I cannot set the "Mono Runtime" as .exe default application. I post another question about setting the default application of a file.
Well, from this question, I have got three points:
1, filewatcher.exe is developed by VS2012 - Windows Service(C#) project, this kind of .exe cannot be run by mono on Ubuntu, maybe windows service's special configuration can only be install as windows service. However, normal C# executable file (e.g: Windows Forms Application's exe file) can be run by mono on Ubuntu.
2, Although mono runtime cannot be set as the default application for filewatcher.exe, we can use
mono filewatcher.exe

to run it.
So, we can create a script like this - assume the script file name is filewatcherservice:
#! /bin/bash
mono /home/user/filewatcher.exe

and then, use the following command:
sudo chmod +x filewatcherservice

to make it an executable file
then, copy this file to /etc/init.d directory
finally,install the filewatcherservice as a service
sudo update-rc.d filewatcherservice defaults

3, Use the following command(maybe you need to install it before use it)
sudo sysv-rc-conf

to start the service.
Done!

Thanks everybody for your help.
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900