LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 09-04-2019, 08:36 AM   #1
igadoter
Senior Member
 
Registered: Sep 2006
Location: wroclaw, poland
Distribution: many, primary Slackware
Posts: 2,717
Blog Entries: 1

Rep: Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625
Need to create my own local service, my own local server - how I can do that?


Just as in title. Service, server, custom application - common infrastructure - I just don't want to run again and again the same application to gather information. Worse - to create hard encoded user interface I think is wrong solution. Small service would allow me to use different user interfaces - depending on my needs. So where to begin? Literature to read, code to hack? How small? I would say tiny. Esentially is there recipe how to create own service and server? I would greatly appreciate help. I am not aware to hack a code - no matter C, Perl, Python, Awk, shell scripting - maybe except C++ and similar huge languages.
 
Old 09-04-2019, 10:57 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,703

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
Here is one idea. A cron job could be used to run your application over and over again to gather information and maybe store it in a file or database. You can use a web server with CGI, bash or anything else to display that information.
 
Old 09-04-2019, 01:24 PM   #3
igadoter
Senior Member
 
Registered: Sep 2006
Location: wroclaw, poland
Distribution: many, primary Slackware
Posts: 2,717

Original Poster
Blog Entries: 1

Rep: Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625
Thank's but I need to create first this service and server. So well defined way for application to communicate with server and to obtain required information. Kind of communication protocol but of course not something - I am imagining that server is listening umm say on socket - there is request - then eg. it sends back name of named fifo to establish one-way connection - and through that fifo sends requested information - but it needs to fork if there are several request - but the truth these are only my blind guesses - maybe this maybe - server by itself is very simple it looks for information on internet and preprocess it before sending back. I could put this hard coded into larger program - but I want to avoid this. If I would need new functionality instead of to rewrite, to extend old program it would be simpler to create new. At the end I would have a bunch of small apps. So the first step is: how to write your own server?
 
Old 09-04-2019, 03:20 PM   #4
Shiori-kun
LQ Newbie
 
Registered: Mar 2010
Posts: 16

Rep: Reputation: 3
First, what kind of data are you trying to collect?
What are you trying to collect from?

Not to stiffle your creativity but do not reinvent the wheel. Once you figure out what you are collecting data from, then you can select a data format that is compatible and if it is going over a network, the protocol to use for the data collection.

A server to display the data will depend on the display format. If it is graphs and pie charts, I suggest something like rrdtool. This can be called from a cgi script and a web page can be dynamically generated to display the data in near real time.
 
Old 09-04-2019, 03:23 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,703

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
Here are a couple of examples.

https://www.thegeekstuff.com/2012/02/c-daemon-process/

https://www.datamation.com/netsys/ar...ith-Python.htm
 
1 members found this post helpful.
Old 09-04-2019, 04:46 PM   #6
igadoter
Senior Member
 
Registered: Sep 2006
Location: wroclaw, poland
Distribution: many, primary Slackware
Posts: 2,717

Original Poster
Blog Entries: 1

Rep: Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625
Thanks I compiled the example from the first link. It works. As it was in comments I changed "/" to "/tmp". I read man(3) about daemon function but I have no idea how to call daemon() instead of what is in this example.
 
Old 09-04-2019, 04:55 PM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,703

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
If your asking about how to add networking then here is a very good guide.

https://beej.us/guide/bgnet/
 
Old 09-04-2019, 05:27 PM   #8
igadoter
Senior Member
 
Registered: Sep 2006
Location: wroclaw, poland
Distribution: many, primary Slackware
Posts: 2,717

Original Poster
Blog Entries: 1

Rep: Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625
Thanks. Don't know what actually to think about daemonizing scripts - they are being executed by interpreter - so it is rather interpreter demonize itself - I will try later on example in Python but I suspect in processes list there will be something like '3314 user users python /home/user/my-daemon.py'. But of course I need to run this the first.
 
Old 09-05-2019, 12:59 AM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
TBH, I'm not entirely clear on what you want, but it sounds like looking at Chaps 17 & 18 here https://docstore.mik.ua/orelly/perl4/cook/index.htm might help.
 
Old 09-05-2019, 01:20 AM   #10
igadoter
Senior Member
 
Registered: Sep 2006
Location: wroclaw, poland
Distribution: many, primary Slackware
Posts: 2,717

Original Poster
Blog Entries: 1

Rep: Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625
Quote:
Originally Posted by chrism01 View Post
TBH, I'm not entirely clear on what you want, but it sounds like looking at Chaps 17 & 18 here https://docstore.mik.ua/orelly/perl4/cook/index.htm might help.
Thanks - starting from chapter 15 - custom app needs to communicate somehow with server.

Edit: At this moment with my knowledge supposedly I myself don't know clear what I want. Service - one requests something - clean a carpet - and it is done. To separate part of job independent on custom action - customer can add functionality to its own application. But all these application rely on the same service. People often ask: why your app does not do this or that? This was I realized that instead of trying to build app which would satisfy all possible wishes - it is better to provide service and let others create their own custom apps.

Last edited by igadoter; 09-05-2019 at 01:39 AM.
 
Old 09-05-2019, 05:42 AM   #11
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,703

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
A somewhat complicated example of what I think you want to accomplish is gpsd. It reads GPS receiver data and provides it to clients over TCP networking. It has an API developed for several different programming languages.

You will need to do the same thing i.e. collect the information and then provide it to the clients using a defined protocol. Write your service so that it can be run as a regular application for troubleshooting purposes and not as daemon.
 
Old 09-05-2019, 02:19 PM   #12
igadoter
Senior Member
 
Registered: Sep 2006
Location: wroclaw, poland
Distribution: many, primary Slackware
Posts: 2,717

Original Poster
Blog Entries: 1

Rep: Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625
I was thinking about something similar - service on demand - problem is I need my own protocol. Does it simpler than daemon and usual means of ipc?
 
Old 09-05-2019, 03:14 PM   #13
hoes
Member
 
Registered: Sep 2005
Distribution: debian, linux from scratch
Posts: 190

Rep: Reputation: 51
Maybe xinetd is something to look into when you want a service up on demand.
Although in that case xinetd would be up all the time instead of the service
 
Old 09-05-2019, 04:43 PM   #14
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,703

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
Good suggestion. xinetd would be the daemon process and when it detects traffic on the desired port starts your application and pipes the incoming data to it.
 
Old 09-05-2019, 04:56 PM   #15
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
D. J. Bernstein’s daemontools could also work. It’s an alternative to xinetd.

Last edited by scasey; 09-05-2019 at 04:57 PM.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
systemctl status postgresql-tst.service starts the service if service is stopped MarianForums Linux - Newbie 7 11-03-2018 03:02 PM
How to create own DNS service? netjack Linux - Networking 6 08-14-2015 08:23 PM
help need friends dhcpd service " this service is being refreshed right now golpemortal Linux - Server 2 10-08-2012 03:37 AM
Need info on how to create my own linux distro without using one of the roll your own xiqtem Linux - General 3 07-16-2010 11:53 PM
how to create my own slackware install DVD with my own kernel dont_stop_me Slackware 4 03-05-2010 03:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration