LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-23-2018, 01:22 AM   #1
Boobalan M
LQ Newbie
 
Registered: Jan 2018
Posts: 4

Rep: Reputation: Disabled
How do we get my UNIT(service) name in unit.sevice


I have small design where i need to get unit name inside my servcie script.

For eg:

Below is my service script,

sample.service

[Unit]
Description=job

[Service]
Type=simple
User=root
Type=forking
ExecStart='{here i need service name}'
Restart=always

When start using 'systemctl start sample' i need to get 'sample' inside my 'sample.service' script.

Is this feasible?
 
Old 01-23-2018, 01:57 AM   #2
ferrari
Senior Member
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 3,767

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Welcome to LinuxQuestions.org Boobalan M!

I'm not sure I follow you, but I do note that you have two 'Type=' directives. You need to be clear about which type you're after. The 'ExecStart=' entry must consist of one command (eg path to an executable shell script).

A typical example might look like this...

Code:
[Unit]
Description=My custom service
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/path/to/
ExecStart=/path/to/my_daemon --option=123
Restart=always

[Install]
WantedBy=multi-user.target
Some simple how to's to give a basic idea...
https://www.digitalocean.com/communi...and-unit-files
http://patrakov.blogspot.co.nz/2011/...ice-files.html

Reference:
http://patrakov.blogspot.co.nz/2011/...ice-files.html
 
Old 01-23-2018, 02:08 AM   #3
Boobalan M
LQ Newbie
 
Registered: Jan 2018
Posts: 4

Original Poster
Rep: Reputation: Disabled
Hi ferrari,

Thanks for response.

Actual implementation is, i have the case where my executable will be installed in different directory. Let's say executable is "MyExe" and installed in "mypath"

I will be creating on service script like below and i will keep service name like "MyExe.script",

[Unit]
Description=PLIN_SSP_01

[Service]
Type=simple
User=root
Type=forking
Environment="install_dir=mypath"
ExecStart=${install_dir}/{Here i need service script name}'
Restart=always

In this way, always executable and script name will always remains same.

Please give your input on this if this is achievable?


Regards,
Boobalan M

Last edited by Boobalan M; 01-23-2018 at 02:12 AM.
 
Old 01-23-2018, 02:27 AM   #4
ferrari
Senior Member
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 3,767

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Sorry, I'm still not grasping what you're tying to achieve here. Hopefully others can.
 
Old 01-23-2018, 02:52 AM   #5
Boobalan M
LQ Newbie
 
Registered: Jan 2018
Posts: 4

Original Poster
Rep: Reputation: Disabled
Actual query is, my intention is not configure executable name inside script also. Instead, when ever i run "systemctl start MyExe" script should detect that "MyExe" the is executable to be executed(from install directory).

We do not wanted to configure executable inside script also instead will expose like executable and script name are same.

Hope this makes clear.
 
Old 01-23-2018, 03:17 AM   #6
ferrari
Senior Member
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 3,767

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Now I think I understand I think what you're after are template unit files in the form <service_name>@<script_name>.service, whereby service instances can be created dynamically as needed. Such a template service could be constructed such that a script called <script_name> can be executed when the given service instance is started.

Described here...
http://0pointer.de/blog/projects/instances.html
https://fedoramagazine.org/systemd-template-unit-files/

Last edited by ferrari; 01-23-2018 at 03:22 AM.
 
Old 01-23-2018, 05:03 AM   #7
Boobalan M
LQ Newbie
 
Registered: Jan 2018
Posts: 4

Original Poster
Rep: Reputation: Disabled
Not exactly this way i was expecting as i could see that here we need to make our script naming convention like "MyExe@MyExe.service" instead "MyExe.service". Any i will go forward with this option.


Also i could see that, i couldnt use env variable in "WorkingDirectory" inside script.

Environment="INSTALL_DIR=/opt/product/mypath"

WorkingDirectory=${INSTALL_DIR}/bin

I could see that path expansion not working in WorkingDirectory. Is there any way?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
My first homemade ".service" unit file taylorkh Linux - General 5 10-22-2017 12:49 PM
Ubuntu 15.04 - Unit bumblebeed.service entered failed state diamondpumpkin Linux - Server 4 10-19-2016 02:27 PM
[SOLVED] start GUI application from systemd unit .service? mshlinux Linux - Desktop 3 10-10-2016 01:10 AM
bacula-dir not starting ; Unit bacula-dir.service entered failed state zalgo Linux - Software 2 04-09-2015 02:32 AM
Storage unit and IO unit salmanucit Linux - General 2 06-17-2008 11:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:59 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration