I used to run services in 14.04 by executing
ip netns exec namespacename service start servicename
But I realized that this doesnt work anymore on 16.04. The service starts in normal namespace.
I tried to edit /lib/systemd/system/servicename.service file to use namespace but it was not successful. First problem was that the program was executed with its own user who doesn't have access to namespaces. I changed it to run the program as root then use sudo in ExecStart but for some reason service control never came back to command prompt.
Any ideas on how to accomplish a service to automatically and permanently run inside a namespace every time it is restarted on Ubuntu 16.04 ?
If it matters the service in question is transmission-daemon
I managed to get it working with the following .service file. In the file 'vpn' is the name of the namespace. My problem was setting the wrong
Type for the service. I still feel that this solution is not the best solution. If you have a better way, please tell!
[Unit] Description=Transmission BitTorrent Daemon After=network.target [Service] User=root Type=simple ExecStart=/bin/sh -c 'exec /sbin/ip netns exec vpn /usr/bin/sudo -u debian-transmission /usr/bin/transmission-daemon -f --log-error --config-dir /var/lib/transmission-daemon/info' ExecReload=/bin/kill -s HUP $MAINPID [Install] WantedBy=multi-user.target