1

I used the suggested answer from this post to make a custom service in my ubuntu 17.04 environment: Installing gitblit GO as service in Ubuntu Server 16.04

Unfortunately when I hit

sudo systemctl enable gitblit_server.service

I receive

Failed to enable unit: File gitblit_server.service: Invalid argument

as an error.

Any idea what I am doing wrong?


Update:

result for journalctl -xe

Sep 01 16:06:22 git-dmz01 sudo[7121]: msoadmin : TTY=pts/1 ; PWD=/etc/systemd/system ; USER=root ; COMMAND=/bin/systemctl enable gitblit_server.service
Sep 01 16:06:22 git-dmz01 sudo[7121]: pam_unix(sudo:session): session opened for user root by msoadmin(uid=0)
Sep 01 16:06:22 git-dmz01 systemd[1]: [/etc/systemd/system/gitblit_server.service:12] Missing '='.
Sep 01 16:06:22 git-dmz01 sudo[7121]: pam_unix(sudo:session): session closed for user root

content of my file gitblit_server.service:

[Unit]
   Description=gitblit Server CVS
   After=network.target
[Service]
   User=msoadmin
   Type=simple
   WorkingDirectory=/opt/gitblit
   PIDFile=/var/run/gitblit.service.pid
   ExecStartPre=/opt/gitblit/java-proxy-config.sh
   ExecStart=/usr/bin/java -server -Xmx1024M -Djava.awt.headless=true -jar
   /opt/gitblit/gitblit.jar --baseFolder /opt/gitblit/data --dailyLogFile

[Install]
   WantedBy=multi-user.target
6
  • You are using the wrong answer to create custom services. To start with, custom service files should not be placed within /lib/systemd/system, rather you'd use /etc/systemd/system/your_custom_file.service. Secondly, after creating the service file you'd run systemct daemon-reload to notify systemd about your newly created file. Make sure you've restored SELinux file context and so on. Sep 1, 2017 at 13:49
  • I moved it to /etc/systemd/system/gitblit_server.service and reloaded the daemon. How can I restore SELinux file?
    – Max
    Sep 1, 2017 at 13:57
  • You can do that by restorecon -RFvv /etc/systemd/system. Also make sure you have assigned the right permissions to the file chmod 664 /etc/systemd/system/gitblit_server.service Sep 1, 2017 at 14:00
  • Still the same error
    – Max
    Sep 1, 2017 at 14:03
  • Plase update the question and include the contents of your file, permissions and the error you are getting exactly. See what journalctl -xe shows Sep 1, 2017 at 14:05

1 Answer 1

2

You are using the wrong answer to create custom services. To start with, custom service files should not be placed within /lib/systemd/system rather you'd use /etc/systemd/system/your_custom_file.service.

Secondly, after creating the service file you'd run systemct daemon-reload to notify systemd about your newly created file. Make sure you've restored SELinux file context using restorecon -RFvv /etc/systemd/system

After the update, the answer is obvious.

[Service]
.....
....
ExecStart=/usr/bin/java -server -Xmx1024M -Djava.awt.headless=true -jar
   /opt/gitblit/gitblit.jar --baseFolder /opt/gitblit/data --dailyLogFile
....

Here, the line that starts with /opt/gitblit/.. is treated as a single line and not part of ExecStart directive which is causing the error. You could simply fix it using a backslash as follows:

ExecStart=/usr/bin/java -server -Xmx1024M -Djava.awt.headless=true -jar \
   /opt/gitblit/gitblit.jar --baseFolder /opt/gitblit/data --dailyLogFile

Finally run:

systemctl daemon-reload && systemctl enable gitblit_server.service

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.