lorenzo's picture

I'd like to edit confconsole in order to support one application of mine as "UI", but I am a bit confused about the steps. Do you know if there is any howto/guide, please?

I'd like to use a TKL application to deploy one C# application of mine with Mono. This C# application is currently executed at boot as crono job on a TKL-core virtual machine with Mono installed. However, as it is, there is no way to check mono application status and/or check/edit its configuration.
Therefore, I thought to edit Turnkey Linux Configuration Console in order to allow users to check C# application status and configuration.

In order to do that, I found some discussion in the forum about confconsole, but I am not much skilled in setting-up a Debian/Ubuntu and I think I am missing some (to be optimistic) points.. sorry :(

As far as I understood, I have to edit confconsoly.py in order to add wanted new features. Then, which steps should I take to achieve my goal?

Sorry for the newbie questions and thanks in advance for your help!

All the best.

 

P.S. I forgot to mention that i am currently using TKL-core 14.1 for AMD64.

Forum: 
Jeremy Davis's picture

If you mean that you want to add some questions to the firstboot inithook config then you'll need to add some files to the inithooks directory of your appliance code as per what the other appliances do (check out overlay/usr/lib/inithooks/ of pretty much any appliance in the library).

If you want to just change the text that confconsole displays then edit /etc/confconsole/services.txt (edit/add it to the overlay if you are building an app from scratch).

Further if you think that your app would be useful for others, is ready for prime time and is open source then please consider releasing it as a TurnKey appliance. I can help you out there if you want...

lorenzo's picture

To clarify, this C# application reads data from some sources, do some process, and pushes processed data to some data bases. Both sources and data bases are specified by two configuration files. Additionally, this C# application produce a log of its actions stored in a file log.
I'd like to show in confconsole the current sources, current data bases, and the tail of file log. Is it possible?

As far as I understood services.txt doesn't do any magic.. unless I store those informations in environment variables, whose enviroment variables should be populated with a script in inithooks directory.. Am i right? I do not know if there is any easier and more elegant way..

I already thought about releasing the Turnkey appliance, but this C# application is not open source.. :(
However, I aim to release an appliance for debugging Mono applications remotely, if it may be usefull ;) and any help would be really appreciated, thanks!

Jeremy Davis's picture

Unless you know python then leveraging services.txt is probably your best bet. We are currently tweaking Confconsole to include additional functionality but I'm not sure if it'll be relevant to your usage scenario (or when it'll be ready).

Your ideas sound reasonable but TBH I haven't played with it much myself so you might need to do some trial and error...

PS I removed that other post as it was just from a spammer.

lorenzo's picture

TBH, I have never developed with python, but confconsoly.py seems as hard as any other uncommented script to understand :-P.

For example, if I understood correctly, to add another sub-menu in "advanced menu", it should be enough to:
1. add another line which appends a new item in "_get_advmenu" (e.g. items.append(("NewSubMenu", "NewSubMenu Brief Description"));
2. add a new function "_get_ifconfNEW(self, ifname)" which can be based on "_get_ifconftext" as template;
3. add "self._get_ifconfNew(self.ifname)" in "ifconf" (e.g.

retcode, choice = self.console.menu("%s configuration" % self.ifname,

                                                        self._get_ifconftext(self.ifname),
                                                        self._get_ifconfNEW(self.ifname),
                                                        self._get_ifconfmenu(self.ifname))

 

   

).
Am I right?

Instead, if I'd like to use "services.txt" to add my new features, I should edit services.txt in something like:

Web:       http://$ipaddr
               https://$ipaddre
               ...
New:       $newVariable
 

Am I right? 
Howerever, is it right my guess that $newVariable should be an enviroment variable of linux? Otherwise, how do I define such $newVariable?

It is a lovely news that you are currently tweaking confconsole! ;-)

P.S. Thanks for removing the spammer, and, of cource, for your help!

Jeremy Davis's picture

As I think I mentioned, I don't actually know much about Confconsole (or python) myself and have never worked on it (or even looked at the code in depth) but your ideas sound pretty reasonable to me.

I suggest that you have a bit of a play (using trial and error) and see how you go. Post your progress and if you get totally stuck I'll see if I can get someone to help steer you in the right direction.

Sorry I can't be of more help, I'm just not 100% sure myself...

lorenzo's picture

Definitely, I'll keep this post updated ;-)

Good, if it sounds reasonable to you as well, I'm going to start to play! 
Do not worry, if you do not know actually how confconsole works, you know much more than me.
BTW, do you know if to see the results of edit is enought  to re-execute the inithooks? (e.g. by rebooting the virtual machine?)

Thanks again for your support!

Jeremy Davis's picture

Ok that sounds great. I look forward to hearing how you go!

As for applying your changes, confconsole runs as a daemon so restarting that should be sufficient. I.e.:

service confconsole restart

Rebooting the VM will definitely do it though!

lorenzo's picture

Super!

Jeremy, finally, I have managed to obtain what I was aiming to! Of course, it does not have any whistle or bell but, it do its job.

I was aiming to add a sub-menu to confconsole which shows some configuration parameters from certain files; Here, the stepes that allowed my to do so:

1. Add the new Sub-menu to advanced menu in confconsole

Edit confconsole.py method "_get_advmenu" by adding your new sub-menu item to the advanced menu of confconsole. For example, listening below represents the code to add "my app" sub-menu to the advanced menu.

def _get_advmenu(self):
        items = []
        items.append(("myapp", "Check  my app configuration"))
        items.append(("Networking", "Configure appliance networking"))

        if self.installer.available:
            items.append(("Install", "Install to hard disk"))

        items.append(("Reboot", "Reboot the appliance"))
        items.append(("Shutdown", "Shutdown the appliance"))
        items.append(("Quit", "Quit the configuration console"))

        return items

2. Add the mothod called when sub-menu is selected

Edit confconsole.py by adding a new method which is called when sub-menu is selected. It is important to name well this method as, as far as I understood, it have to be called "_adv_" + [sub-menu first item]. For example, for "myapp" it have to be called "_adv_myapp". Listening below shows an example of "myapp" sub-menu method implementation.

def _adv_myapp(self):
        ##Let's get the parameter from the file.

        text = "My app configuration contains the following parameters:\n" 
        parameters = file('/usr/local/mono/myapp', 'r').readlines()
        for parameter in parameters:
               #Append a line for each parameter in parameter read from myapp config file.
               text += "               %s" % parameter

        #Show a msgbox containing myapp parameters and return to advanced menu on ok.
        retcode self.console.msgbox("myapp Configuration", text, button_label = 'ok')

        if retcode is not self.OK:

                return "advanced"

        return "advanced"

3. Save & test it

Save confconsole.py and run it via "confconsole" or "service confconsole restart" (as suggested by Jeremy). If everything was wrote fine and the intedenation respected there should be a new sub-menu (i.e. myapp) in advanced menu. Therefore, if this new sub-menu is selected a msgbox should appear showing the list of parameters contained in the specified file.

I hope that is clear enough. Otherwise, just point me the points that I may rewrite or go in more details.

Jeremy Davis's picture

Sounds like you've done it! Great work!

The mods to confconsole that we're working on will make adding new menu entries really easy. The plan is that you just have to drop a new (specially formatted) file into confconsole's filesystem (sort of similar to the way that inithooks are automatically picked up when placed in the right part of the filesystem) which will automagically create a new menu entry. If you want to create a whole new menu tree then you just do that as sub-directories. I.e. the new sub-directory becomes a new menu item, which when clicked opens a new sub-menu. The files within the sub-directory auto populate the sub-menu (and can include more sub-directories/sub-menus).

lorenzo's picture

That is a great news!
If I may, then I would advice to publish a tutorial about that and to provide such pre-formatted files (i.e. templates?) with some comment in the key-points. In my experience, I had some hard hours while I was trying to figure it out how the whole thing was working and why it was not doing what I guessed it should do :-P.

I am looking forward to the new confconsole mods!

P.S. It is off-topic, but I was also trying to provide na alternative interface via an ASP.NET MVC interface that I developed in visual studio 2015, but I was not able to deploy it on the asp.net-mono-TKL appliance.. Do you have any suggestion about that Jeremy, please? Should I open another thread?

Jeremy Davis's picture

Here is the work in progress. We'll aim to document it properly; but per always there are so many priorities and only so many hours in the day (hence why open source docs are often pretty crap...)

As for your asp.net development questions, I am no help at all. I have been involved with maintenance of our asp-net-apache (i.e. mono) appliance but only from a TKL/OS perspective and very basic testing. I have no experience with asp.net/mono/etc at all so am absolutely no help to you at all there...

It may be a limitation of Mono perhaps? Historically Mono was always a subset of dotNet, not a full implementation. I know MS have open sourced dotNet and AFAIK MS are working with Xamarin (the company behind Mono) but I'm not sure what their plan is regarding implementation of a complete dotNet.

It may be a bug in Mono? We install Mono from the Xamarin upstream. Perhaps there is a bug in it?

Or perhaps it is a misconfiguration and/or bug in the TurnKey appliance. I'd like to think that there isn't but TBH it's totally possible...

I suggest that you consult with the Mono community. If it does end up being anything to do with our appliance please let me know ASAP. Additional brownie points if you can tell us exactly what is wrong and how to fix it! Extra bonus brownie points if you fix the code and give us a GitHub pull request! :)

lorenzo's picture

It seems that there is no rest for the wicked ;)
If I may give some help, let me know.. also for the doc, but as you probably already noticed, I am not a native speaker.

Alas! Do not worry.. I'll check Mono community and let you know.
BTW, the examples embedded within appliance are not working.. to let them work I had to install them on a "virgin" TKL appliance; then, I had to "scp" them to asp.net-mono appliance to let them work.
Infortunately, still no results for my web appliactions.. T.T

What do you mean by "brownie points"? :P

Jeremy Davis's picture

To avoid the ever narrowing post box (each new post is indented from the one above - makes the thread of the conversation nice but gets a bit out of hand in long conversations...) I am posting as a reply to your OP.

Firstly I forgot to actually post the link to the work in progress, doh! Here it is: https://github.com/OnGle/confconsole/tree/plugin_system

Regarding the examples not working, that's not very good! We'll definitely need to fix that. If you have any ideas, I'd love to hear more about it. Even if you could document how to test them (I don't even know where to start).

In my vocab, "brownie points" are a fictional currency that is earned through good deeds. AFAIK it originally comes from the junior Girl Guides/Girl Scouts (who are called "Brownies") but I'm not sure of that...

lorenzo's picture

Thank you for the link, I peeked in it already ;)

Sure, I 'll probably look at it with a friend at the end of the month; I hope to give some good news.

Aha! Good to know, thanks ;)

Jeremy Davis's picture

Look forward to hearing how you go. Also if you keep an eye on the turnekylinux/confconsole GitHub repo then you'll know when we merge the code (we won't do that until it's confirmed working and we're happy).
lorenzo's picture

As soon as I'll have some news, I'll post it ;)
Definitely! Looking forward to it.

lorenzo's picture

Unfortunately, I did not manage with ASP.NET Mono yet.. If there is any update, I'll wrote it here :(

Jeremy Davis's picture

Unfortunately I haven't got any update news either. Hopefully next time we stpeak we'll both have good news! Fingers crossed! :)
Lone Wolf's picture

Lorenzo,

Thanks for posting your findings here, they saved me the time to do some research myself. I was about to start a thread regarding how the examples are not working on 14.1, while they were working on 14.0. The way I fixed them was by creating an instance of 14.0, downloading them from /usr/share (the folder is asp.net-demos) and then uploading them to /usr/share on the 14.1 instance.

In the spirit of "equivalent exchange", let me save you some time with my own findings with the appliance. I have had some success with my own ASP .net web applications, so I can provide some guidance on how to set yours up. (Sorry if this is months late, I just saw your post).

So, what kind of problems are you having with your ASP .net applications? I will attempt to address a few concerns that perhaps might help you, if they are unrelated please let me know and give me more details to see if I can provide with some pointers or help.

Let's begin with adding applications to the default application as "children" of it:

  1. Open the file /etc/apache2/sites-available/000-default.conf (The  directory /etc/apache2/sites-available is where the apache sites need to be added)
  2. At the bottom of file, add the following lines (Change the values in bold with those of yours):
    # For more information about mod_mono:
    http://www.mono-project.com/docs/web/mod_mono/
    # Instruct Apache to to map the virtual path "/samples" to the physical path of the examples ("/usr/share/asp.net-demos"):
    Alias /samples "/usr/share/asp.net-demos"
    # Create an ASP .net application in the virtual path "/samples" mapped to the physical path of the examples ("/usr/share/asp.net-demos")
    MonoApplications "/samples:/usr/share/asp.net-demos"
    # Instruct Apache that everything in the virtual path "/samples" should be handled by mod_mono:
    <Location /samples>
         SetHandler mono
         Require all granted
    </Location>
  3. Save the file and restart apache by executing (You need to execute this whenever you add a new ASP .net web application in apache but not when making changes to the any of the files inside the folder containing the Web Application, even cs files):
    /etc/init.d/apache2 reload

Another way to accomplish adding a new application is the following:

  1. Open the file /etc/mono-server4/debian.webapp
  2. Add the following lines before the line </apps> (Change the values in bold for those of yours):
    <web-application>
        <!-- Name of the Web Application (It can be empty): -->
        <name>samples</name>
        <!-- Virtual Path of the Web Application: -->
        <vpath>/samples</vpath>
        <!-- Physical Path of the Web Application: -->
        <path>/usr/share/asp.net-demos</path>
    </web-application>
  3. Save the file and restart apache by executing (Again, you need to execute this whenever you add a new ASP .net web application this way, but not when modifying files inside of the folder containg the Web Application):
    /etc/init.d/apache2 reload

Now, let's replicate a common IIS behavior by having the default web application (the one that ships with the appliance) on port 80 and the examples on port 1080.

  1. Open the file /etc/apache2/ports.conf
  2. Add the following lines below the line "Listen 80", so Apache will be listening to the new port (Change the bold value in case you want to use a different port instead of 1080):
    # Instruct Apache to listen to the following port:
    Listen 1080
  3. Save the file
  4. Create the file samples.conf (or any other name you prefer, as long as it ends in .conf) inside the directory /etc/apache2/sites-available 
  5. Add the following content to the file (Change the values in bold with those of your own):

    # Specify a virtual host to point to the Web Application:
    <VirtualHost *:1080>
            ServerAdmin webmaster@example.com
            DocumentRoot "/usr/share/asp.net-demos"
            
            MonoApplications default "/:/usr/share/asp.net-demos"
            MonoServerPath default /usr/bin/mod-mono-server4
    </VirtualHost>

    # This part is not required if there is any other enabled site which specifies it:
    <Location />
            SetHandler mono
            Require all granted
    </Location>

  6. Save the file
  7. Enable this new site by executing the following command (If you used a different name than sample.conf, replace the bold value. Note that you don't need to specify the full path, regardless of the current path you are working on the terminal):
    a2ensite samples.conf
  8. Restart Apache by executing the following command:
    /etc/init.d/apache2 reload

Once you follow these steps, you will be able to navigate to http://<Appliance's IP> and https://<Appliance's IP> and have the default web application included with the appliance launched. If you navigate to http://<Appliance's IP>:1080  (or the port you configured) you will navigate directly to the web application which you configured (if you didn't change any bold value, this would be the asp.net examples web application).

Figuring this out was a headache, and I must admit I didn't get this to work by just modifying /etc/mono-server4/debian.webapp (No, if you follow the instructions above you don't need to modify this file). Another thing to take in account is that in the mod_mono page of the mono project site (http://www.mono-project.com/docs/web/mod_mono/), the team recommends to use reload instead of restart, which is why the command provided in the instructions to restart Apache is reload and not restart.

If you desire to replace the default web application provided in the appliance, you have a few choices:

  • Use the existing /var/www directory: Add and delete files as needed so your web application is the one served through port 80 (http) and port 443 (https). This is the simpliest option, the TK way!
  • Create your own web application as detailed above and disable the default web application by using the following command:
    a2dissite 000-default.conf
  • Modify the existing configuration so that it points to your own application by either:
    • Altering the /etc/apache2/sites-available/000-default.conf file so that the configuration points to your own web application (The configuration would look like the one presented above)
    • Altering the /etc/mono-server4/debian.webapp so that the path points to your own web application's directory

A few considerations:

  • The directory of your web-application that Apache points to needs to provide read (and maybe write) access to the Apache's account (www-data), this can be accomplished by either:
    • Having your web application be inside the /var/www or the /usr/share directories.
    • Executing the following commands (replace the bold values with your own):
      # Grant access to the www-data to the web application's directory
      sudo chown -R www-data:www-data /usr/share/asp.net-examples
      # Grant access to the "root" directory (the one containing your web application) to everyone so they can read it:
      sudo chmod -R 755 /usr/share
  • Mono's ASP .net implementation differs from Microsoft's, a crucial detail which can bite you is that Microsoft's implementation uses the precompiled DLL of your web application, while Mono's creates an automatically generated DLL prefixed with App_ which makes a reference to your precompiled DLL. This subtle difference has a few consequences:
    • You can make changes to files which contain code (cs, aspx, etc.) and these changes are picked up without the need to restart the web server (No need of an equivalent of an IIS reset).
    • Code which retrieves resources from the executing assembly will fail. This one is very important, since this is the reason why the Entity Framework 5 would not work: It seeks for resources in the executing assembly, those resources are packaged in your precompiled DLL, not in the automatically generated DLL prefixed with App_.
    • You might need to delete the pre-compiled DLLs and then copy the new pre-compiled DLLs into the bin directory of the web application in the appliance.
  • Mono's implementation of the .net framework is not complete yet and there might be a few differences, so you might need to check for what is implemented and what is not. The main advantage of Mono is that it is open-source and you can implement anything you need (if time allows you to do so), more since Microsoft has published the source code of the .net framework (so you could use it as a reference). I will post more about this in another thread, since I want some advice regarding what to do after modifying the source code, compiling it and installing it on an appliance.
  • Since Mono's implementation of the .net framework differs a little, it might make sense for you to install (not in your appliance, of course) MonoDevelop in a development environment (a virtual machine, for example), compile your code and use those assemblies (I really haven't had to do this myself, the only issue I came across was when using EF 5).
  • SignalR appears not to work with Apache (even though I saw a post which claimed it could be done if you built a development version, I was unable to get it working after following every step and spending at least two days on it).
  • You are not dealing with IIS, so you will need to refer a lot to how to configure Apache to behave the way you intended with an IIS configuration.

I hope that this helps you, please let me know if it does.

Regards!

lorenzo's picture

Lone Wolf,
I am really glad that you found my findings helpful.

Thanks a lot for your help and suggestions!
Currently, I had to move on with other topics after my previous post. So, I would not use your suggestion immediatly. However, I have to come back to my asp .net web applications in next months!

I will update you as soon as possible, hopefully, with good news ;-)

All the best!

 

Lone Wolf's picture

Lorenzo,

You are welcome, don't worry about having to take some time to check my suggestions. Hopefully they will help, let me know a few months from now to see how everything went, I wish you good luck!

Regards!

lorenzo's picture

Lone Wolf,

sure! Thank you once again ;)

Regards

Add new comment