How to run a user service with systemd
Most Linux systems uses systemd as init and service manager nowadays.
You can use systemd to start your services, so that they are automatically restarted if they crash, and automatically started when the system boots. You can even do this as a regular user, without root access (then the service will run with permissions of your user), and have it automatically started when the system boots without you having to login.
- Create the
~/.config/systemd/userdirectory if necessary:
mkdir -p ~/.config/systemd/user- Create a service unit configuration file
for your service in that directory
~/.config/systemd/user/myservice.service:
[Unit]
Description=MyService
[Service]
Type=exec
LoadCredential=my-password:%h/myservice.pw
ExecStart=%h/.local/bin/myservice -password-file ${CREDENTIALS_DIRECTORY}/my-password
Restart=on-failure
NoNewPrivileges=true
AppArmorProfile=myservice
[Install]
WantedBy=default.target
- Load the service definition:
systemctl --user daemon-reload- Enable the service:
systemctl --user enable myservice.service- Start the service
systemctl --user start myservice.service- Enable starting the service on boot without login (you might need to run this as root):
sudo loginctl enable-lingerThis will provide the service with credentials from file ~/myservice.pw, and run the service with AppArmor
profile myservice (which you must create and load first).
How to Publish a Gradle Project on Maven Central
You can publish a Java or Kotlin library built with Gradle on Maven Central like this.
First setup your Gradle build to produce a valid bundle for Maven Central.
-
Include the Maven Publish Plugin in your build.
-
Setup building of Javadoc and Source archives using Dokka.
-
Set the required POM metadata in Gradle like this.
See here for a complete working example.
Now you can run gradle publish to create the Maven bundle in the mavenPublish directory (which you probably want to include in .gitignore).