Link to home
Start Free TrialLog in
Avatar of Rohit Bajaj
Rohit BajajFlag for India

asked on

how to run a command as a nologin user

hi,
i have created a user without any shell with /sbin/nologin
now inside root i have a directory where i can run mvn jett:run command .
but this runs the jetty process as root user.
how to make the user as the nologin user which i created.
if i enter bash shell with the nologin user and run the command i get some error relates to maven .m2 directory

what could be the way to run it with nologin user from inside a script ?

thanks
Avatar of simon3270
simon3270
Flag of United Kingdom of Great Britain and Northern Ireland image

Is the problem, assuming you are doing something like
   su other_user -c "mvn jett:run.."
that the other_user doesn't have a home directory?  If it doesn't, it can't find the usual $HOME/.m2 directory for maven settings.

You can specify at least the repository part of the .m2 directory on the command line:
   mvn -Dmaven.repo.local=/path/to/.m2/repository jett:run
(You may be able to specify others.)  Then you just set up a .m2 directory structure, owned by other_user, in the specified location, and and run the above command.
Avatar of Rohit Bajaj

ASKER

HI,
Although i am doing it another way.
If i try
su flocksnippet -c "mvn jetty:run"
i get the error :
This account is currently not available
dont know why this happens
If i do getent passwd flocksnippet i get :
flocksnippet:x:997:996::/home/flocksnippet:/sbin/nologin

What actually i was doing is :
#!/bin/bash
source /etc/init.d/functions
cd /opt/flock-snippets
daemon —user=flocksnippet “/bin/mvn -Dmaven.repo.local=/root/.m2/repository -X jetty:run” &

Open in new window


when i run this i see the error :
Reading global settings from /usr/share/maven/conf/settings.xml
Reading user settings from /home/flocksnippet/.m2/settings.xml
using local repository at /root/.m2/repository
[ERROR] Could not create local repository at /root/.m2/repository
org.apache.maven.repository.LocalREpositoryNotAccessibleException : Could not create local repository at /root/.m2/repository


For more information see :
https://cwiki.apache.org/confluence/display/MAVEN/LocalRepositoryNotAccessibleException

Open in new window

I tried givin su -s /bin/bash..

That no account error went but the other error could not create repo at /root/.m2/repository came back...
Although this repo is already there...
It's easier if the user running the mvn command owns the .m2 direcotry structure - your command is trying to access one owned by root, so the flocksnippet user can't write to it.

Change the parameter to
   -Dmaven.repo.local=/home/flocksnippet/.m2/repository
In fact, it looks as though it is already using /home/flocksnippet/.m2 (for settings.xml), so you probbaly don't need the -Dmaven.repo.local parameter at all.

What was the original error you were seeing?
Hi,
I found it out. This was a permissions issue
Although i changed the group for .m2 and repository folder to flocksnippet
But the root still had root access only.
So maven was not able to access the path /root/.m2/repository

want to know one thing
i used chgrp to change the group for a folder. But like for root/.m2/repository
I had to execute chgrp /root
chgrp /root/.m2
and chgrp /root/.m2/repository
Is there any way to do it in one go ?

Also as in my current case .m2 folder is placed inside /root
And any such nologin process which i create may need to access this and so
i need to give access to this folder. What i am doing currently is creating a group out of root, flocksnippet name it flocksnippet and assign this group to all the folders on the path.

Is this a good way to do ?
Should .m2 folder be placed somwhere else instead of root  ?
ASKER CERTIFIED SOLUTION
Avatar of simon3270
simon3270
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial