Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sbt-native-packager 1.0.0] [play 2.3.8] Debian package installation uses wrong user to start #560

Closed
MeiSign opened this issue Apr 23, 2015 · 10 comments

Comments

@MeiSign
Copy link

MeiSign commented Apr 23, 2015

I am creating a debian package of my Scala Play 2.3.8 application with the sbt native packager ("com.typesafe.sbt" % "sbt-native-packager" % "1.0.0"). The SystemV startscripts that are being generated use a custom user to start and stop the app which is exactly as intended.
The problem is, that the installation with dpkg -i package.deb seems to start the app directly after the installation as root user. The /var/run/neeedo-app/running.pid is then owned by the root user and all further stop or start attempts fail because this file cant be overwritten by the daemon user.

This is my build.sbt:

import com.typesafe.sbt.SbtNativePackager._
import NativePackagerKeys._
import com.typesafe.sbt.packager.archetypes.ServerLoader.SystemV

name := """neeedo-api"""

version := "1.0-SNAPSHOT"

scalaVersion := "2.11.1"

maintainer in Debian := "neeedo-team <[email protected]>"

packageSummary in Debian := "neeedo api application"

serverLoading in Debian := SystemV

packageDescription := "neeedo api application"

daemonUser in Linux := neeedo-api

daemonGroup in Linux := neeedo-api

I am running the dpkg install command also with the neeedo-app user. I don't understand why the running.pid file is created by the root user after installation. If I delete the file manually with sudo and use the start/stop script afterswords everything works fine.

Is this an issue with the deb package building process or is something wrong with my server environment? I can't figure it out. Help appreciated.

@MeiSign MeiSign changed the title Debian package installation uses wrong user to start [sbt-native-packager 1.0.0] [play 2.3.8] Debian package installation uses wrong user to start Apr 23, 2015
@muuki88
Copy link
Contributor

muuki88 commented Apr 23, 2015

That's very interesting as the postinst script uses the same facilities to start the service:

What OS are you running on?

@MeiSign
Copy link
Author

MeiSign commented Apr 23, 2015

Ubuntu 14.04.2 LTS

@muuki88 muuki88 closed this as completed Apr 23, 2015
@muuki88 muuki88 reopened this Apr 23, 2015
@muuki88
Copy link
Contributor

muuki88 commented Apr 23, 2015

And you start the service with
sudo service neeedo start ?

@MeiSign
Copy link
Author

MeiSign commented Apr 23, 2015

Actually I start the application with /etc/init.d/neeedo-api start
When i use sudo service neeedo start the pid file gets created with the root user. That might explain this issue but its still not clear to me. Since I am using SystemV I should use the /etc/init.d/ script right?

I just found out that the only way to start my application successful is running the /etc/init.d/neeedo-api start script without sudo. If dpkg runs sudo service neeedo start after installation that should be the problem. Can I overwrite this?

@muuki88
Copy link
Contributor

muuki88 commented Apr 23, 2015

Hm. With systemv you are supposed to use the service command. Running the /etc/init.d script shouldn't be the way to go. I'll try this when I get time.

Can you use the default upstart systemloader?

@kardapoltsev
Copy link
Member

Actually it shouldn't be a problem since /var/run/app_name is owned by daemon user and this user is able to delete running.pid inside this directory.
Your program actually not started as root. Owner of running.pid and daemon-user isn't the same.
When you run sudo service app_name start or sudo /etc/init.d/app_name start then script will be executed as root, start-stop-daemon create running.pid also as root but start your program as daemon-user.
Could you please show what exactly errors you have?

@MeiSign
Copy link
Author

MeiSign commented Apr 26, 2015

I will try to create a smaller example project today. And I will also try to use upstart systemloader. Thanks for your help today.

@MeiSign
Copy link
Author

MeiSign commented Apr 26, 2015

Ok I think I understand the issue now. The problem why the files are created by the root user is probably because I have to run dpkg with sudo and all further scripts invoked by this installation are then also run as root user. This explains why the running.pid file is then owned by root.

@MeiSign
Copy link
Author

MeiSign commented Apr 26, 2015

I finally found the solution to my problem the issue can be closed. Sorry for the inconvenience the native packager is working correctly.

My application is using environment variables in its config and when you run the start script with sudo as root user you have different environment variables. This led to the fact the the app couldn't start and unfortunately no error reporting was visible (I have to investigate further to see why because normally this should be reported).

Thanks for your help...

@MeiSign MeiSign closed this as completed Apr 26, 2015
@muuki88
Copy link
Contributor

muuki88 commented Apr 26, 2015

thanks for sharing :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants