You are not logged in.

#1 2015-05-10 09:47:11

edke
Member
From: Kosice, Slovakia
Registered: 2011-09-20
Posts: 43

[SOLVED] My custom Systemd unit wont start after reboot, worked ..

Hello guys.

Don't now to what is this related, but my custom Systemd unit stopped autostart after reboot. Unit is located in /home folder and looks like this:

[Unit]
Description=pymelkor
Wants=network.target
After=network.target

[Service]
ExecStart=/home/kraken/apps/klimanetonline/app/.klimanetonline/bin/python \
          app/manage.py run_melkor
User=kraken
Group=users
Restart=always
WorkingDirectory=/home/kraken/apps/klimanetonline

[Install]
WantedBy=multi-user.target

Enabling of unit:

# systemctl enable /home/kraken/apps/klimanetonline/etc/pymelkor.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/pymelkor.service to /home/kraken/apps/klimanetonline/etc/pymelkor.service.
Created symlink from /etc/systemd/system/pymelkor.service to /home/kraken/apps/klimanetonline/etc/pymelkor.service.

Status after enabling:

# systemctl status pymelkor 
● pymelkor.service - pymelkor
   Loaded: loaded (/home/kraken/apps/klimanetonline/etc/pymelkor.service; enabled; vendor preset: disabled)
   Active: inactive (dead)

Unit works:

root@bilbo ~ # systemctl start pymelkor 
root@bilbo ~ # systemctl status pymelkor 
● pymelkor.service - pymelkor
   Loaded: loaded (/home/kraken/apps/klimanetonline/etc/pymelkor.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2015-05-10 11:40:52 CEST; 1s ago
 Main PID: 621 (python)
   CGroup: /system.slice/pymelkor.service
           └─621 /home/kraken/apps/klimanetonline/app/.klimanetonline/bin/python app/manage.py run_melkor

May 10 11:40:52 bilbo systemd[1]: Started pymelkor.
May 10 11:40:52 bilbo systemd[1]: Starting pymelkor...

But after reboot, systemd is not aware of unit, wont autostart it in multi-user.target. Only after daemon reload, unit apears again and have to start it manualy:

root@bilbo /home/kraken # ps aux | grep melkor 
root       416  0.0  0.0  10816  2232 pts/0    S+   11:42   0:00 grep -i melkor
root@bilbo /home/kraken # systemctl status pymelkor 
● pymelkor.service
   Loaded: not-found (Reason: No such file or directory)
   Active: inactive (dead)
root@bilbo /home/kraken # systemctl daemon-reload
root@bilbo /home/kraken # systemctl status pymelkor 
● pymelkor.service - pymelkor
   Loaded: loaded (/home/kraken/apps/klimanetonline/etc/pymelkor.service; enabled; vendor preset: disabled)
   Active: inactive (dead)
root@bilbo /home/kraken # systemctl start pymelkor 
root@bilbo /home/kraken # systemctl status pymelkor 
● pymelkor.service - pymelkor
   Loaded: loaded (/home/kraken/apps/klimanetonline/etc/pymelkor.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2015-05-10 11:42:27 CEST; 1s ago
 Main PID: 438 (python)
   CGroup: /system.slice/pymelkor.service
           └─438 /home/kraken/apps/klimanetonline/app/.klimanetonline/bin/python app/manage.py run_melkor

May 10 11:42:27 bilbo systemd[1]: Started pymelkor.
May 10 11:42:27 bilbo systemd[1]: Starting pymelkor...

Can anyone help me with this ? Searched for some info, found none, this worked before configured this way ..... sad

Last edited by edke (2015-05-10 15:41:45)

Offline

#2 2015-05-10 09:56:05

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: [SOLVED] My custom Systemd unit wont start after reboot, worked ..

Is your home directory encrypted or something like that?

Offline

#3 2015-05-10 09:58:09

edke
Member
From: Kosice, Slovakia
Registered: 2011-09-20
Posts: 43

Re: [SOLVED] My custom Systemd unit wont start after reboot, worked ..

Raynman wrote:

Is your home directory encrypted or something like that?

Nope, normal homedir, with permissions to read the file. Everything works after daemon-reload and manually starting service. But not right after the start:

# systemctl status pymelkor 
● pymelkor.service
   Loaded: not-found (Reason: No such file or directory)
   Active: inactive (dead)

Offline

#4 2015-05-10 11:19:36

Spider.007
Member
Registered: 2004-06-20
Posts: 1,175

Re: [SOLVED] My custom Systemd unit wont start after reboot, worked ..

The proper way to do this would be https://wiki.archlinux.org/index.php/Systemd/User instead of making the System instance responsible for starting a user service. I suspect your /home is on a different partition but that isn't really the issue; this setup is probably not supported and definitely not encouraged in systemd

Offline

#5 2015-05-10 15:41:02

edke
Member
From: Kosice, Slovakia
Registered: 2011-09-20
Posts: 43

Re: [SOLVED] My custom Systemd unit wont start after reboot, worked ..

Spider.007 wrote:

The proper way to do this would be https://wiki.archlinux.org/index.php/Systemd/User instead of making the System instance responsible for starting a user service. I suspect your /home is on a different partition but that isn't really the issue; this setup is probably not supported and definitely not encouraged in systemd

Hello Spider.

Thank you for your response. Worked with that info for few hours and finally have solution and reason for troubles:
- as you said, problem is that service file is not on root partition, therefore not available at time systemd starts and loads services
- can be solved by copying file to /etc/systemd/system, which is not really nice for my hosting templates but will figure out something else
- I disagree about user services part, my service is not really different that for example redis.service, it runs as other user, not root but it's a daemon, needs to be started when multi-user.target is reached, not related any way to user and his session, logging etc

Again, slight change in server concept lead to few hours of bashing my head against table, in this case separation of home folder from root smile Thank you for your help.

Offline

#6 2015-05-10 17:10:03

Spider.007
Member
Registered: 2004-06-20
Posts: 1,175

Re: [SOLVED] My custom Systemd unit wont start after reboot, worked ..

I'm happy to help. Redis is a system-service, it runs as another (system) user but it's still very much different from a service that runs as a normal user. I don't know what service you're trying to run exactly, but user-services can run when multi-user is started just as well.

If this service you have is a system-service, it should probably have a dedicated user. Not sure what you mean with 'hosting templates', but a pretty good explanation of a possible option is http://superuser.com/questions/393423/t … 429#393429.

Offline

Board footer

Powered by FluxBB